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 :)
This commit is contained in:
Marco Farrugia 2020-09-23 22:56:41 -04:00 committed by Profpatsch
parent 67d2de5ffa
commit a360b05cb7

View File

@ -48,9 +48,10 @@ let
srcs.bazel_skylib srcs.bazel_skylib
srcs.io_bazel_rules_sass srcs.io_bazel_rules_sass
srcs.platforms srcs.platforms
(if stdenv.hostPlatform.isDarwin # `bazel query` wants all of these to be available regardless of platform.
then srcs."java_tools_javac11_darwin-v8.0.zip" srcs."java_tools_javac11_darwin-v8.0.zip"
else srcs."java_tools_javac11_linux-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."coverage_output_generator-v2.1.zip"
srcs.build_bazel_rules_nodejs srcs.build_bazel_rules_nodejs
srcs."android_tools_pkg-0.19.0rc1.tar.gz" srcs."android_tools_pkg-0.19.0rc1.tar.gz"
@ -131,10 +132,21 @@ let
bazelRC = writeTextFile { bazelRC = writeTextFile {
name = "bazel-rc"; name = "bazel-rc";
text = '' text = ''
build --override_repository=${remote_java_tools.name}=${remote_java_tools}
build --distdir=${distDir}
startup --server_javabase=${runJdk} 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 # load default location for the system wide configuration
try-import /etc/bazel.bazelrc try-import /etc/bazel.bazelrc
''; '';
@ -534,7 +546,7 @@ stdenv.mkDerivation rec {
export TEST_TMPDIR=$(pwd) export TEST_TMPDIR=$(pwd)
hello_test () { hello_test () {
$out/bin/bazel test --distdir=${distDir} \ $out/bin/bazel test \
--test_output=errors \ --test_output=errors \
--java_toolchain='${javaToolchain}' \ --java_toolchain='${javaToolchain}' \
examples/cpp:hello-success_test \ examples/cpp:hello-success_test \