bazel_7: backport bazel_6 bash fixes for remote execution

+31 -21
+31 -21
pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
··· 3 3 , callPackage 4 4 , lib 5 5 , fetchurl 6 - , fetchpatch 7 - , fetchFromGitHub 8 - , runCommand 9 - , runCommandCC 10 6 , makeWrapper 11 - , recurseIntoAttrs 12 - , newScope 13 7 , writeTextFile 14 - , autoPatchelfHook 15 8 , substituteAll 9 + , writeShellApplication 10 + , makeBinaryWrapper 16 11 # this package (through the fixpoint glass) 17 12 , bazel_self 18 13 # native build inputs 19 14 , runtimeShell 20 - , lr 21 - , xe 22 15 , zip 23 16 , unzip 24 17 , bash 25 - , writeCBin 26 18 , coreutils 27 19 , which 28 20 , gawk ··· 36 28 , file 37 29 , installShellFiles 38 30 , lndir 39 - # updater 40 31 , python3 41 - , writeScript 42 32 # Apple dependencies 43 33 , cctools 44 34 , libcxx ··· 50 40 # Allow to independently override the jdks used to build and run respectively 51 41 , buildJdk 52 42 , runJdk 53 - # Downstream packages for tests 54 - , bazel-watcher 55 43 # Always assume all markers valid (this is needed because we remove markers; they are non-deterministic). 56 44 # Also, don't clean up environment variables (so that NIX_ environment variables are passed to compilers). 57 45 , enableNixHacks ? false 58 - }@args: 46 + }: 59 47 60 48 let 61 49 version = "7.0.0"; ··· 131 119 132 120 defaultShellPath = lib.makeBinPath defaultShellUtils; 133 121 122 + bashWithDefaultShellUtilsSh = writeShellApplication { 123 + name = "bash"; 124 + runtimeInputs = defaultShellUtils; 125 + text = '' 126 + if [[ "$PATH" == "/no-such-path" ]]; then 127 + export PATH=${defaultShellPath} 128 + fi 129 + exec ${bash}/bin/bash "$@" 130 + ''; 131 + }; 132 + 133 + # Script-based interpreters in shebangs aren't guaranteed to work, 134 + # especially on MacOS. So let's produce a binary 135 + bashWithDefaultShellUtils = stdenv.mkDerivation { 136 + name = "bash"; 137 + src = bashWithDefaultShellUtilsSh; 138 + nativeBuildInputs = [ makeBinaryWrapper ]; 139 + buildPhase = '' 140 + makeWrapper ${bashWithDefaultShellUtilsSh}/bin/bash $out/bin/bash 141 + ''; 142 + }; 143 + 134 144 platforms = lib.platforms.linux ++ lib.platforms.darwin; 135 145 136 146 inherit (stdenv.hostPlatform) isDarwin isAarch64; ··· 319 329 # If you add more replacements here, you must change the grep above! 320 330 # Only files containing /bin are taken into account. 321 331 sedVerbose "$path" \ 322 - -e 's!/usr/local/bin/bash!${bash}/bin/bash!g' \ 323 - -e 's!/usr/bin/bash!${bash}/bin/bash!g' \ 324 - -e 's!/bin/bash!${bash}/bin/bash!g' \ 325 - -e 's!/usr/bin/env bash!${bash}/bin/bash!g' \ 332 + -e 's!/usr/local/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \ 333 + -e 's!/usr/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \ 334 + -e 's!/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \ 335 + -e 's!/usr/bin/env bash!${bashWithDefaultShellUtils}/bin/bash!g' \ 326 336 -e 's!/usr/bin/env python2!${python3}/bin/python!g' \ 327 337 -e 's!/usr/bin/env python!${python3}/bin/python!g' \ 328 338 -e 's!/usr/bin/env!${coreutils}/bin/env!g' \ ··· 331 341 332 342 # Fixup scripts that generate scripts. Not fixed up by patchShebangs below. 333 343 sedVerbose scripts/bootstrap/compile.sh \ 334 - -e 's!/bin/bash!${bash}/bin/bash!g' \ 344 + -e 's!/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \ 335 345 -e 's!shasum -a 256!sha256sum!g' 336 346 337 347 # Augment bundled repository_cache with our extra paths ··· 402 412 # Bazel starts a local server and needs to bind a local address. 403 413 __darwinAllowLocalNetworking = true; 404 414 405 - buildInputs = [ buildJdk ] ++ defaultShellUtils; 415 + buildInputs = [ buildJdk bashWithDefaultShellUtils ] ++ defaultShellUtils; 406 416 407 417 # when a command can’t be found in a bazel build, you might also 408 418 # need to add it to `defaultShellPath`.