about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorLuke Granger-Brown <git@lukegb.com>2020-07-04 23:24:35 +0000
committerProfpatsch <mail@profpatsch.de>2020-07-17 18:29:58 +0200
commitd7d4a926957de29e8e618d1c848e2036ea98d9cc (patch)
tree61086b5f1bb6631f21f5dfe99d2e64ce81ef7a91 /pkgs/build-support
parentb6eca9a2afa143bcbee3b4ae1bdc13993bc71784 (diff)
buildBazelPackage: add "fetchConfigured" for fetching only things required for the build
"bazel fetch" will, by default, fetch everything that _might_ be used,
including things that will later be discarded due to the way the build
is configured.

Concretely, this means that for some builds of Java packages, this will
avoid failures where the builder tries to retrieve the JDK from /usr/share/java
(or equivalent).

This also means that for most packages we can fetch _fewer_ dependencies,
since the standard tree pruning for artifacts to fetch will take effect.

fetchConfigured is disabled by default since it changes the fetch hashes
of tensorflow/tensorflow2 (since it ends up fetching less).
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/build-bazel-package/default.nix12
1 files changed, 10 insertions, 2 deletions
diff --git a/pkgs/build-support/build-bazel-package/default.nix b/pkgs/build-support/build-bazel-package/default.nix
index 31c0c8e92e569..bbcbc4e2e11df 100644
--- a/pkgs/build-support/build-bazel-package/default.nix
+++ b/pkgs/build-support/build-bazel-package/default.nix
@@ -30,6 +30,13 @@ args@{
 , removeRulesCC ? true
 , removeLocalConfigCc ? true
 , removeLocal ? true
+
+# Use build --nobuild instead of fetch. This allows fetching the dependencies
+# required for the build as configured, rather than fetching all the dependencies
+# which may not work in some situations (e.g. Java code which ends up relying on
+# Debian-specific /usr/share/java paths, but doesn't in the configured build).
+, fetchConfigured ? false
+
 , ...
 }:
 
@@ -79,7 +86,7 @@ in stdenv.mkDerivation (fBuildAttrs // {
       bazel \
         --output_base="$bazelOut" \
         --output_user_root="$bazelUserRoot" \
-        fetch \
+        ${if fetchConfigured then "build --nobuild" else "fetch"} \
         --loading_phase_threads=1 \
         $bazelFlags \
         $bazelFetchFlags \
@@ -112,7 +119,8 @@ in stdenv.mkDerivation (fBuildAttrs // {
       # platforms -> NIX_BUILD_TOP/tmp/install/35282f5123611afa742331368e9ae529/_embedded_binaries/platforms
       find $bazelOut/external -maxdepth 1 -type l | while read symlink; do
         name="$(basename "$symlink")"
-        rm "$symlink" "$bazelOut/external/@$name.marker"
+        rm "$symlink"
+        test -f "$bazelOut/external/@$name.marker" && rm "$bazelOut/external/@$name.marker"
       done
 
       # Patching symlinks to remove build directory reference