bazel: Test that all shebangs are patched correctly
This commit is contained in:
parent
b32d6f1c16
commit
7429acdea1
@ -208,6 +208,7 @@ stdenv.mkDerivation rec {
|
|||||||
# about why to create a subdir for the workspace.
|
# about why to create a subdir for the workspace.
|
||||||
cp -r ${workspaceDir} wd && chmod u+w wd && cd wd
|
cp -r ${workspaceDir} wd && chmod u+w wd && cd wd
|
||||||
|
|
||||||
|
BAZEL_EXTRACTED=${be.install_dir}
|
||||||
${bazelScript}
|
${bazelScript}
|
||||||
|
|
||||||
touch $out
|
touch $out
|
||||||
@ -223,6 +224,7 @@ stdenv.mkDerivation rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
shebang = callPackage ./shebang-test.nix { inherit runLocal bazelTest distDir; };
|
||||||
bashTools = callPackage ./bash-tools-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; };
|
cpp = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; };
|
||||||
java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples distDir; };
|
java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples distDir; };
|
||||||
|
47
pkgs/development/tools/build-managers/bazel/shebang-test.nix
Normal file
47
pkgs/development/tools/build-managers/bazel/shebang-test.nix
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user