3
0
Fork 0
forked from mirrors/nixpkgs

bazel: fix java toolchain regression

By changing the default toolchain to JDK8, we broke the default Java
toolchain, which assumes JDK9.

Instead, set `host_java_toolchain` manually for our build of bazel,
and set `java_toolchain` to run the java tests with the build JDK as
well.

Fixes https://github.com/NixOS/nixpkgs/issues/54289
This commit is contained in:
Philip Patsch 2019-01-28 11:51:09 +01:00 committed by Profpatsch
parent 7e6662a275
commit 5c6892e1a2
2 changed files with 13 additions and 8 deletions

View file

@ -1,10 +1,11 @@
{ stdenv, callPackage, lib, fetchurl, fetchpatch, runCommand, makeWrapper
, jdk, zip, unzip, bash, writeCBin, coreutils
, zip, unzip, bash, writeCBin, coreutils
, which, python, perl, gawk, gnused, gnutar, gnugrep, gzip, findutils
# Apple dependencies
, cctools, clang, libcxx, CoreFoundation, CoreServices, Foundation
# Allow to independently override the jdks used to build and run respectively
, buildJdk ? jdk, runJdk ? jdk
, buildJdk, runJdk
, buildJdkName
# Always assume all markers valid (don't redownload dependencies).
# Also, don't clean up environment variables.
, enableNixHacks ? false
@ -53,6 +54,9 @@ let
#
[ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip ];
# Java toolchain used for the build and tests
javaToolchain = "@bazel_tools//tools/jdk:toolchain_host${buildJdkName}";
in
stdenv.mkDerivation rec {
@ -177,11 +181,6 @@ stdenv.mkDerivation rec {
substituteInPlace scripts/bootstrap/compile.sh \
--replace /bin/sh ${customBash}/bin/bash
# We only build with JDK8 for now, since JDK11 does not compile bazel
substituteInPlace tools/jdk/default_java_toolchain.bzl \
--replace '"jvm_opts": JDK9_JVM_OPTS' \
'"jvm_opts": JDK8_JVM_OPTS'
# add nix environment vars to .bazelrc
cat >> .bazelrc <<EOF
build --experimental_distdir=${distDir}
@ -191,6 +190,7 @@ stdenv.mkDerivation rec {
build --linkopt="-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt="-Wl,/g')"
build --host_linkopt="-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt="-Wl,/g')"
build --host_javabase='@local_jdk//:jdk'
build --host_java_toolchain='${javaToolchain}'
EOF
# add the same environment vars to compile.sh
@ -199,6 +199,7 @@ stdenv.mkDerivation rec {
-e "/\$command \\\\$/a --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\" \\\\" \
-e "/\$command \\\\$/a --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\" \\\\" \
-e "/\$command \\\\$/a --host_javabase='@local_jdk//:jdk' \\\\" \
-e "/\$command \\\\$/a --host_java_toolchain='${javaToolchain}' \\\\" \
-i scripts/bootstrap/compile.sh
# --experimental_strict_action_env (which will soon become the
@ -268,7 +269,9 @@ stdenv.mkDerivation rec {
export TEST_TMPDIR=$(pwd)
hello_test () {
$out/bin/bazel test --test_output=errors \
$out/bin/bazel test \
--test_output=errors \
--java_toolchain='${javaToolchain}' \
examples/cpp:hello-success_test \
examples/java-native/src/test/java/com/example/myproject:hello
}

View file

@ -8282,6 +8282,8 @@ in
bazel = callPackage ../development/tools/build-managers/bazel {
inherit (darwin) cctools;
inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Foundation;
buildJdk = jdk8;
buildJdkName = "jdk8";
runJdk = jdk11;
};