about summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers
diff options
context:
space:
mode:
authorAndreas Herrmann <andreash87@gmx.ch>2019-08-16 16:21:48 +0200
committerFlorian Klink <flokli@flokli.de>2019-10-11 21:44:28 +0200
commit7429acdea1c5b8abc60ebada23112ccd2dd6a313 (patch)
tree39a6894cda3233045746c4caf9d942717f68688e /pkgs/development/tools/build-managers
parentb32d6f1c1629fde344ad2f07fef1f37c38d07835 (diff)
downloadnixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.tar
nixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.tar.gz
nixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.tar.bz2
nixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.tar.lz
nixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.tar.xz
nixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.tar.zst
nixlib-7429acdea1c5b8abc60ebada23112ccd2dd6a313.zip
bazel: Test that all shebangs are patched correctly
Diffstat (limited to 'pkgs/development/tools/build-managers')
-rw-r--r--pkgs/development/tools/build-managers/bazel/default.nix2
-rw-r--r--pkgs/development/tools/build-managers/bazel/shebang-test.nix47
2 files changed, 49 insertions, 0 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix
index e9ce95c16099..352b79f21b6f 100644
--- a/pkgs/development/tools/build-managers/bazel/default.nix
+++ b/pkgs/development/tools/build-managers/bazel/default.nix
@@ -208,6 +208,7 @@ stdenv.mkDerivation rec {
             # about why to create a subdir for the workspace.
             cp -r ${workspaceDir} wd && chmod u+w wd && cd wd
 
+            BAZEL_EXTRACTED=${be.install_dir}
             ${bazelScript}
 
             touch $out
@@ -223,6 +224,7 @@ stdenv.mkDerivation rec {
       };
 
     in {
+      shebang = callPackage ./shebang-test.nix { inherit runLocal bazelTest distDir; };
       bashTools = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest distDir; };
       cpp = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; };
       java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples distDir; };
diff --git a/pkgs/development/tools/build-managers/bazel/shebang-test.nix b/pkgs/development/tools/build-managers/bazel/shebang-test.nix
new file mode 100644
index 000000000000..98ec9a67c156
--- /dev/null
+++ b/pkgs/development/tools/build-managers/bazel/shebang-test.nix
@@ -0,0 +1,47 @@
+{
+  bazel
+, bazelTest
+, distDir
+, runLocal
+, unzip
+}:
+
+# Tests that all shebangs are patched appropriately.
+# #!/usr/bin/... should be replaced by Nix store references.
+# #!.../bin/env python should be replaced by Nix store reference to the python interpreter.
+
+let
+
+  workspaceDir = runLocal "our_workspace" {} "mkdir $out";
+
+  testBazel = bazelTest {
+    name = "bazel-test-shebangs";
+    inherit workspaceDir;
+    bazelPkg = bazel;
+    bazelScript = ''
+      set -ueo pipefail
+      FAIL=
+      check_shebangs() {
+        local dir="$1"
+        { grep -Re '#!/usr/bin' $dir && FAIL=1; } || true
+        { grep -Re '#![^[:space:]]*/bin/env python' $dir && FAIL=1; } || true
+      }
+      check_shebangs $BAZEL_EXTRACTED
+      while IFS= read -r -d "" zip; do
+        unzipped="./$zip/UNPACKED"
+        mkdir -p "$unzipped"
+        unzip -qq $zip -d "$unzipped"
+        check_shebangs "$unzipped"
+        rm -rf unzipped
+      done < <(find $BAZEL_EXTRACTED -type f -name '*.zip' -or -name '*.jar' -print0)
+      if [[ $FAIL = 1 ]]; then
+        echo "Found files in the bazel distribution with illegal shebangs." >&2
+        echo "Replace those by explicit Nix store paths." >&2
+        echo "Python scripts should not use \`bin/env python' but the Python interpreter's store path." >&2
+        exit 1
+      fi
+    '';
+    buildInputs = [ unzip ];
+  };
+
+in testBazel