forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since the 0.21 upgrade, the host `$PATH` is not forwarded anymore by default to the sandboxes in charge to realize Bazel actions. This default change broke the `py_binary` rule among other things. Every python binary is wrapped in a stub in charge to setup the execution environment. Currently, this stub's shebang points to a `/usr/bin/env python` which cannot be resolved with the current `$PATH`. This results in breaking any build pipeline requiring the use of python at some point. On top of the incorrect shebang, the stub template is unable to find the actual python binary using `SearchPath`. This PR fixes those two things by re-writing the stub template shebang to the actual python binary and by substituting the faulty default python binary lookup to the right one.
- Loading branch information
1 parent
2ea8a21
commit 5700473
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
55 changes: 55 additions & 0 deletions
55
pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix
This file contains 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,55 @@ | ||
{ stdenv, lib, writeText, runCommandCC, bazel }: | ||
|
||
let | ||
WORKSPACE = writeText "WORKSPACE" '' | ||
workspace(name = "our_workspace") | ||
''; | ||
|
||
pythonLib = writeText "lib.py" '' | ||
def foo(): | ||
return 43 | ||
''; | ||
|
||
pythonBin = writeText "bin.py" '' | ||
from lib import foo | ||
assert foo() == 43 | ||
''; | ||
|
||
pythonBUILD = writeText "BUILD" '' | ||
py_library( | ||
name = "lib", | ||
srcs = [ "lib.py" ], | ||
) | ||
py_test( | ||
name = "bin", | ||
srcs = [ "bin.py" ], | ||
deps = [ ":lib" ], | ||
) | ||
''; | ||
|
||
runLocal = name: script: runCommandCC name { preferLocalBuild = true; } script; | ||
|
||
workspaceDir = runLocal "our_workspace" '' | ||
mkdir $out | ||
cp ${WORKSPACE} $out/WORKSPACE | ||
mkdir $out/python | ||
cp ${pythonLib} $out/python/lib.py | ||
cp ${pythonBin} $out/python/bin.py | ||
cp ${pythonBUILD} $out/python/BUILD.bazel | ||
''; | ||
|
||
testBazel = runLocal "bazel-test-builtin-rules" '' | ||
export HOME=$(mktemp -d) | ||
cp -r ${workspaceDir}/* . | ||
${bazel}/bin/bazel --output_base=/tmp/bazel-tests/wd\ | ||
test \ | ||
--test_output=errors \ | ||
--host_javabase='@local_jdk//:jdk' \ | ||
//... | ||
touch $out | ||
''; | ||
|
||
in testBazel |
13 changes: 13 additions & 0 deletions
13
pkgs/development/tools/build-managers/bazel/python-stub-path-fix.patch
This file contains 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,13 @@ | ||
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt | ||
index dac21c9a83..69b11c283f 100644 | ||
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt | ||
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt | ||
@@ -67,7 +67,7 @@ def FindPythonBinary(module_space): | ||
return os.path.join(module_space, PYTHON_BINARY) | ||
else: | ||
# Case 4: Path has to be looked up in the search path. | ||
- return SearchPath(PYTHON_BINARY) | ||
+ return "NIX_STORE_PYTHON_PATH" | ||
|
||
def CreatePythonPathEntries(python_imports, module_space): | ||
parts = python_imports.split(':'); |