-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgit_vivado.py
311 lines (277 loc) · 11.2 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# PYTHON 3.X.X REQUIRED!!!
import os
import sys
import configparser
import argparse
import platform
from release import do_release
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'], 'digilent_vivado_checkin.tcl').replace('\\', '/')
xpr_path = args['xpr_path'].replace('\\', '/')
repo_path = args['repo_path'].replace('\\', '/')
version = args['version'].replace('\\', '/')
workspace = args['workspace'].replace('\\', '/')
no_hdf = ' -no_hdf' if args['no_hdf'] else ''
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 -w %s%s" % (vivado_cmd, script_path, notrace, xpr_path, repo_path, version, workspace, no_hdf))
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'], 'digilent_vivado_checkout.tcl').replace('\\', '/')
xpr_path = args['xpr_path'].replace('\\', '/')
repo_path = args['repo_path'].replace('\\', '/')
version = args['version'].replace('\\', '/')
workspace = args['workspace'].replace('\\', '/')
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 -w %s" % (
vivado_cmd,
script_path,
notrace,
# arguments
xpr_path,
repo_path,
version,
workspace
)
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(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_workspace_path = os.path.abspath(os.path.join(script_dir, '..', 'sdk'))
default_version = config_settings['VivadoVersion']
idx = 0
while os.path.exists( os.path.abspath(os.path.join(script_dir, '..', 'release_%d' % (idx))) ):
idx += 1
release_dir = os.path.abspath(os.path.join(script_dir, '..', 'release_%d' % (idx)))
default_zip_path = os.path.abspath(os.path.join(release_dir, '%s-%s.zip' % (project_name, default_version)))
default_temp_directory = os.path.abspath(os.path.join(release_dir, '%s-%s' % (project_name, default_version)))
# 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)
)
parser_checkin.add_argument(
'-w',
dest='workspace',
type=str,
default=default_workspace_path,
help='Path to SDK workspace\nDefault = %s' % (default_workspace_path)
)
parser_checkin.add_argument(
'-no_hdf',
dest='no_hdf',
default=False,
action='store_true',
help='Do not check in hardware handoff\n Default = not set (False)'
)
# 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(
'-w',
dest='workspace',
type=str,
default=default_workspace_path,
help='Path to SDK workspace\nDefault = %s' % (default_workspace_path)
)
# Release Arguments
parser_release = subparsers.add_parser(
'release',
help='Creates release ZIP from XPR',
formatter_class=argparse.RawTextHelpFormatter
)
parser_release.set_defaults(func=do_release)
# Optional Args
parser_release.add_argument(
'-z',
dest='zip_path',
type=str,
default=default_zip_path,
help='Path to new release archive ZIP file\nDefault = %s' % (default_zip_path)
)
parser_release.add_argument(
'-r',
dest='repo_path',
type=str,
default=default_repo_path,
help='Path to target repository from\nDefault = %s' % (default_repo_path)
)
parser_release.add_argument(
'-x',
dest='xpr_path',
type=str,
default=default_xpr_path,
help='Path to XPR file\nDefault = %s' % (default_xpr_path)
)
parser_release.add_argument(
'-v',
dest='version',
type=str,
default=default_version,
help='Vivado version number 20##.#\nDefault = %s' % (default_version)
)
parser_release.add_argument(
'-ws',
dest='workspace',
type=str,
default=default_workspace_path,
help='Path to SDK workspace\nDefault = %s' % (default_workspace_path)
)
parser_release.add_argument(
'-temp',
dest='temp_directory',
type=str,
default=default_temp_directory,
help='Temp directory to store release intermediates\nDefault = %s' % (default_temp_directory)
)
# 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, '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, 'zip_path'):
#if not os.path.dirname(args.zip_path):
# TODO: add warning/confirmation to create directory structure
# TODO: recursively create missing directories in zip_path
if os.path.isfile(args.zip_path):
# TODO: consider adding automatic renaming of release archive
print("Error: Target ZIP archive already exists")
sys.exit()
funcargs['zip_path'] = os.path.abspath(os.path.join(os.getcwd(), args.zip_path))
if hasattr(args, 'no_hdf'):
funcargs['no_hdf'] = args.no_hdf
if hasattr(args, 'workspace'):
# TODO: check for workspace's existence
funcargs['workspace'] = args.workspace
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()
funcargs['xsct_cmd'] = os.path.join(os.path.abspath(config_settings['SdkInstallPath']), args.version, 'bin', config_settings['XsctFile'])
if not os.path.isfile(funcargs['xsct_cmd']):
print('Error: XSCT not installed at %s' % funcargs['xsct_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)