Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot make alternative java_toolchain work (to activate all error prone warnings) #5997

Closed
davido opened this issue Aug 27, 2018 · 2 comments

Comments

@davido
Copy link
Contributor

davido commented Aug 27, 2018

On most recent Bazel version (d019651) I'm, trying to implement alternative java_toolchain and activate all error prone warnings, as described in this comment: [1]:

$ bazel build --java_toolchain //tools:error_prone_warnings_toolchain java/com/google/gerrit/extensions:extension-api-javadoc
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:98:7: 
Current Bazel is not a release version, cannot check for compatibility.
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:99:7: Make sure that you are running at least Bazel 0.14.0.
ERROR: /home/davido/projects/gerrit2/java/com/google/gerrit/extensions/BUILD:49:1: every rule of type java_doc implicitly depends upon the target '@local_jdk//:jdk-default', but this target could not be found because of: no such target '@local_jdk//:jdk-default': target 'jdk-default' not declared in package '' (did you mean 'jre-default'?) defined by /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/local_jdk/BUILD.bazel
ERROR: Analysis of target '//java/com/google/gerrit/extensions:extension-api-javadoc' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.085s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

javadoc.bzl is here: [2] and the reproducer is here: [3].

@cushon
Copy link
Contributor

cushon commented Aug 27, 2018

https://github.com/GerritCodeReview/gerrit/blob/a194115149152c5a99a29188f25358d8a5533844/tools/bzl/javadoc.bzl#L76

Don't depend on @local_jdk directly; use @bazel_tools//tools/jdk:current_java_runtime to get the configured JDK instead (see #5594).

e.g.:

diff --git a/tools/bzl/javadoc.bzl b/tools/bzl/javadoc.bzl
index 34ae9d2c2f..8f2316c696 100644
--- a/tools/bzl/javadoc.bzl
+++ b/tools/bzl/javadoc.bzl
@@ -36,7 +36,7 @@ def _impl(ctx):
         "rm -rf %s" % dir,
         "mkdir %s" % dir,
         " ".join([
-            ctx.file._javadoc.path,
+            "%s/bin/javadoc" % ctx.attr._jdk[java_common.JavaRuntimeInfo].java_home,
             "-Xdoclint:-missing",
             "-protected",
             "-encoding UTF-8",
@@ -67,14 +67,10 @@ java_doc = rule(
         "pkgs": attr.string_list(),
         "title": attr.string(),
         "external_docs": attr.string_list(),
-        "_javadoc": attr.label(
-            default = Label("@local_jdk//:bin/javadoc"),
-            single_file = True,
-            allow_files = True,
-        ),
         "_jdk": attr.label(
-            default = Label("@local_jdk//:jdk-default"),
+            default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
             allow_files = True,
+            providers = [java_common.JavaRuntimeInfo],
         ),
     },
     outputs = {"zip": "%{name}.zip"},

@cushon cushon closed this as completed Aug 27, 2018
@davido
Copy link
Contributor Author

davido commented Aug 27, 2018

Thank you! It works like a charm:

$ bazel build --java_toolchain //tools:error_prone_warnings_toolchain java/com/google/gerrit/extensions:extension-api-javadoc
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:98:7: 
Current Bazel is not a release version, cannot check for compatibility.
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:99:7: Make sure that you are running at least Bazel 0.14.0.
INFO: Analysed target //java/com/google/gerrit/extensions:extension-api-javadoc (1 packages loaded).
INFO: Found 1 target...
Target //java/com/google/gerrit/extensions:extension-api-javadoc up-to-date:
  bazel-bin/java/com/google/gerrit/extensions/extension-api-javadoc.zip
INFO: Elapsed time: 8.688s, Critical Path: 6.34s
INFO: 4 processes: 1 remote cache hit, 3 linux-sandbox.
INFO: Build completed successfully, 5 total actions

lucamilanesio pushed a commit to GerritCodeReview/gerrit that referenced this issue Aug 27, 2018
To support alternative java_toolchains (e.g.: to activate all error
prone warnings) we should not directly depend on @local_jdk, but use
@bazel_tools//tools/jdk:current_java_runtime to get the configured JDK
instead.

See this issue for more context: [1].

[1] bazelbuild/bazel#5997

Inspired-by: Liam Miller-Cushon <cushon@google.com>
Change-Id: I66e1215a01f98e435e514a5442533ab15eaebd35
lucamilanesio pushed a commit to GerritCodeReview/bazlets that referenced this issue Sep 22, 2018
To support alternative java_toolchains (e.g.: to activate all error
prone warnings) we should not directly depend on @local_jdk, but use
@bazel_tools//tools/jdk:current_java_runtime to get the configured JDK
instead.

See this issue for more context: [1].

[1] bazelbuild/bazel#5997

Inspired-by: Liam Miller-Cushon <cushon@google.com>
Bug: Issue GerritCodeReview/gitiles#1
Change-Id: I87cde26cddfeaa317e6489e2c5cdcceb054c670d
thaidn added a commit to tink-crypto/tink that referenced this issue Oct 4, 2018
…est).

Kokoro hasn't failed because its macOS and Ubuntu machines are using old Bazel versions.

Related issues:
#131
#136
bazelbuild/bazel#5997
bazelbuild/bazel#5594

PiperOrigin-RevId: 215787620
GitOrigin-RevId: 7b978f1374938e4b839f8357fc50d36b7ab96be5
chuckx pushed a commit to tink-crypto/tink that referenced this issue Oct 10, 2018
…est).

Kokoro hasn't failed because its macOS and Ubuntu machines are using old Bazel versions.

Related issues:
#131
#136
bazelbuild/bazel#5997
bazelbuild/bazel#5594

PiperOrigin-RevId: 215787620
GitOrigin-RevId: 7b978f1374938e4b839f8357fc50d36b7ab96be5
chuckx pushed a commit to tink-crypto/tink that referenced this issue Oct 12, 2018
…est).

Kokoro hasn't failed because its macOS and Ubuntu machines are using old Bazel versions.

Related issues:
#131
#136
bazelbuild/bazel#5997
bazelbuild/bazel#5594

PiperOrigin-RevId: 215787620
GitOrigin-RevId: 7b978f1374938e4b839f8357fc50d36b7ab96be5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants