Mercurial > mxe-octave
comparison tools/pkg-install.py @ 5257:1927e90b6f63
* tools/pkg-install.py: extract src BIST tests from pkg and install
author | John Donoghue |
---|---|
date | Mon, 06 Jan 2020 09:59:07 -0500 |
parents | b6ca48619aa6 |
children | c752f70af1b6 |
comparison
equal
deleted
inserted
replaced
5256:aad0cc165a27 | 5257:1927e90b6f63 |
---|---|
59 so = re.search(nm, l, re.M|re.S) | 59 so = re.search(nm, l, re.M|re.S) |
60 if so: | 60 if so: |
61 pkg.append(str(so.group(1))) | 61 pkg.append(str(so.group(1))) |
62 return pkg | 62 return pkg |
63 | 63 |
64 def extract_test_code(filename): | |
65 body = [] | |
66 if not os.path.isfile(filename): | |
67 return body | |
68 with open(filename, 'rt') as f: | |
69 lines = f.read().splitlines() | |
70 for l in lines: | |
71 if l.startswith("%!"): | |
72 body.append(l) | |
73 if not body: | |
74 return body | |
75 return "\n".join(body) | |
76 | |
64 def write_index_file(env, desc, index_nm): | 77 def write_index_file(env, desc, index_nm): |
65 | 78 |
66 with open(index_nm, 'w') as f: | 79 with open(index_nm, 'w') as f: |
67 files = os.listdir(env.m_dir) | 80 files = os.listdir(env.m_dir) |
68 classes = fnmatch.filter(files, "@*") | 81 classes = fnmatch.filter(files, "@*") |
248 if env.verbose: | 261 if env.verbose: |
249 print "running make ..." | 262 print "running make ..." |
250 if os.system(env.make + " --directory '" + src + "'" ) != 0: | 263 if os.system(env.make + " --directory '" + src + "'" ) != 0: |
251 raise Exception, "make failed during build - stopping install" | 264 raise Exception, "make failed during build - stopping install" |
252 | 265 |
266 # extract any tests | |
267 if env.verbose: | |
268 print "checking for src BIST tests" | |
269 | |
270 files = os.listdir(src) | |
271 srcfiles = fnmatch.filter(files, "*.cc") + fnmatch.filter(files,"*.cpp") + fnmatch.filter(files, "*.cxx") + fnmatch.filter(files, "*.c") | |
272 for sf in srcfiles: | |
273 tst = extract_test_code(sf) | |
274 if tst: | |
275 with open(sf + "-tst", "w") as f: | |
276 f.write("## DO NOT EDIT! Generated from " + sf + "\n") | |
277 f.write(tst + "\n") | |
278 | |
253 # copy files to inst and inst arch | 279 # copy files to inst and inst arch |
254 files = src + "/FILES" | 280 files = src + "/FILES" |
255 instdir = packdir + "/inst" | 281 instdir = packdir + "/inst" |
256 archdir = instdir + "/" + env.arch | 282 archdir = instdir + "/" + env.arch |
257 | 283 |
258 if os.path.isfile(files) == True: | 284 if os.path.isfile(files) == True: |
285 raise Exception, "make using FILES not supported yet" | |
259 pass # TODO yet | 286 pass # TODO yet |
260 else: | 287 else: |
261 # get .m, .oct and .mex files | 288 # get .m, .oct and .mex files |
262 files = os.listdir(src) | 289 files = os.listdir(src) |
263 m_files = fnmatch.filter(files, "*.m") | 290 m_files = fnmatch.filter(files, "*.m") |
291 tst_files = fnmatch.filter(files, "*-tst") | |
264 mex_files = fnmatch.filter(files, "*.mex") | 292 mex_files = fnmatch.filter(files, "*.mex") |
265 oct_files = fnmatch.filter(files, "*.oct") | 293 oct_files = fnmatch.filter(files, "*.oct") |
266 files = m_files + mex_files + oct_files | 294 files = m_files + mex_files + oct_files + tst_files |
267 files = list(src + "/" + s for s in files) | 295 files = list(src + "/" + s for s in files) |
268 | 296 |
269 # split files into arch and non arch files | 297 # split files into arch and non arch files |
270 archdependant = fnmatch.filter(files, "*.mex") + fnmatch.filter(files,"*.oct") | 298 archdependant = fnmatch.filter(files, "*.mex") + fnmatch.filter(files,"*.oct") + fnmatch.filter(files, "*-tst") |
271 archindependant = list( x for x in files if x not in archdependant ) | 299 archindependant = list( x for x in files if x not in archdependant ) |
272 | 300 |
273 # copy the files | 301 # copy the files |
274 copyfile(archindependant, instdir) | 302 copyfile(archindependant, instdir) |
275 copyfile(archdependant, archdir) | 303 copyfile(archdependant, archdir) |
371 return deps | 399 return deps |
372 | 400 |
373 def rebuild_pkg(env): | 401 def rebuild_pkg(env): |
374 currdir = os.getcwd() | 402 currdir = os.getcwd() |
375 | 403 |
404 | |
376 try: | 405 try: |
377 oct_dir = env.prefix + "/share/octave" | 406 oct_dir = env.prefix + "/share/octave" |
378 pkg_dir = oct_dir + "/packages" | 407 pkg_dir = oct_dir + "/packages" |
379 arch_dir = env.prefix + "/lib/octave/packages" | 408 arch_dir = env.prefix + "/lib/octave/packages" |
380 | 409 |
381 pkg_list_file = oct_dir + "/octave_packages" | 410 pkg_list_file = oct_dir + "/octave_packages" |
382 | 411 |
383 descs=glob.glob(pkg_dir + "/*/packinfo/DESCRIPTION") | 412 descs=glob.glob(pkg_dir + "/*/packinfo/DESCRIPTION") |
413 | |
414 if env.verbose: | |
415 print "Rebuilding pkg list {}".format(pkg_list_file) | |
384 | 416 |
385 with open(pkg_list_file, "w") as f: | 417 with open(pkg_list_file, "w") as f: |
386 f.write("# Created by pkg-install.py\n") | 418 f.write("# Created by pkg-install.py\n") |
387 f.write("# name: global_packages\n") | 419 f.write("# name: global_packages\n") |
388 f.write("# type: cell\n"); | 420 f.write("# type: cell\n"); |
389 f.write("# rows: 1\n") | 421 f.write("# rows: 1\n") |
390 f.write("# columns: {}\n".format(len(descs))) | 422 f.write("# columns: {}\n".format(len(descs))) |
391 | 423 |
392 for d in descs: | 424 for d in descs: |
393 pkg = d[len(pkg_dir):-len("/packinfo/DESCRIPTION")] | 425 pkg = d[len(pkg_dir):-len("/packinfo/DESCRIPTION")] |
394 if env.verbose: | |
395 print "Rebuilding {}".format(pkg) | |
396 desc = get_description(d) | 426 desc = get_description(d) |
397 desc["Name"] = desc["Name"].lower() | 427 desc["Name"] = desc["Name"].lower() |
398 desc["Depends"] = fix_depends(desc.get("Depends","")) | 428 desc["Depends"] = fix_depends(desc.get("Depends","")) |
399 | 429 |
400 f.write("# name: <cell-element>\n"); | 430 f.write("# name: <cell-element>\n"); |