From 57004738b168663bb4053c6737053e0039cc6259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Baylac-Jacqu=C3=A9?= Date: Tue, 15 Jan 2019 15:14:33 +0100 Subject: [PATCH] bazel: fix python stub paths. 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. --- .../tools/build-managers/bazel/default.nix | 18 +++++- .../bazel/python-bin-path-test.nix | 55 +++++++++++++++++++ .../bazel/python-stub-path-fix.patch | 13 +++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix create mode 100644 pkgs/development/tools/build-managers/bazel/python-stub-path-fix.patch diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index 510ad3956b68..31a8c33ffe92 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, fetchurl, fetchpatch, runCommand, makeWrapper +{ stdenv, callPackage, lib, fetchurl, fetchpatch, runCommand, makeWrapper , jdk, zip, unzip, bash, writeCBin, coreutils , which, python, perl, gnused, gnugrep, findutils # Apple dependencies @@ -38,6 +38,11 @@ stdenv.mkDerivation rec { platforms = platforms.linux ++ platforms.darwin; }; + # additional tests that check bazel’s functionality + passthru.tests = { + python_bin_path = callPackage ./python-bin-path-test.nix {}; + }; + name = "bazel-${version}"; src = fetchurl { @@ -47,8 +52,10 @@ stdenv.mkDerivation rec { sourceRoot = "."; - patches = - lib.optional enableNixHacks ./nix-hacks.patch; + patches = [ + (lib.optional enableNixHacks ./nix-hacks.patch) + ./python-stub-path-fix.patch + ]; # Bazel expects several utils to be available in Bash even without PATH. Hence this hack. @@ -118,6 +125,10 @@ stdenv.mkDerivation rec { ''; genericPatches = '' + # Substitute python's stub shebang to plain python path. (see TODO add pr URL) + substituteInPlace src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt\ + --replace "/usr/bin/env python" "${python}/bin/python" \ + --replace "NIX_STORE_PYTHON_PATH" "${python}/bin/python" \ # substituteInPlace is rather slow, so prefilter the files with grep grep -rlZ /bin src/main/java/com/google/devtools | while IFS="" read -r -d "" path; do # If you add more replacements here, you must change the grep above! @@ -137,6 +148,7 @@ stdenv.mkDerivation rec { --replace '"jvm_opts": JDK9_JVM_OPTS' \ '"jvm_opts": JDK8_JVM_OPTS' + # add nix environment vars to .bazelrc cat >> .bazelrc <