-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgit_vivado.py
215 lines (188 loc) · 7.63 KB
/
git_vivado.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# PYTHON 3.X.X REQUIRED!!!
import os
import sys
import configparser
import argparse
import platform
def accept_warning(s):
c = ''
d = {'Y': True, 'y': True, 'N': False, 'n': False}
while c not in d:
c = input('Warning: %s Y/N? ' % s)
return d[c]
def do_checkin(args):
DEBUG_NO_VIVADO = args['DEBUG_NO_VIVADO']
DEBUG_VIVADO_TCL_TRACE = args['DEBUG_VIVADO_TCL_TRACE']
vivado_cmd = args['vivado_cmd'].replace('\\', '/')
script_path = os.path.join(args['script_dir'], 'checkin.tcl').replace('\\', '/')
xpr_path = args['xpr_path'].replace('\\', '/')
repo_path = args['repo_path'].replace('\\', '/')
version = args['version'].replace('\\', '/')
if not args['force'] and not accept_warning('Files and directories contained in %s may be overwritten. Do you wish to continue?' % repo_path):
sys.exit()
print('Checking in project %s to repo %s' % (os.path.basename(xpr_path), os.path.basename(repo_path)))
if DEBUG_NO_VIVADO:
print ('vivado_cmd: %s' % vivado_cmd)
print ('script_path: %s' % script_path)
print ('xpr_path: %s' % xpr_path)
print ('repo_path: %s' % repo_path)
print ('version: %s' % version)
else:
notrace = '' if DEBUG_VIVADO_TCL_TRACE else ' -notrace'
os.system("%s -mode batch -source %s%s -tclargs -x %s -r %s -v %s" % (vivado_cmd, script_path, notrace, xpr_path, repo_path, version))
def do_checkout(args):
DEBUG_NO_VIVADO = args['DEBUG_NO_VIVADO']
DEBUG_VIVADO_TCL_TRACE = args['DEBUG_VIVADO_TCL_TRACE']
vivado_cmd = args['vivado_cmd'].replace('\\', '/')
script_path = os.path.join(args['script_dir'], 'checkout.tcl').replace('\\', '/')
xpr_path = args['xpr_path'].replace('\\', '/')
repo_path = args['repo_path'].replace('\\', '/')
version = args['version'].replace('\\', '/')
build = args['build']
if not args['force'] and not accept_warning('Files and directories contained in %s may be overwritten. Do you wish to continue?' % os.path.dirname(xpr_path)):
sys.exit()
print('Checking out project %s from repo %s' % (os.path.basename(xpr_path), os.path.basename(repo_path)))
notrace = '' if DEBUG_VIVADO_TCL_TRACE else ' -notrace'
cmd = "%s -mode batch -source %s%s -tclargs -x %s -r %s -v %s%s" % (
vivado_cmd,
script_path,
notrace,
# arguments
xpr_path,
repo_path,
version,
' -b' if build else ''
)
if DEBUG_NO_VIVADO:
print ('vivado_cmd: %s' % vivado_cmd)
print ('script_path: %s' % script_path)
print ('xpr_path: %s' % xpr_path)
print ('repo_path: %s' % repo_path)
print ('version: %s' % version)
print ('build: %s' % build)
print(cmd)
else:
os.system(cmd)
if __name__ == "__main__":
# Parse CONFIG.INI
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
project_name = os.path.basename(os.path.abspath(os.path.join(script_dir, '..')))
config = configparser.ConfigParser()
config.read(os.path.join(script_dir, "config.ini"))
operating_system = platform.system()
config_settings = config[operating_system]
# Default arguments assume that this script is contained in a submodule within the target repository
default_repo_path = os.path.abspath(os.path.join(script_dir, '..'))
default_xpr_path = os.path.abspath(os.path.join(script_dir, '..', 'proj', '%s.xpr' % project_name))
default_version = config_settings['VivadoVersion']
# Parse SYS.ARGV
parser = argparse.ArgumentParser(description='Handles vivado project git repo operations')
parser.add_argument(
'-f',
dest='force',
default=False,
action='store_true',
help='Force overwrite of existing files and folders'
)
subparsers = parser.add_subparsers(help='sub-command help')
# Checkin Arguments
parser_checkin = subparsers.add_parser(
'checkin',
help='Checks in XPR to REPO',
formatter_class=argparse.RawTextHelpFormatter
)
parser_checkin.set_defaults(func=do_checkin)
# Optional Args
parser_checkin.add_argument(
'-r',
dest='repo_path',
type=str,
default=default_repo_path,
help='Path to target repository from\nDefault = %s' % (default_repo_path)
)
parser_checkin.add_argument(
'-x',
dest='xpr_path',
type=str,
default=default_xpr_path,
help='Path to XPR file\nDefault = %s' % (default_xpr_path)
)
parser_checkin.add_argument(
'-v',
dest='version',
type=str,
default=default_version,
help='Vivado version number 20##.#\nDefault = %s' % (default_version)
)
# Checkout Arguments
parser_checkout = subparsers.add_parser(
'checkout',
help='Checks out XPR from REPO',
formatter_class=argparse.RawTextHelpFormatter
)
parser_checkout.set_defaults(func=do_checkout)
# Optional Args
parser_checkout.add_argument(
'-r',
dest='repo_path',
type=str,
default=default_repo_path,
help='Path to target repository from\nDefault = %s' % (default_repo_path)
)
parser_checkout.add_argument(
'-x',
dest='xpr_path',
type=str,
default=default_xpr_path,
help='Path to XPR file\nDefault = %s' % (default_xpr_path)
)
parser_checkout.add_argument(
'-v',
dest='version',
type=str,
default=default_version,
help='Vivado version number 20##.#\nDefault = %s' % (default_version)
)
parser_checkout.add_argument(
'-b',
dest='build',
default=False,
action='store_true',
help='Build the project after checkout\nDefault = false'
)
# Parse Arguments
args = parser.parse_args()
funcargs = {'script_dir': script_dir}
if not hasattr(args, 'func'):
print("Please select a subcommand to execute. See this command's help page")
sys.exit()
if hasattr(args, 'force'):
funcargs['force'] = args.force
if hasattr(args, 'build'):
funcargs['build'] = args.build
if hasattr(args, 'repo_path'):
funcargs['repo_path'] = os.path.abspath(os.path.join(os.getcwd(), args.repo_path))
if hasattr(args, 'xpr_path'):
if args.xpr_path[-4:] != '.xpr':
print('Error: xpr_path argument must end in .xpr')
sys.exit()
funcargs['xpr_path'] = os.path.abspath(os.path.join(os.getcwd(), args.xpr_path))
if args.func == do_checkout and os.path.isfile(funcargs['xpr_path']) or os.path.isdir(funcargs['xpr_path']):
# TODO: add warning about overwriting existing project
# TODO: add clean and overwrite process
# TODO: move project_info.tcl to repo root
print('Error: cannot check out repo when project exists; Please clean out the %s/proj directory' % (funcargs['repo_path']))
sys.exit()
if hasattr(args, 'version'):
funcargs['vivado_cmd'] = os.path.join(os.path.abspath(config_settings['VivadoInstallPath']), args.version, 'bin', 'vivado')
funcargs['version'] = args.version
if not os.path.isfile(funcargs['vivado_cmd']):
print('Error: Vivado not installed at %s' % funcargs['vivado_cmd'])
sys.exit()
if hasattr(args, 'temp_directory'):
funcargs['temp_directory'] = args.temp_directory
DEBUG_NO_VIVADO = False
DEBUG_VIVADO_TCL_TRACE = False
funcargs['DEBUG_NO_VIVADO'] = DEBUG_NO_VIVADO
funcargs['DEBUG_VIVADO_TCL_TRACE'] = DEBUG_VIVADO_TCL_TRACE
args.func(funcargs)