Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ttx_diff] Build otl-normalizer binary explicitly #1057

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Oct 18, 2024

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.

longer term, in order to manage the growing complexity of ttx_diff and to support the very different cases of 'CI on many fonts running on a transient host' and 'me at my desk comparing one source' I'd like to tease apart the building vs diffing bits of ttx_diff, and one part of that will mean the diffing bits shouldn't need to know where the fontc repo is located; we'll just pass in the path to the binary itself.

@@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have logic to find the root fontc directory. We already assume the paths of crates. It would be more consistent with the existing code to just presume you'll find the binary at root / "target" / "release" / the_name.

@@ -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?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest asserting it's a file like fontmake_ttf below

# 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)
Copy link
Member

@anthrotype anthrotype Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is that None doing as second positional parameter? Can we get rid of it or use a named keyword argument instead?

Is it stdin? It's not clear from subprocess.run signature
https://docs.python.org/3.13/library/subprocess.html#subprocess.run

The full function signature is largely the same as that of the Popen constructor - most of the arguments to this function are passed through to that interface. (timeout, input, check, and capture_output are not.)

Copy link
Member Author

@cmyr cmyr Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't calling subprocess.run, it's calling a run fn defined in this file (but yes, can use named args, i'll also rename our run fn in a followup PR)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahah bad choice of name then 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's passing working_dir=None and the entire reason of existence of ttx_diff.run() is to call subprocess.run with the given cwd=working_dir, then it's better to avoid the wrapper altogether and simply use subproces.run directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main purpose is that it also logs the command before running.

@@ -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",
Copy link
Member

@anthrotype anthrotype Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you're already using subprocess.run, I suggest you get rid of this external GNU command and use use the timeout parameter, which should be equivalent and more portable

https://docs.python.org/3.13/library/subprocess.html#subprocess.run

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I'll do that in a separate PR.

Base automatically changed from ttx-simple-skip to main October 18, 2024 14:29
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.
@cmyr cmyr added this pull request to the merge queue Oct 18, 2024
Merged via the queue into main with commit 2611c59 Oct 18, 2024
10 checks passed
@cmyr cmyr deleted the ttx-use-normalizer-bin branch October 18, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants