@@ -2,7 +2,7 @@
22# this package (through the fixpoint glass)
33, bazel
44, lr, xe, zip, unzip, bash, writeCBin, coreutils
5−, which, python, gawk, gnused, gnutar, gnugrep, gzip, findutils
5+, which, gawk, gnused, gnutar, gnugrep, gzip, findutils
66# updater
77, python3, writeScript
88# Apple dependencies
@@ -14,38 +14,41 @@
1414# Always assume all markers valid (don't redownload dependencies).
1515# Also, don't clean up environment variables.
1616, enableNixHacks ? false
17+, gcc-unwrapped
18+, autoPatchelfHook
1719}:
1820
1921let
20− version = "0.26.1";
22+ version = "0.27.0";
2123
2224 src = fetchurl {
2325 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
24− sha256 = "000ny51hwnjyizm1md4w8q7m832jhf3c767pgbvg6nc7h67lzsf0";
26+ sha256 = "0yn662dzgfr8ls4avfl12k5sr4f210bab12wml18bh4sjlxhs263";
2527 };
2628
2729 # Update with `eval $(nix-build -A bazel.updater)`,
2830 # then add new dependencies from the dict in ./src-deps.json as required.
29− srcDeps =
31+ srcDeps = lib.attrsets.attrValues srcDepsSet;
32+ srcDepsSet =
3033 let
3134 srcs = (builtins.fromJSON (builtins.readFile ./src-deps.json));
32− toFetchurl = d: fetchurl {
35+ toFetchurl = d: lib.attrsets.nameValuePair d.name (fetchurl {
3336 name = d.name;
3437 urls = d.urls;
3538 sha256 = d.sha256;
36− };
37− in map toFetchurl [
39+ });
40+ in builtins.listToAttrs (map toFetchurl [
3841 srcs.desugar_jdk_libs
3942 srcs.io_bazel_skydoc
4043 srcs.bazel_skylib
4144 srcs.io_bazel_rules_sass
4245 (if stdenv.hostPlatform.isDarwin
43− then srcs.${"java_tools_javac10_darwin-v3.2.zip"}
44− else srcs.${"java_tools_javac10_linux-v3.2.zip"})
46+ then srcs.${"java_tools_javac11_darwin-v2.0.zip"}
47+ else srcs.${"java_tools_javac11_linux-v2.0.zip"})
4548 srcs.${"coverage_output_generator-v1.0.zip"}
4649 srcs.build_bazel_rules_nodejs
47− srcs.${"android_tools_pkg-0.2.tar.gz"}
48− ];
50+ srcs.${"android_tools_pkg-0.4.tar.gz"}
51+ ]);
4952
5053 distDir = runCommand "bazel-deps" {} ''
5154 mkdir -p $out
@@ -87,6 +90,33 @@ let
8790
8891 platforms = lib.platforms.linux ++ lib.platforms.darwin;
8992
93+ # This repository is fetched by bazel at runtime
94+ # however it contains prebuilt java binaries, with wrong interpreter
95+ # and libraries path.
96+ # We prefetch it, patch it, and override it in a global bazelrc.
97+ system = if stdenv.hostPlatform.isDarwin
98+ then "darwin" else "linux";
99+
100+ remote_java_tools = stdenv.mkDerivation {
101+ name = "remote_java_tools_${system}";
102+
103+ src = srcDepsSet."java_tools_javac11_${system}-v2.0.zip";
104+
105+ nativeBuildInputs = [ autoPatchelfHook unzip ];
106+ buildInputs = [ gcc-unwrapped ];
107+
108+ sourceRoot = ".";
109+
110+ buildPhase = ''
111+ mkdir $out;
112+ '';
113+
114+ installPhase = ''
115+ cp -Ra * $out/
116+ touch $out/WORKSPACE
117+ '';
118+ };
119+
90120in
91121stdenv.mkDerivation rec {
92122 name = "bazel-${version}";
@@ -117,6 +147,7 @@ stdenv.mkDerivation rec {
117147 runLocal = name: attrs: script: runCommandCC name ({
118148 preferLocalBuild = true;
119149 meta.platforms = platforms;
150+ buildInputs = [ python3 ];
120151 } // attrs) script;
121152
122153 # bazel wants to extract itself into $install_dir/install every time it runs,
@@ -258,8 +289,8 @@ stdenv.mkDerivation rec {
258289 # Substitute python's stub shebang to plain python path. (see TODO add pr URL)
259290 # See also `postFixup` where python is added to $out/nix-support
260291 substituteInPlace src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt\
261− --replace "/usr/bin/env python" "${python}/bin/python" \
262− --replace "NIX_STORE_PYTHON_PATH" "${python}/bin/python" \
292+ --replace "/usr/bin/env python" "${python3}/bin/python" \
293+ --replace "NIX_STORE_PYTHON_PATH" "${python3}/bin/python" \
263294
264295 # md5sum is part of coreutils
265296 sed -i 's|/sbin/md5|md5sum|' \
@@ -275,6 +306,11 @@ stdenv.mkDerivation rec {
275306 --replace /bin/true ${coreutils}/bin/true
276307 done
277308
309+ # bazel test runner include references to /bin/bash
310+ substituteInPlace tools/build_rules/test_rules.bzl \
311+ --replace /bin/bash ${customBash}/bin/bash
312+
313+
278314 # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
279315 substituteInPlace scripts/bootstrap/compile.sh \
280316 --replace /bin/bash ${customBash}/bin/bash
@@ -323,19 +359,26 @@ stdenv.mkDerivation rec {
323359 mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash
324360
325361 patchShebangs .
362+
363+ # bazel reads its system bazelrc in /etc
364+ # override this path to a builtin one
365+ substituteInPlace \
366+ src/main/cpp/option_processor.cc \
367+ --replace BAZEL_SYSTEM_BAZELRC_PATH "\"$out/etc/bazelrc\""
326368 '';
327369 in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches
328370 + genericPatches;
329371
330372 buildInputs = [
331373 buildJdk
374+ python3
332375 ];
333376
334377 # when a command can’t be found in a bazel build, you might also
335378 # need to add it to `defaultShellPath`.
336379 nativeBuildInputs = [
337380 zip
338− python
381+ python3
339382 unzip
340383 makeWrapper
341384 which
@@ -375,20 +418,40 @@ stdenv.mkDerivation rec {
375418
376419 wrapProgram "$out/bin/bazel" --add-flags --server_javabase="${runJdk}"
377420
421+ # generates the system bazelrc
422+ # warning: the name of the repository depends on the system, hence
423+ # the reference to .name
424+ mkdir $out/etc
425+ echo "build --override_repository=${remote_java_tools.name}=${remote_java_tools}" > $out/etc/bazelrc
426+
378427 # shell completion files
379428 mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions
380429 mv ./bazel_src/output/bazel-complete.bash $out/share/bash-completion/completions/bazel
381430 cp ./bazel_src/scripts/zsh_completion/_bazel $out/share/zsh/site-functions/
382431 '';
383432
384− # Temporarily disabling for now. A new approach is needed for this derivation as Bazel
385− # accesses the internet during the tests which fails in a sandbox.
386− doInstallCheck = false;
433+ doInstallCheck = true;
387434 installCheckPhase = ''
388435 export TEST_TMPDIR=$(pwd)
389436
437+ tar xf ${srcDepsSet.io_bazel_skydoc} -C $TEST_TMPDIR
438+ mv $(ls | grep skydoc-) io_bazel_skydoc
439+
440+ tar xf ${srcDepsSet.bazel_skylib} -C $TEST_TMPDIR
441+ mv $(ls | grep bazel-skylib-) bazel_skylib
442+
443+ tar xf ${srcDepsSet.io_bazel_rules_sass} -C $TEST_TMPDIR
444+ mv $(ls | grep rules_sass-) rules_sass
445+
446+ unzip ${srcDepsSet.build_bazel_rules_nodejs} -d $TEST_TMPDIR
447+ mv rules_nodejs-0.16.2 build_bazel_rules_nodejs
448+
390449 hello_test () {
391450 $out/bin/bazel test \
451+ --override_repository=io_bazel_skydoc=$TEST_TMPDIR/io_bazel_skydoc \
452+ --override_repository=bazel_skylib=$TEST_TMPDIR/bazel_skylib \
453+ --override_repository=io_bazel_rules_sass=$TEST_TMPDIR/rules_sass \
454+ --override_repository=build_bazel_rules_nodejs=$TEST_TMPDIR/build_bazel_rules_nodejs \
392455 --test_output=errors \
393456 --java_toolchain='${javaToolchain}' \
394457 examples/cpp:hello-success_test \
@@ -424,7 +487,7 @@ stdenv.mkDerivation rec {
424487 echo "${customBash} ${defaultShellPath}" >> $out/nix-support/depends
425488 # The templates get tar’d up into a .jar,
426489 # so nix can’t detect python is needed in the runtime closure
427− echo "${python}" >> $out/nix-support/depends
490+ echo "${python3}" >> $out/nix-support/depends
428491 '';
429492
430493 dontStrip = true;