Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from pathlib import Path 

10from shutil import which 

11 

12from vunit.ostools import Process 

13 

14 

15def run_vivado_tcl(vivado_path, tcl_file, no_log_file=False): 

16 """ 

17 Setting cwd ensures that any .log or .jou files produced are placed in 

18 the same directory as the TCL file that produced them. 

19 

20 Arguments: 

21 vivado_path (`pathlib.Path`): Path to Vivado executable. Can set to None 

22 to use whatever version is in PATH. 

23 tcl_file (`pathlib.Path`): Path to TCL file. 

24 

25 Return: 

26 bool: True if everything went well. 

27 """ 

28 tcl_file = tcl_file.resolve() 

29 

30 cmd = [ 

31 str(get_vivado_path(vivado_path)), 

32 "-mode", 

33 "batch", 

34 "-notrace", 

35 "-source", 

36 str(tcl_file), 

37 ] 

38 if no_log_file: 

39 cmd += ["-nojournal", "-nolog"] 

40 

41 try: 

42 Process(args=cmd, cwd=tcl_file.parent).consume_output() 

43 except Process.NonZeroExitCode: 

44 return False 

45 return True 

46 

47 

48def run_vivado_gui(vivado_path, project_file): 

49 """ 

50 Setting cwd ensures that any .log or .jou files produced are placed in 

51 the same directory as the project. 

52 

53 Arguments: 

54 vivado_path (`pathlib.Path`): Path to Vivado executable. Can set to None 

55 to use whatever version is in PATH. 

56 project_file (`pathlib.Path`): Path to a project .xpr file. 

57 

58 Return: 

59 bool: True if everything went well. 

60 """ 

61 project_file = project_file.resolve() 

62 if not project_file.exists(): 

63 raise FileNotFoundError(f"Project does not exist: {project_file}") 

64 

65 cmd = [str(get_vivado_path(vivado_path)), "-mode", "gui", str(project_file)] 

66 

67 try: 

68 Process(args=cmd, cwd=project_file.parent).consume_output() 

69 except Process.NonZeroExitCode: 

70 return False 

71 return True 

72 

73 

74def get_vivado_path(vivado_path=None): 

75 """ 

76 Wrapper to get a ``pathlib.Path`` to vivado executable. 

77 

78 Arguments: 

79 vivado_path (`pathlib.Path`): Path to vivado executable. Set to None to use whatever 

80 is available in PATH. 

81 """ 

82 if vivado_path is not None: 

83 return vivado_path.resolve() 

84 

85 which_vivado = which("vivado") 

86 if which_vivado is None: 

87 raise FileNotFoundError("Could not find vivado on PATH") 

88 

89 return Path(which_vivado).resolve() 

90 

91 

92def to_tcl_path(path): 

93 """ 

94 Return a path string in a format suitable for TCL. 

95 """ 

96 return str(path.resolve()).replace("\\", "/")