From e2ba01d0ce0c729af602f150f636058ba6544cf0 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Thu, 17 Oct 2024 20:17:21 -0400 Subject: [PATCH] [ttx_diff] Build otl-normalizer binary explicitly Invoking this through cargo has some overhead, and involves possible conjestion (I believe only one cargo process at a time will run in a given package or workspace) and I would also like to rule out one more possible complication that could contribute to getting SIGKILL'd. --- resources/scripts/ttx_diff.py | 37 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/resources/scripts/ttx_diff.py b/resources/scripts/ttx_diff.py index a289ec48..76b8701f 100755 --- a/resources/scripts/ttx_diff.py +++ b/resources/scripts/ttx_diff.py @@ -125,14 +125,14 @@ def run_ttx(font_file: Path): # generate a simple text repr for gpos for this font, with retry -def run_normalizer_gpos(cargo_manifest_path: Path, font_file: Path): +def run_normalizer_gpos(normalizer_bin: Path, font_file: Path): out_path = font_file.with_suffix(".markkern.txt") if out_path.exists(): eprint(f"reusing {out_path}") NUM_RETRIES = 5 for i in range(NUM_RETRIES + 1): try: - return try_normalizer_gpos(cargo_manifest_path, font_file, out_path) + return try_normalizer_gpos(normalizer_bin, font_file, out_path) except subprocess.CalledProcessError as e: time.sleep(0.1) if i >= NUM_RETRIES: @@ -142,17 +142,12 @@ def run_normalizer_gpos(cargo_manifest_path: Path, font_file: Path): # we had a bug where this would sometimes hang in mysterious ways, so we may # call it multiple times if it fails -def try_normalizer_gpos(cargo_manifest_path: Path, font_file: Path, out_path: Path): +def try_normalizer_gpos(normalizer_bin: Path, font_file: Path, out_path: Path): if not out_path.is_file(): cmd = [ "timeout", "10m", - "cargo", - "run", - "--release", - "--manifest-path", - str(cargo_manifest_path), - "--", + str(normalizer_bin.absolute()), font_file.name, "-o", out_path.name, @@ -457,12 +452,11 @@ def reduce_diff_noise(fontc: etree.ElementTree, fontmake: etree.ElementTree): # returns a dictionary of {"compiler_name": {"tag": "xml_text"}} -def generate_output(build_dir: Path, otl_norm_cargo_path: Path, fontmake_ttf: Path, fontc_ttf: Path): - # don't run ttx or otl-normalizer if we don't have to: +def generate_output(build_dir: Path, otl_norm_bin: Path, fontmake_ttf: Path, fontc_ttf: Path): fontc_ttx = run_ttx(fontc_ttf) fontmake_ttx = run_ttx(fontmake_ttf) - fontc_gpos = run_normalizer_gpos(otl_norm_cargo_path, fontc_ttf) - fontmake_gpos = run_normalizer_gpos(otl_norm_cargo_path, fontmake_ttf) + fontc_gpos = run_normalizer_gpos(otl_norm_bin, fontc_ttf) + fontmake_gpos = run_normalizer_gpos(otl_norm_bin, fontmake_ttf) fontc = etree.parse(fontc_ttx) fontmake = etree.parse(fontmake_ttx) @@ -616,6 +610,19 @@ def delete_things_we_must_rebuild(rebuild: str, fontmake_ttf: Path, fontc_ttf: P os.remove(path) +# returns the path to the compiled binary +def build_crate(manifest_path: Path): + cmd = ['cargo', 'build', '--release', '--manifest-path', str(manifest_path)] + run(cmd, None, check=True) + crate_name = manifest_path.parent.name + crate_dir = manifest_path.parent + # walk upwards looking for the `target` dir; will abort at root + while crate_dir.parent != crate_dir: + bin_path = crate_dir / "target" / "release" / crate_name + if bin_path.exists(): + return bin_path + crate_dir = crate_dir.parent + def main(argv): if len(argv) != 2: sys.exit("Only one argument, a source file, is expected") @@ -627,6 +634,8 @@ def main(argv): sys.exit("Expected to be at the root of fontc") fontc_manifest_path = root / "fontc" / "Cargo.toml" otl_norm_manifest_path = root / "otl-normalizer" / "Cargo.toml" + otl_bin_path = build_crate(otl_norm_manifest_path) + assert otl_bin_path is not None, "failed to build otl-normalizer?" if shutil.which("fontmake") is None: sys.exit("No fontmake") @@ -676,7 +685,7 @@ def main(argv): assert fontmake_ttf.is_file(), fontmake_ttf assert fontc_ttf.is_file(), fontc_ttf - output = generate_output(build_dir, otl_norm_manifest_path, fontmake_ttf, fontc_ttf) + output = generate_output(build_dir, otl_bin_path, fontmake_ttf, fontc_ttf) if output["fontc"] == output["fontmake"]: eprint("output is identical") continue