diff options
Diffstat (limited to 'nixpkgs/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix')
-rw-r--r-- | nixpkgs/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/nixpkgs/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix b/nixpkgs/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix index 47e01c5ad807..d7943ef25844 100644 --- a/nixpkgs/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix +++ b/nixpkgs/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix @@ -1,4 +1,4 @@ -{ stdenv, callPackage, lib, fetchurl, fetchFromGitHub, installShellFiles +{ stdenv, callPackage, lib, fetchurl, fetchpatch, fetchFromGitHub, installShellFiles , runCommand, runCommandCC, makeWrapper, recurseIntoAttrs # this package (through the fixpoint glass) , bazel_self @@ -27,12 +27,12 @@ }: let - version = "4.2.1"; + version = "4.2.2"; sourceRoot = "."; src = fetchurl { url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip"; - sha256 = "Eup6oR4r2xLeHc65k5oi6W9aSAQ3yxfBIzedjg/fXoI="; + sha256 = "mYHQ1To1bE6HlihHdQqXyegFTkYIVHSABsgPDX4rLTM="; }; # Update with `eval $(nix-build -A bazel.updater)`, @@ -40,7 +40,7 @@ let srcDeps = lib.attrsets.attrValues srcDepsSet; srcDepsSet = let - srcs = (builtins.fromJSON (builtins.readFile ./src-deps.json)); + srcs = lib.importJSON ./src-deps.json; toFetchurl = d: lib.attrsets.nameValuePair d.name (fetchurl { urls = d.urls; sha256 = d.sha256; @@ -75,7 +75,7 @@ let for i in ${builtins.toString srcDeps}; do cp $i $out/$(stripHash $i); done ''; - defaultShellPath = lib.makeBinPath + defaultShellUtils = # Keep this list conservative. For more exotic tools, prefer to use # @rules_nixpkgs to pull in tools from the nix repository. Example: # @@ -103,7 +103,27 @@ let # ], # ) # - [ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip file zip python27 python3 ]; + # Some of the scripts explicitly depend on Python 2.7. Otherwise, we + # default to using python3. Therefore, both python27 and python3 are + # runtime dependencies. + [ + bash + coreutils + file + findutils + gawk + gnugrep + gnused + gnutar + gzip + python27 + python3 + unzip + which + zip + ]; + + defaultShellPath = lib.makeBinPath defaultShellUtils; # Java toolchain used for the build and tests javaToolchain = "@bazel_tools//tools/jdk:toolchain_${buildJdkName}"; @@ -177,7 +197,7 @@ stdenv.mkDerivation rec { homepage = "https://github.com/bazelbuild/bazel/"; description = "Build tool that builds code quickly and reliably"; license = licenses.asl20; - maintainers = [ maintainers.mboes ]; + maintainers = lib.teams.bazel.members; inherit platforms; }; @@ -208,6 +228,11 @@ stdenv.mkDerivation rec { strictActionEnvPatch = defaultShellPath; }) + (substituteAll { + src = ./actions_path.patch; + actionsPathPatch = defaultShellPath; + }) + # bazel reads its system bazelrc in /etc # override this path to a builtin one (substituteAll { @@ -227,7 +252,7 @@ stdenv.mkDerivation rec { runLocal = name: attrs: script: let attrs' = removeAttrs attrs [ "buildInputs" ]; - buildInputs = [ python3 ] ++ (attrs.buildInputs or []); + buildInputs = [ python3 which ] ++ (attrs.buildInputs or []); in runCommandCC name ({ inherit buildInputs; @@ -350,32 +375,6 @@ stdenv.mkDerivation rec { # Bazel starts a local server and needs to bind a local address. __darwinAllowLocalNetworking = true; - # Bazel expects several utils to be available in Bash even without PATH. Hence this hack. - customBash = writeCBin "bash" '' - #include <stdio.h> - #include <stdlib.h> - #include <string.h> - #include <unistd.h> - - extern char **environ; - - int main(int argc, char *argv[]) { - char *path = getenv("PATH"); - char *pathToAppend = "${defaultShellPath}"; - char *newPath; - if (path != NULL) { - int length = strlen(path) + 1 + strlen(pathToAppend) + 1; - newPath = malloc(length * sizeof(char)); - snprintf(newPath, length, "%s:%s", path, pathToAppend); - } else { - newPath = pathToAppend; - } - setenv("PATH", newPath, 1); - execve("${bash}/bin/bash", argv, environ); - return 0; - } - ''; - postPatch = let darwinPatches = '' @@ -434,8 +433,8 @@ stdenv.mkDerivation rec { substituteInPlace tools/objc/j2objc_dead_code_pruner.py --replace "$!/usr/bin/python2.7" "#!${python27}/bin/python" # md5sum is part of coreutils - sed -i 's|/sbin/md5|md5sum|' \ - src/BUILD + sed -i 's|/sbin/md5|md5sum|g' \ + src/BUILD third_party/ijar/test/testenv.sh tools/objc/libtool.sh # replace initial value of pythonShebang variable in BazelPythonSemantics.java substituteInPlace src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java \ @@ -448,8 +447,8 @@ stdenv.mkDerivation rec { # We default to python3 where possible. See also `postFixup` where # python3 is added to $out/nix-support substituteInPlace "$path" \ - --replace /bin/bash ${customBash}/bin/bash \ - --replace "/usr/bin/env bash" ${customBash}/bin/bash \ + --replace /bin/bash ${bash}/bin/bash \ + --replace "/usr/bin/env bash" ${bash}/bin/bash \ --replace "/usr/bin/env python" ${python3}/bin/python \ --replace /usr/bin/env ${coreutils}/bin/env \ --replace /bin/true ${coreutils}/bin/true @@ -457,17 +456,17 @@ stdenv.mkDerivation rec { # bazel test runner include references to /bin/bash substituteInPlace tools/build_rules/test_rules.bzl \ - --replace /bin/bash ${customBash}/bin/bash + --replace /bin/bash ${bash}/bin/bash for i in $(find tools/cpp/ -type f) do substituteInPlace $i \ - --replace /bin/bash ${customBash}/bin/bash + --replace /bin/bash ${bash}/bin/bash done # Fixup scripts that generate scripts. Not fixed up by patchShebangs below. substituteInPlace scripts/bootstrap/compile.sh \ - --replace /bin/bash ${customBash}/bin/bash + --replace /bin/bash ${bash}/bin/bash # add nix environment vars to .bazelrc cat >> .bazelrc <<EOF @@ -488,6 +487,8 @@ stdenv.mkDerivation rec { build --host_javabase='@local_jdk//:jdk' build --host_java_toolchain='${javaToolchain}' build --verbose_failures + build --curses=no + build --sandbox_debug EOF # add the same environment vars to compile.sh @@ -500,6 +501,8 @@ stdenv.mkDerivation rec { -e "/\$command \\\\$/a --host_javabase='@local_jdk//:jdk' \\\\" \ -e "/\$command \\\\$/a --host_java_toolchain='${javaToolchain}' \\\\" \ -e "/\$command \\\\$/a --verbose_failures \\\\" \ + -e "/\$command \\\\$/a --curses=no \\\\" \ + -e "/\$command \\\\$/a --sandbox_debug \\\\" \ -i scripts/bootstrap/compile.sh # This is necessary to avoid: @@ -521,21 +524,18 @@ stdenv.mkDerivation rec { in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches + genericPatches; - buildInputs = [ - buildJdk - python3 - ]; + buildInputs = [buildJdk] ++ defaultShellUtils; # when a command can’t be found in a bazel build, you might also # need to add it to `defaultShellPath`. nativeBuildInputs = [ + coreutils installShellFiles - zip + makeWrapper python3 unzip - makeWrapper which - customBash + zip ] ++ lib.optionals (stdenv.isDarwin) [ cctools libcxx CoreFoundation CoreServices Foundation ]; # Bazel makes extensive use of symlinks in the WORKSPACE. @@ -565,7 +565,7 @@ stdenv.mkDerivation rec { # Note that .bazelversion is always correct and is based on bazel-* # executable name, version checks should work fine export EMBED_LABEL="${version}- (@non-git)" - ${customBash}/bin/bash ./bazel_src/compile.sh + ${bash}/bin/bash ./bazel_src/compile.sh ./bazel_src/scripts/generate_bash_completion.sh \ --bazel=./bazel_src/output/bazel \ --output=./bazel_src/output/bazel-complete.bash \ @@ -617,7 +617,9 @@ stdenv.mkDerivation rec { ./bazel_src/output/bazel-complete.fish ''; - doInstallCheck = true; + # Install check fails on `aarch64-darwin` + # https://github.com/NixOS/nixpkgs/issues/145587 + doInstallCheck = stdenv.hostPlatform.system != "aarch64-darwin"; installCheckPhase = '' export TEST_TMPDIR=$(pwd) @@ -655,16 +657,10 @@ stdenv.mkDerivation rec { ''; # Save paths to hardcoded dependencies so Nix can detect them. + # This is needed because the templates get tar’d up into a .jar. postFixup = '' mkdir -p $out/nix-support - echo "${customBash} ${defaultShellPath}" >> $out/nix-support/depends - # The templates get tar’d up into a .jar, - # so nix can’t detect python is needed in the runtime closure - # Some of the scripts explicitly depend on Python 2.7. Otherwise, we - # default to using python3. Therefore, both python27 and python3 are - # runtime dependencies. - echo "${python27}" >> $out/nix-support/depends - echo "${python3}" >> $out/nix-support/depends + echo "${defaultShellPath}" >> $out/nix-support/depends '' + lib.optionalString stdenv.isDarwin '' echo "${cctools}" >> $out/nix-support/depends ''; |