Repository navigation
fix(zipapp): keep runfiles symlinks in --build_python_zip zips #4604
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
Open
fmeum
wants to merge
2
commits into
bazel-contrib:main
Choose a base branch
from
fmeum:zip-data-binary-venv-symlink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| (zipapp) `--build_python_zip` now keeps symlinks in the runfiles as symlinks, | ||
| so it no longer fails when a `py_binary` has another `py_binary` in its | ||
| runfiles. |
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
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,7 @@ | ||
| """Runs the py_binary that is a data dependency of this binary.""" | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
| data_bin = os.path.join(os.path.dirname(__file__), "zip_data_bin") | ||
| subprocess.run([data_bin], check=True) |
26 changes: 26 additions & 0 deletions
26
tests/bootstrap_impls/run_binary_zip_with_binary_data_test.sh
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,26 @@ | ||
| # --- begin runfiles.bash initialization v3 --- | ||
| # Copy-pasted from the Bazel Bash runfiles library v3. | ||
| set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
| source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
| source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
| source "$0.runfiles/$f" 2>/dev/null || \ | ||
| source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
| source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
| { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
| # --- end runfiles.bash initialization v3 --- | ||
| set +e | ||
|
|
||
| bin=$(rlocation $BIN_RLOCATION) | ||
| if [[ -z "$bin" ]]; then | ||
| echo "Unable to locate test binary: $BIN_RLOCATION" | ||
| exit 1 | ||
| fi | ||
| actual=$($bin 2>&1) | ||
|
|
||
| # The zip runs the data binary from its extracted runfiles, which requires the | ||
| # venv of the data binary to be intact. | ||
| if ! (echo "$actual" | grep "^Hello$" ) >/dev/null; then | ||
| echo "expected the data binary to print: Hello" | ||
| echo "but got: $actual" | ||
| exit 1 | ||
| fi |
Oops, something went wrong.
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.
Keep source-symlink data readable when its target is not packaged.
With an exec runtime and no shrubbery toolchain, this selects the Python zipper. Suppose
config.jsonpoints toconfigs/prod.json, but onlyconfig.jsonappears indata. The writer preserves that relative source symlink without addingconfigs/prod.json. The extractedconfig.jsonthen points to a missing file. (raw.githubusercontent.com)The previous implementation passed
config.jsonto Bazel's zipper, which followed the source symlink and stored its contents. (raw.githubusercontent.com)Dereference ordinary source symlinks when their targets are absent from the archive. Preserve declared venv symlinks whose targets are packaged.