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