diff --git a/Build b/Build index 88ded95..eb83b48 100755 --- a/Build +++ b/Build @@ -9,7 +9,7 @@ import time import shutil import re from datetime import datetime -from subprocess import run, PIPE +from subprocess import run, PIPE, DEVNULL from machfs import Volume ######################################################################## @@ -39,7 +39,7 @@ def extract_makefile_defines(makefile, seed={}): REB = re.compile(rb'Build-date: (\d\d\d\d-\d\d-\d\d)') def get_build_date(from_dir): try: - msg = run(['git', 'rev-list', '--format=%B', '--max-count=1', 'HEAD'], cwd=from_dir, stdout=PIPE, check=True) + msg = run(['git', 'rev-list', '--format=%B', '--max-count=1', 'HEAD'], cwd=from_dir, stdout=PIPE, stderr=DEVNULL, check=True) msg = msg.stdout except: return @@ -129,79 +129,80 @@ try: except FileNotFoundError: overs = [] -remaining = list(overs) +if overs: + remaining = list(overs) -overs_re = '|'.join(re.escape(x) for x in overs) -overs_re = r'^[^#\s]*\b(Thing.lib)"?\s*ƒ\s*'.replace('Thing.lib', overs_re) -overs_re = re.compile(overs_re, re.IGNORECASE) - -for f in all_makefiles: - mfile = open(f).read().split('\n') - - havechanged = False - newmfile = [] - - idx = -1 - while idx + 1 < len(mfile): - idx += 1 - m = overs_re.match(mfile[idx]) - if m: - thefile = m.group(1) - havechanged = True - newmfile.append('# Rule replaced at build time by ' + path.basename(__file__)) - remaining = [x for x in remaining if x.upper() != thefile.upper()] - - srcfile = '{Sources}%s:%s' % (OVERDIR, thefile) - newmfile.append(m.group(0) + srcfile) - newmfile.append('\tDuplicate -y {Deps} {Targ}') - - lastidx = idx # how many "old" lines should be commented out? - if mfile[idx].endswith('∂'): - while lastidx + 1 < len(mfile) and mfile[lastidx + 1].endswith('∂'): - lastidx += 1 # capture continuations of first line - while lastidx + 1 < len(mfile) and mfile[lastidx + 1].startswith('\t'): - lastidx += 1 # capture build lines starting with tab - - while idx <= lastidx: - newmfile.append('#\t' + mfile[idx]) - idx += 1 - else: - newmfile.append(mfile[idx]) - - if havechanged: - open(f, 'w').write('\n'.join(newmfile)) - -if remaining: # try to find where these override files with *no build rule* should go - found_locations = {k: [] for k in remaining} - - overs_re = '|'.join(re.escape(x) for x in remaining) - overs_re = r'^[^#]*"({\w+}(?:\w+:)*)(Thing.lib)"'.replace('Thing.lib', overs_re) + overs_re = '|'.join(re.escape(x) for x in overs) + overs_re = r'^[^#\s]*\b(Thing.lib)"?\s*ƒ\s*'.replace('Thing.lib', overs_re) overs_re = re.compile(overs_re, re.IGNORECASE) for f in all_makefiles: mfile = open(f).read().split('\n') - for line in mfile: - m = overs_re.match(line) + havechanged = False + newmfile = [] + + idx = -1 + while idx + 1 < len(mfile): + idx += 1 + m = overs_re.match(mfile[idx]) if m: - orig_name = next(x for x in remaining if x.upper() == m.group(2).upper()) - found_loc = m.group(1)+m.group(2) - if found_loc.upper() not in (x.upper() for x in found_locations[orig_name]): - found_locations[orig_name].append(found_loc) + thefile = m.group(1) + havechanged = True + newmfile.append('# Rule replaced at build time by ' + path.basename(__file__)) + remaining = [x for x in remaining if x.upper() != thefile.upper()] - for f in main_makefiles: - with open(f, 'a') as fd: - fd.write('\n# Rules created at build time by %s\n' % path.basename(__file__)) - for orig_name, found_locs in found_locations.items(): - if len(found_locs) == 1: - remaining = [x for x in remaining if x != orig_name] - fd.write(found_locs[0]) - fd.write(' ƒ {Sources}%s:%s\n' % (OVERDIR, orig_name)) - fd.write('\tDuplicate -y {Deps} {Targ}\n') + srcfile = '{Sources}%s:%s' % (OVERDIR, thefile) + newmfile.append(m.group(0) + srcfile) + newmfile.append('\tDuplicate -y {Deps} {Targ}') -diag = 'Successfully spliced: %d/%d' % (len(overs)-len(remaining), len(overs)) -if remaining: diag += '; Failed: ' + ' '.join(remaining) -log(diag) + lastidx = idx # how many "old" lines should be commented out? + if mfile[idx].endswith('∂'): + while lastidx + 1 < len(mfile) and mfile[lastidx + 1].endswith('∂'): + lastidx += 1 # capture continuations of first line + while lastidx + 1 < len(mfile) and mfile[lastidx + 1].startswith('\t'): + lastidx += 1 # capture build lines starting with tab + + while idx <= lastidx: + newmfile.append('#\t' + mfile[idx]) + idx += 1 + else: + newmfile.append(mfile[idx]) + + if havechanged: + open(f, 'w').write('\n'.join(newmfile)) + + if remaining: # try to find where these override files with *no build rule* should go + found_locations = {k: [] for k in remaining} + + overs_re = '|'.join(re.escape(x) for x in remaining) + overs_re = r'^[^#]*"({\w+}(?:\w+:)*)(Thing.lib)"'.replace('Thing.lib', overs_re) + overs_re = re.compile(overs_re, re.IGNORECASE) + + for f in all_makefiles: + mfile = open(f).read().split('\n') + + for line in mfile: + m = overs_re.match(line) + if m: + orig_name = next(x for x in remaining if x.upper() == m.group(2).upper()) + found_loc = m.group(1)+m.group(2) + if found_loc.upper() not in (x.upper() for x in found_locations[orig_name]): + found_locations[orig_name].append(found_loc) + + for f in main_makefiles: + with open(f, 'a') as fd: + fd.write('\n# Rules created at build time by %s\n' % path.basename(__file__)) + for orig_name, found_locs in found_locations.items(): + if len(found_locs) == 1: + remaining = [x for x in remaining if x != orig_name] + fd.write(found_locs[0]) + fd.write(' ƒ {Sources}%s:%s\n' % (OVERDIR, orig_name)) + fd.write('\tDuplicate -y {Deps} {Targ}\n') + + diag = 'Successfully spliced: %d/%d' % (len(overs)-len(remaining), len(overs)) + if remaining: diag += '; Failed: ' + ' '.join(remaining) + log(diag) ########################################################################