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

bazel: Fix python stub template #66718

Merged
merged 1 commit into from Aug 16, 2019

Conversation

aherrmann
Copy link
Member

The shebang in the python stub template was incorrectly patched to

<store-path>/bin/env python

instead of

<store-path>/bin/python

The reason was that patchShebangs was called with --replace which is
an unknown argument.

patching script interpreter paths in src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt --replace /usr/bin/env python /nix/store/w7gsq8v86hni4ynaqgwwlnlny115ylng-python3-3.7.4/bin/python
find: unknown predicate `--replace'

Using substituteInPlace instead resolves that issue.

Motivation for this change

The wrong shebang caused failures of py_binary targets due to python
not being in PATH in certain circumstances.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @Profpatsch

The shebang in the python stub template was incorrectly patched to
```
<store-path>/bin/env python
```
instead of
```
<store-path>/bin/python
```

The reason was that `patchShebangs` was called with `--replace` which is
an unknown argument.
```
patching script interpreter paths in src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt --replace /usr/bin/env python /nix/store/w7gsq8v86hni4ynaqgwwlnlny115ylng-python3-3.7.4/bin/python
find: unknown predicate `--replace'
```

Using `substituteInPlace` instead resolves that issue.

The wrong shebang caused failures of `py_binary` targets due to `python`
not being in `PATH` in certain circumstances.
@Profpatsch
Copy link
Member

Notably, our tests didn’t catch that we introduced a broken path in the final bazel.

We were able to find it by letting bazel self-extract and then grepping over the extracted repository, which found it in the main bazel .jar file (which you can then check with strings from binutils).
This check needs to be added to our tests, no /bin/env should remain in the final bazel jar.

I can provide instructions on how to implement such a test.

cc @abbradar, this was originally introduced by https://github.com/NixOS/nixpkgs/pull/64903/files#diff-4746b81564a01e241a84d455575437e7R311 and slipped through review.

@Profpatsch
Copy link
Member

@GrahamcOfBorg build bazel.tests

@aherrmann aherrmann mentioned this pull request Aug 16, 2019
10 tasks
@Profpatsch Profpatsch merged commit f426173 into NixOS:master Aug 16, 2019
@abbradar
Copy link
Member

Thanks for fixing this! I don't like that it didn't fail because of unknown argument; I'll look into this in several weeks (will be busy at CCCamp ;) ).

@aherrmann aherrmann deleted the bazel-python-stub-template branch August 21, 2019 12:45
@mboes mboes mentioned this pull request Sep 1, 2019
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants