-
Notifications
You must be signed in to change notification settings - Fork 2
fix: replace cargo generate-lockfile with targeted Cargo.lock edits for Android build #170
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/usr/bin/env python3 | ||
| """Directly edit Cargo.lock to add specific dependency entries without a full | ||
| `cargo generate-lockfile` re-resolve, which can drift pinned versions of | ||
| unrelated crates (e.g. rama-* alpha pins jumping to newer stable releases | ||
| that require a newer rustc than the Android build environment has). | ||
|
|
||
| Applies exactly two deltas needed for the Android vendored-OpenSSL patches: | ||
| - codex-http-client gains a dependency on openssl-sys | ||
| - codex-thread-store gains a dependency on libc | ||
|
|
||
| Each insertion requires that exactly one matching [[package]] block exists; | ||
| otherwise it fails closed (raises) rather than silently editing the wrong | ||
| block or doing nothing. | ||
| """ | ||
| import re | ||
| import sys | ||
|
|
||
|
|
||
| def insert_dependency(lockfile_text, pkg_name, pkg_version, new_dep): | ||
| block_re = re.compile( | ||
| r'(name = "' + re.escape(pkg_name) + r'"\nversion = "' + re.escape(pkg_version) + r'"\n)' | ||
| r'((?:(?!\[\[package\]\])[^\n]*\n)*?)' | ||
| r'(dependencies = \[\n)((?:\s*"[^"]+",?\n)*)(\]\n)' | ||
| ) | ||
| matches = list(block_re.finditer(lockfile_text)) | ||
| if len(matches) != 1: | ||
| raise ValueError( | ||
| f"expected exactly one package block for {pkg_name} {pkg_version}, found {len(matches)}" | ||
| ) | ||
| match = matches[0] | ||
| deps_block = match.group(4) | ||
| dep_lines = [l for l in deps_block.split('\n') if l.strip()] | ||
| dep_names = [] | ||
| for l in dep_lines: | ||
| m = re.match(r'\s*"([^"]+)",?\s*$', l) | ||
| if not m: | ||
| raise ValueError(f"unexpected dependency line format: {l!r}") | ||
| dep_names.append(m.group(1)) | ||
| if new_dep in dep_names: | ||
| raise ValueError(f"dependency already present: {new_dep}") | ||
| sorted_names = sorted(dep_names + [new_dep]) | ||
| idx = sorted_names.index(new_dep) | ||
| new_lines = dep_lines[:idx] + [f' "{new_dep}",'] + dep_lines[idx:] | ||
| new_deps_block = '\n'.join(new_lines) + '\n' | ||
| return lockfile_text[:match.start(4)] + new_deps_block + lockfile_text[match.end(4):] | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) != 2: | ||
| print(f"usage: {sys.argv[0]} <path-to-Cargo.lock>", file=sys.stderr) | ||
| sys.exit(1) | ||
| path = sys.argv[1] | ||
| with open(path, 'r', encoding='utf-8') as f: | ||
| text = f.read() | ||
|
|
||
| text = insert_dependency(text, 'codex-http-client', '0.0.0', 'openssl-sys') | ||
| text = insert_dependency(text, 'codex-thread-store', '0.0.0', 'libc') | ||
|
|
||
| with open(path, 'w', encoding='utf-8') as f: | ||
| f.write(text) | ||
|
|
||
| print(f"Cargo.lock patched: codex-http-client+openssl-sys, codex-thread-store+libc ({path})") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a supported upstream release already includes either Android dependency in
Cargo.lock, this exception aborts the workflow even though the surrounding manifest patches explicitly treat existing dependencies as already applied. Because the workflow accepts futurerust-v0.1xxreleases and invokes this script unconditionally, upstreaming either fix will turn a valid lockfile into a build failure; return the unchanged lockfile whennew_depis already present while retaining the uniqueness and format checks.Useful? React with 👍 / 👎.