Partial revert "Automated rollback of commit 22893a02ae09e44e3288ec3552d7bd128ae02dc0." NEW: keeping public visibility of java/constraints:srcs This reverts commit 9ed77445b61749d7b54c39ebdcacb194b3e60833.
diff --git a/BUILD b/BUILD index f59256b..b87a792 100644 --- a/BUILD +++ b/BUILD
@@ -7,8 +7,8 @@ srcs = [ "BUILD", "LICENSE", - ] + glob([ - "*.bzl", - ]), + "//java:srcs", + "//toolchains:srcs", + ], visibility = ["@//distro:__pkg__"], )
diff --git a/distro/BUILD b/distro/BUILD index 475697a..71352e8 100644 --- a/distro/BUILD +++ b/distro/BUILD
@@ -9,10 +9,7 @@ # Build the artifact to put on the github release page. pkg_tar( name = "rules_java-%s" % version, - srcs = [ - "//:distribution", - "//java:distribution", - ], + srcs = ["//:distribution"], extension = "tar.gz", # It is all source code, so make it read-only. mode = "0444",
diff --git a/java/BUILD b/java/BUILD index abf9526..103b99a 100644 --- a/java/BUILD +++ b/java/BUILD
@@ -2,15 +2,12 @@ licenses(["notice"]) -# TODO(aiuto): Find a way to strip this rule from the distribution tarball. filegroup( - name = "distribution", + name = "srcs", srcs = glob([ "**", ]) + [ "//java/constraints:srcs", ], - visibility = [ - "@//distro:__pkg__", - ], + visibility = ["@//:__pkg__"], )
diff --git a/java/defs.bzl b/java/defs.bzl index 5ea8c19..4c179a5 100644 --- a/java/defs.bzl +++ b/java/defs.bzl
@@ -15,7 +15,7 @@ _MIGRATION_TAG = "__JAVA_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" -version = "4.0.0" +version = "4.1.0" def _add_tags(attrs): if "tags" in attrs and attrs["tags"] != None:
diff --git a/java/repositories.bzl b/java/repositories.bzl index 9beaf20..492186c 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl
@@ -25,6 +25,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("//toolchains:remote_java_repository.bzl", "remote_java_repository") def java_tools_javac11_repos(): maybe( @@ -64,48 +65,64 @@ https://mirror.bazel.build/openjdk/azul-zulu-8.50.0.51-ca-jdk8.0.275/zsrc8.50.0.53-ca-fx-jdk8.0.275.zip """ maybe( - http_archive, + remote_java_repository, name = "remote_jdk8_linux_aarch64", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], sha256 = "f4072e82faa5a09fab2accf2892d4684324fc999d614583c3ff785e87c03963f", strip_prefix = "zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-8.50.0.51-ca-jdk8.0.275/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz", "https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz", ], + version = "8", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk8_linux", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], sha256 = "1db6b2fa642950ee1b4b1ec2b6bc8a9113d7a4cd723f79398e1ada7dab1c981c", strip_prefix = "zulu8.50.0.51-ca-jdk8.0.275-linux_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-8.50.0.51-ca-jdk8.0.275/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz", "https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz", ], + version = "8", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk8_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], sha256 = "b03176597734299c9a15b7c2cc770783cf14d121196196c1248e80c026b59c17", strip_prefix = "zulu8.50.0.51-ca-jdk8.0.275-macosx_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-8.50.0.51-ca-jdk8.0.275/zulu8.50.0.51-ca-jdk8.0.275-macosx_x64.tar.gz", "https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-macosx_x64.tar.gz", ], + version = "8", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk8_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], sha256 = "49759b2bd2ab28231a21ff3a3bb45824ddef55d89b5b1a05a62e26a365da0774", strip_prefix = "zulu8.50.0.51-ca-jdk8.0.275-win_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-8.50.0.51-ca-jdk8.0.275/zulu8.50.0.51-ca-jdk8.0.275-win_x64.zip", "https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-win_x64.zip", ], + version = "8", ) def remote_jdk9_repos(): @@ -117,9 +134,12 @@ https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zsrc9.0.7.1-jdk9.0.7.zip """ maybe( - http_archive, + remote_java_repository, name = "remote_jdk9_linux_aarch64", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], sha256 = "72e7843902b0395e2d30e1e9ad2a5f05f36a4bc62529828bcbc698d54aec6022", strip_prefix = "jdk9-server-release-1708", urls = [ @@ -127,35 +147,48 @@ "https://mirror.bazel.build/openjdk.linaro.org/releases/jdk9-server-release-170bazel_skylib8.tar.xz", "http://openjdk.linaro.org/releases/jdk9-server-release-1708.tar.xz", ], + version = "9", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk9_linux", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], sha256 = "45f2dfbee93b91b1468cf81d843fc6d9a47fef1f831c0b7ceff4f1eb6e6851c8", strip_prefix = "zulu9.0.7.1-jdk9.0.7-linux_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-linux_x64.tar.gz", ], + version = "9", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk9_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], strip_prefix = "zulu9.0.7.1-jdk9.0.7-macosx_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-macosx_x64.tar.gz", ], + version = "9", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk9_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], strip_prefix = "zulu9.0.7.1-jdk9.0.7-win_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-win_x64.zip", ], + version = "9", ) def remote_jdk10_repos(): @@ -168,9 +201,12 @@ """ maybe( - http_archive, + remote_java_repository, name = "remote_jdk10_linux_aarch64", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], sha256 = "b7098b7aaf6ee1ffd4a2d0371a0be26c5a5c87f6aebbe46fe9a92c90583a84be", strip_prefix = "jdk10-server-release-1804", urls = [ @@ -178,36 +214,49 @@ "https://mirror.bazel.build/openjdk.linaro.org/releases/jdk10-server-release-1804.tar.xz", "http://openjdk.linaro.org/releases/jdk10-server-release-1804.tar.xz", ], + version = "10", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk10_linux", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], sha256 = "b3c2d762091a615b0c1424ebbd05d75cc114da3bf4f25a0dec5c51ea7e84146f", strip_prefix = "zulu10.2+3-jdk10.0.1-linux_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-linux_x64.tar.gz", ], + version = "10", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk10_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], sha256 = "7394d5f41804cfbdb47c609879c4e738bf53358484ea0995076190915b94c702", strip_prefix = "zulu10.2+3-jdk10.0.1-macosx_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-macosx_x64.tar.gz", ], + version = "10", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk10_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], sha256 = "fd9456b53dab8b9f504ed0f0e2f6305bd0815978d0e02a41643d111290bf940c", strip_prefix = "zulu10.2+3-jdk10.0.1-win_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-win_x64.zip", ], + version = "10", ) def remote_jdk11_repos(): @@ -220,67 +269,79 @@ """ maybe( - http_archive, + remote_java_repository, name = "remote_jdk11_linux_aarch64", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", sha256 = "a452f1b9682d9f83c1c14e54d1446e1c51b5173a3a05dcb013d380f9508562e4", strip_prefix = "zulu11.37.48-ca-jdk11.0.6-linux_aarch64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu11.37.48-ca-jdk11.0.6/zulu11.37.48-ca-jdk11.0.6-linux_aarch64.tar.gz", ], + version = "11", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk11_linux", build_file = "@bazel_tools//tools/jdk:jdk.BUILD", sha256 = "360626cc19063bc411bfed2914301b908a8f77a7919aaea007a977fa8fb3cde1", - strip_prefix = "zulu11.37.17-ca-jdk11.0.6-linux_x64", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], urls = [ "https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-linux_x64.tar.gz", ], + version = "11", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk11_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", sha256 = "e1fe56769f32e2aaac95e0a8f86b5a323da5af3a3b4bba73f3086391a6cc056f", strip_prefix = "zulu11.37.17-ca-jdk11.0.6-macosx_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz", ], + version = "11", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk11_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", sha256 = "a9695617b8374bfa171f166951214965b1d1d08f43218db9a2a780b71c665c18", strip_prefix = "zulu11.37.17-ca-jdk11.0.6-win_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-win_x64.zip", ], + version = "11", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk11_linux_ppc64le", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:ppc", + ], sha256 = "a417db0295b1f4b538ecbaf7c774f3a177fab9657a665940170936c0eca4e71a", strip_prefix = "jdk-11.0.7+10", urls = [ "https://mirror.bazel.build/openjdk/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.7_10.tar.gz", "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.7_10.tar.gz", ], + version = "11", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk11_linux_s390x", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:s390x", + ], sha256 = "d9b72e87a1d3ebc0c9552f72ae5eb150fffc0298a7cb841f1ce7bfc70dcd1059", strip_prefix = "jdk-11.0.7+10", urls = [ "https://mirror.bazel.build/github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.7_10.tar.gz", "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.7_10.tar.gz", ], + version = "11", ) def remote_jdk12_repos(): @@ -290,99 +351,135 @@ https://mirror.bazel.build/openjdk/azul-zulu12.2.3-ca-jdk12.0.1/zsrc12.2.3-jdk12.0.1.zip """ maybe( - http_archive, + remote_java_repository, name = "remote_jdk12_linux", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], sha256 = "529c99841d69e11a85aea967ccfb9d0fd40b98c5b68dbe1d059002655e0a9c13", strip_prefix = "zulu12.2.3-ca-jdk12.0.1-linux_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu12.2.3-ca-jdk12.0.1/zulu12.2.3-ca-jdk12.0.1-linux_x64.tar.gz", ], + version = "12", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk12_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], sha256 = "67ca9d285056132ebb19fa237a14affda52132142e1171fe1c20e18974b3b8a5", strip_prefix = "zulu12.2.3-ca-jdk12.0.1-macosx_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu12.2.3-ca-jdk12.0.1/zulu12.2.3-ca-jdk12.0.1-macosx_x64.tar.gz", ], + version = "12", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk12_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], sha256 = "cf28404c23c3aa1115363ba6e796c30580a768e1d7d6681a7d053e516008e00d", strip_prefix = "zulu12.2.3-ca-jdk12.0.1-win_x64", urls = [ "https://mirror.bazel.build/openjdk/azul-zulu12.2.3-ca-jdk12.0.1/zulu12.2.3-ca-jdk12.0.1-win_x64.zip", ], + version = "12", ) def remote_jdk14_repos(): """Imports OpenJDK 14 repositories.""" maybe( - http_archive, + remote_java_repository, name = "remote_jdk14_linux", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], sha256 = "48bb8947034cd079ad1ef83335e7634db4b12a26743a0dc314b6b861480777aa", strip_prefix = "zulu14.28.21-ca-jdk14.0.1-linux_x64", urls = [ "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-linux_x64.tar.gz", ], + version = "14", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk14_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], sha256 = "088bd4d0890acc9f032b738283bf0f26b2a55c50b02d1c8a12c451d8ddf080dd", strip_prefix = "zulu14.28.21-ca-jdk14.0.1-macosx_x64", urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-macosx_x64.tar.gz"], + version = "14", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk14_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], sha256 = "9cb078b5026a900d61239c866161f0d9558ec759aa15c5b4c7e905370e868284", strip_prefix = "zulu14.28.21-ca-jdk14.0.1-win_x64", urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-win_x64.zip"], + version = "14", ) def remote_jdk15_repos(): """Imports OpenJDK 15 repositories.""" maybe( - http_archive, + remote_java_repository, name = "remote_jdk15_linux", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], sha256 = "0a38f1138c15a4f243b75eb82f8ef40855afcc402e3c2a6de97ce8235011b1ad", strip_prefix = "zulu15.27.17-ca-jdk15.0.0-linux_x64", urls = [ "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz", "https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz", ], + version = "15", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk15_macos", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], sha256 = "f80b2e0512d9d8a92be24497334c974bfecc8c898fc215ce0e76594f00437482", strip_prefix = "zulu15.27.17-ca-jdk15.0.0-macosx_x64", urls = [ "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-macosx_x64.tar.gz", "https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-macosx_x64.tar.gz", ], + version = "15", ) maybe( - http_archive, + remote_java_repository, name = "remote_jdk15_windows", - build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], sha256 = "f535a530151e6c20de8a3078057e332b08887cb3ba1a4735717357e72765cad6", strip_prefix = "zulu15.27.17-ca-jdk15.0.0-win_x64", urls = [ "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-win_x64.zip", "https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-win_x64.zip", ], + version = "15", ) def bazel_skylib():
diff --git a/toolchains/BUILD b/toolchains/BUILD new file mode 100644 index 0000000..67d2c89 --- /dev/null +++ b/toolchains/BUILD
@@ -0,0 +1,9 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["@//:__pkg__"], +)
diff --git a/toolchains/remote_java_repository.bzl b/toolchains/remote_java_repository.bzl new file mode 100644 index 0000000..050903c --- /dev/null +++ b/toolchains/remote_java_repository.bzl
@@ -0,0 +1,88 @@ +# Copyright 2020 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Rules for importing and registering JDKs from http archive. + +Rule remote_java_repository imports and registers JDK with the toolchain resolution. +""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def _toolchain_config_impl(ctx): + ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name = ctx.name)) + ctx.file("BUILD.bazel", ctx.attr.build_file) + +_toolchain_config = repository_rule( + local = True, + implementation = _toolchain_config_impl, + attrs = { + "build_file": attr.string(), + }, +) + +def remote_java_repository(name, version, exec_compatible_with, prefix = "remotejdk", **kwargs): + """Imports and registers a JDK from a http archive. + + Toolchain resolution is determined with exec_compatible_with + parameter and constrained with --java_runtime_version flag either having value + of "version" or "{prefix}_{version}" parameters. + + Args: + name: A unique name for this rule. + version: Version of the JDK imported. + exec_compatible_with: Platform constraints (CPU and OS) for this JDK. + prefix: Optional alternative prefix for configuration flag value used to determine this JDK. + **kwargs: Refer to http_archive documentation + """ + http_archive( + name = name, + build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + **kwargs + ) + _toolchain_config( + name = name + "_toolchain_config_repo", + build_file = """ +config_setting( + name = "prefix_version_setting", + values = {{"java_runtime_version": "{prefix}_{version}"}}, + visibility = ["//visibility:private"], +) +config_setting( + name = "version_setting", + values = {{"java_runtime_version": "{version}"}}, + visibility = ["//visibility:private"], +) +alias( + name = "version_or_prefix_version_setting", + actual = select({{ + ":version_setting": ":version_setting", + "//conditions:default": ":prefix_version_setting", + }}), + visibility = ["//visibility:private"], +) +toolchain( + name = "toolchain", + exec_compatible_with = {exec_compatible_with}, + target_settings = [":version_or_prefix_version_setting"], + toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type", + toolchain = "{toolchain}", +) +""".format( + prefix = prefix, + version = version, + exec_compatible_with = exec_compatible_with, + toolchain = "@{repo}//:jdk".format(repo = name), + ), + ) + native.register_toolchains("@" + name + "_toolchain_config_repo//:toolchain")