about summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers/bazel
diff options
context:
space:
mode:
authorMarco Farrugia <afmarco@gmail.com>2020-09-23 22:56:41 -0400
committerProfpatsch <mail@profpatsch.de>2020-10-19 18:32:48 +0200
commita360b05cb719c26260eb6d37762549f419dd98d5 (patch)
treeb19305412c44e39ea695a2e2db7c1895a302a680 /pkgs/development/tools/build-managers/bazel
parent67d2de5ffaa6766a71b077a331b1cad07b7e3a80 (diff)
bazel: Fix bazel query and provide a default java toolchain
These are fixes for problems I ran into with:
- `bazel test //example:cpp-test`
This needed `build --host_javabase='@local_jdk//:jdk'`

- `bazel query 'deps(//example:cpp-test)'`
This needed the same flags as `build`.

Is it contentious to (partially?) configure the default java toolchain? I don't see it as much different than providing the bazel server's java.
It would continue to be configurable/overridable by overriding the flags. 

---
And a random notes from this escapade, but https://github.com/bazelbuild/bazel/blob/master/WORKSPACE#L144-L308 looks a little different from https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/build-managers/bazel/bazel_3/src-deps.json so one of them is probably wrong :)
Diffstat (limited to 'pkgs/development/tools/build-managers/bazel')
-rw-r--r--pkgs/development/tools/build-managers/bazel/bazel_3/default.nix24
1 files changed, 18 insertions, 6 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix
index 0bfc9071d7e6d..1aed3fe442972 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix
@@ -48,9 +48,10 @@ let
       srcs.bazel_skylib
       srcs.io_bazel_rules_sass
       srcs.platforms
-      (if stdenv.hostPlatform.isDarwin
-       then srcs."java_tools_javac11_darwin-v8.0.zip"
-       else srcs."java_tools_javac11_linux-v8.0.zip")
+      # `bazel query` wants all of these to be available regardless of platform.
+      srcs."java_tools_javac11_darwin-v8.0.zip"
+      srcs."java_tools_javac11_linux-v8.0.zip"
+      srcs."java_tools_javac11_windows-v8.0.zip"
       srcs."coverage_output_generator-v2.1.zip"
       srcs.build_bazel_rules_nodejs
       srcs."android_tools_pkg-0.19.0rc1.tar.gz"
@@ -131,10 +132,21 @@ let
   bazelRC = writeTextFile {
     name = "bazel-rc";
     text = ''
-      build --override_repository=${remote_java_tools.name}=${remote_java_tools}
-      build --distdir=${distDir}
       startup --server_javabase=${runJdk}
 
+      # Can't use 'common'; https://github.com/bazelbuild/bazel/issues/3054
+      # Most commands inherit from 'build' anyway.
+      build --distdir=${distDir}
+      fetch --distdir=${distDir}
+      query --distdir=${distDir}
+
+      build --override_repository=${remote_java_tools.name}=${remote_java_tools}
+      fetch --override_repository=${remote_java_tools.name}=${remote_java_tools}
+      query --override_repository=${remote_java_tools.name}=${remote_java_tools}
+      
+      # Provide a default java toolchain, this will be the same as ${runJdk}
+      build --host_javabase='@local_jdk//:jdk'
+
       # load default location for the system wide configuration
       try-import /etc/bazel.bazelrc
     '';
@@ -534,7 +546,7 @@ stdenv.mkDerivation rec {
     export TEST_TMPDIR=$(pwd)
 
     hello_test () {
-      $out/bin/bazel test --distdir=${distDir} \
+      $out/bin/bazel test \
         --test_output=errors \
         --java_toolchain='${javaToolchain}' \
         examples/cpp:hello-success_test \