Skip to content

Commit

Permalink
local_java_runtime should create a public native#java_runtime
Browse files Browse the repository at this point in the history
`local_java_repository` should expose the underlying `java_runtime` as public so that it can be used when creating custom java toolchains.

I'm able to reproduce this using `5.0.0-pre.20210708.4`

WORKSPACE
```
load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")

local_java_repository(
    name = "jdk11",
    java_home = "/tmp/jdk11/11.0.11_9/jdk-unarchived/",
)
```

BUILD.bazel
```
load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")

default_java_toolchain(
    name = "java11",
    java_runtime = "@jdk11//:jdk11",
    # ...
    visibility = ["//visibility:public"],
)
```

Error message
```
(00:44:56) ERROR: .../BUILD.bazel:64:23: in java_toolchain rule //:jdk11_java_toolchain: target '@jdk11//:jdk11' is not visible from target '//:jdk11_java_toolchain'. Check the visibility declaration of the former target if you think the dependency is legitimate
```

Closes #13739.

PiperOrigin-RevId: 391237206
  • Loading branch information
Bencodes authored and copybara-github committed Aug 17, 2021
1 parent 115da04 commit cfc2d1d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/jdk/local_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _detect_java_version(repository_ctx, java_bin):
return minor
return major

def local_java_runtime(name, java_home, version, runtime_name = None):
def local_java_runtime(name, java_home, version, runtime_name = None, visibility = ["//visibility:public"]):
"""Defines a java_runtime target together with Java runtime and compile toolchain definitions.
Java runtime toolchain is constrained by flag --java_runtime_version having
Expand All @@ -54,12 +54,14 @@ def local_java_runtime(name, java_home, version, runtime_name = None):
java_home: Path to the JDK.
version: Version of the JDK.
runtime_name: name of java_runtime target if it already exists.
visibility: Visibility that will be applied to the java runtime target
"""
if runtime_name == None:
runtime_name = name
native.java_runtime(
name = runtime_name,
java_home = java_home,
visibility = visibility,
)

native.config_setting(
Expand Down

0 comments on commit cfc2d1d

Please sign in to comment.