Build ONOS exclusively with Bazel-provided remote JDK
This change make it possible to build ONOS in a host system without JDK
installed, or ignoring the one installed, instead relying exclusively on
the "remote" JDK provided by Bazel. The JDK version, along with the
toolchain configuration (language source and target values), are checked
in as part of the build files (tools/build/bazel/BUILD), thus enabling
deterministic builds that are less dependent of the host environment.
To allow this, this change replaces all references to JDK-related tools
expected to be on the host PATH, such as the jar command, with their
counterpart from the remote JDK (now a sandboxed relative path). This is
achieved by:
* Creating a new "jdk_genrule" macro that exposes the remote JDK bin
directory to the PATH visible by the genrule command. This is used
for all genrule targets invoking for example `jar`;
* Modifying custom Starlak rule implementations by replacing
invocation to JDK tools with a path from the remote one.
* Renaming the onos/lib directory to onos/deps as it clashes with
the Bazel-provided JDK's lib directory (that for some strange reason
is resolved on the ONOS workspace)
Finally, this change is reflected on the Dockerfile which now builds
ONOS from an Ubuntu image with no JDK installed.
Change-Id: Ie7d990cfce6fef00ddb4ffffe4c6205b8530fb47
diff --git a/tools/build/bazel/BUILD b/tools/build/bazel/BUILD
index cf20246..57f700d 100644
--- a/tools/build/bazel/BUILD
+++ b/tools/build/bazel/BUILD
@@ -1,15 +1,20 @@
load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")
-# This is where we define the language source and target values passed to javac
-# when building ONOS. This toolchain should be used when invoking bazel build
+# This is where we define the JDK used to build ONOS, as well as the language
+# source and target values passed to javac. The :default_toolchain and
+# :default_jdk are expected to be passed as arguments when invoking bazel build
# (see onos/.bazelrc)
default_java_toolchain(
name = "default_toolchain",
source_version = "11",
target_version = "11",
- visibility = [
- "//visibility:public",
- ],
+ visibility = ["//visibility:public"],
+)
+
+alias(
+ name = "default_jdk",
+ actual = "@bazel_tools//tools/jdk:remote_jdk11",
+ visibility = ["//visibility:public"],
)
py_binary(