From 30a730c54298f6abafc622045cc2e6542126f735 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Mon, 28 Sep 2026 16:31:53 +0100 Subject: Leave a generated file as it was when its generator fails Run against HarfBuzz 14.5.0 and Unicode 18.0.0, text/unicode.py met a line breaking class it does not know (HH) and text/syllabic.py a table laid out otherwise, and the tool had already emptied both files. A generator's output now replaces its file only when it succeeds, and the tool stops before building when one fails: those are what to port first. --- text/upstream.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'text') diff --git a/text/upstream.py b/text/upstream.py index ec0e18b..0cf1d98 100644 --- a/text/upstream.py +++ b/text/upstream.py @@ -90,9 +90,9 @@ def run(name, command, results, **kwargs): print(f'== {name}', file=sys.stderr) done = subprocess.run(command, capture_output=True, text=True, cwd=ROOT, **kwargs) sys.stderr.write(done.stderr[-4000:]) - reports = [json.loads(line) for line in done.stdout.splitlines() if line.startswith('{')] + reports = [json.loads(line) for line in done.stdout.splitlines() if line.startswith('{"')] results[name] = {'passed': done.returncode == 0, **({'report': reports} if reports else {})} - if done.returncode: + if done.returncode and not name.endswith('.py'): sys.stderr.write(done.stdout[-4000:]) return done @@ -114,13 +114,17 @@ def main(): results = {} generated = ['text/unicode-data.c', 'text/syllabic-data.c'] - with open(ROOT / 'text' / 'unicode-data.c', 'w') as out: - results['unicode.py'] = {'passed': subprocess.run([sys.executable, 'text/unicode.py', str(database)], - stdout=out, cwd=ROOT).returncode == 0} - with open(ROOT / 'text' / 'syllabic-data.c', 'w') as out: - results['syllabic.py'] = {'passed': subprocess.run([sys.executable, 'text/syllabic.py', str(source / 'src')], - stdout=out, cwd=ROOT).returncode == 0} + for name, target, given in (('unicode.py', 'unicode-data.c', database), ('syllabic.py', 'syllabic-data.c', + source / 'src')): + # a generator that fails leaves its file as it was + made = run(name, [sys.executable, f'text/{name}', str(given)], results) + if not made.returncode: + (ROOT / 'text' / target).write_text(made.stdout) run('syllabic.py --check', [sys.executable, 'text/syllabic.py', str(source / 'src'), '--check'], results) + if not all(r['passed'] for r in results.values()): + # the generators do not follow this version yet: what to port first + print(json.dumps({'harfbuzz': version, 'unicode': unicode, 'checks': results})) + return 1 build = UPSTREAM / 'build' flags = [f'BUILD={build}', f'HARFBUZZ_CFLAGS=-I{source / "src"}', -- cgit v1.2.3