Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 62 lines 1.6 kB view raw
1{ 2 bazel, 3 bazelTest, 4 extracted, 5 ripgrep, 6 runLocal, 7 unzip, 8 ... 9}: 10 11# Tests that all shebangs are patched appropriately. 12# #!/usr/bin/... should be replaced by Nix store references. 13# #!.../bin/env python should be replaced by Nix store reference to the python interpreter. 14 15let 16 17 workspaceDir = runLocal "our_workspace" { } "mkdir $out"; 18 19 testBazel = bazelTest { 20 name = "bazel-test-shebangs"; 21 inherit workspaceDir; 22 bazelPkg = bazel; 23 bazelScript = '' 24 set -ueo pipefail 25 FAIL= 26 check_shebangs() { 27 local dir="$1" 28 { rg -e '#!/usr/bin' -e '#![^[:space:]]*/bin/env' $dir -e && echo && FAIL=1; } || true 29 } 30 extract() { 31 local dir="$1" 32 find "$dir" -type f '(' -name '*.zip' -or -name '*.jar' ')' -print0 \ 33 | while IFS="" read -r -d "" zip ; do 34 echo "Extracting $zip" 35 local unzipped="$zip-UNPACKED" 36 mkdir -p "$unzipped" 37 unzip -qq $zip -d "$unzipped" 38 extract "$unzipped" 39 rm -rf "$unzipped" "$zip" || true 40 done 41 check_shebangs "$dir" 42 } 43 44 mkdir install_root 45 cp --no-preserve=all -r ${extracted bazel}/install/*/* install_root/ 46 extract ./install_root 47 48 if [[ $FAIL = 1 ]]; then 49 echo "Found files in the bazel distribution with illegal shebangs." >&2 50 echo "Replace those by explicit Nix store paths." >&2 51 echo "Python scripts should not use \`bin/env python' but the Python interpreter's store path." >&2 52 exit 1 53 fi 54 ''; 55 buildInputs = [ 56 unzip 57 ripgrep 58 ]; 59 }; 60 61in 62testBazel