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

Bazel incompatible changes #5383

Closed
laurentlb opened this issue Feb 22, 2019 · 20 comments · Fixed by #5454
Closed

Bazel incompatible changes #5383

laurentlb opened this issue Feb 22, 2019 · 20 comments · Fixed by #5454
Assignees
Milestone

Comments

@laurentlb
Copy link
Contributor

This repository doesn't build with Bazel future incompatible changes, and will break with future releases of Bazel.

In order to detect the issues in advance, you can try Bazelisk:
bazelisk --migrate test //...

Some of the issues can be fixed automatically using Buildifier:
buildifier --lint=fix path/to/file.bzl

@ejona86
Copy link
Member

ejona86 commented Feb 26, 2019

@laurentlb, what version of Bazel should we test with?

@laurentlb
Copy link
Contributor Author

In general, the latest version of Bazel. This would be 0.22 (or 0.23, released a few minutes ago, the announcement is pending).

If you use bazelisk, it will automatically fetch the latest version.

@ejona86
Copy link
Member

ejona86 commented Feb 26, 2019

I asked because 1) there was no statement as to what is broken and 2) I had run with 0.22 already. In fact, it still is working. Please in the future provide at least a subset of the errors you see.

grpc-java$ bazel version
INFO: Invocation ID: 8e1df78a-d4ba-4462-9100-3d7cfc3aae25
Build label: 0.22.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Jan 28 12:58:08 2019 (1548680288)
Build timestamp: 1548680288
Build timestamp as int: 1548680288

grpc-java$ bazel build ...
INFO: Invocation ID: fbcf25a5-1e7e-4e53-b155-154e9d773273
INFO: Analysed 30 targets (0 packages loaded, 0 targets configured).
INFO: Found 30 targets...
INFO: Elapsed time: 0.329s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action

@laurentlb
Copy link
Contributor Author

$ USE_BAZEL_VERSION=0.22.0 bazelisk --migrate build //... --nobuild
...
Migration is needed for the following flags:
  --incompatible_disable_legacy_proto_provider
  --incompatible_no_support_tools_in_action_inputs
  --incompatible_new_actions_api
  --incompatible_disable_deprecated_attr_params

If you run Bazel with any of these 4 flags, the build fails. We plan to enable these flags by default in a future version of Bazel, so fixing the issue know will prevent a future breakage.

Some issues can be fixed automatically with Buildifier. Actually, they have already been fixed inside Google (cl/235192309). The issue --incompatible_no_support_tools_in_action_inputs should be easy to fix.

@ejona86
Copy link
Member

ejona86 commented Feb 26, 2019

@laurentlb, so Bazel isn't giving warnings any more for features that will be removed? Is there somewhere "thou must use bazelisk in order to prevent being broken" is written down?

I do know that I purposefully did not fix incompatible_disable_legacy_proto_provider because it was too new of a change. I'd have to look at the others.

@ejona86
Copy link
Member

ejona86 commented Feb 26, 2019

bazelisk was released less than two weeks ago and it isn't "official" (although it was written by a member of bazel team), so I don't really trust what it tells me. But I looked and it appears to figure out the flags to use based on labels like https://github.com/bazelbuild/bazel/labels/migration-0.22 . Okay, so now I trust it more.

And looking more, strict and migrate operate on the same flags, except strict passes them all at once and migrate runs multiple times.

Before many of these can be fixed we'll have to swap to some different building with kokoro, because kokoro team will no longer update the Bazel version (even though it was unannounced).

sigh... Bazel 0.23 broke the build and it was unrelated to all the incompatible flags. The error message is also unclear what the conflicting actions were (I only see one action listed)...

$ ~/Desktop/bazelisk-linux-amd64 build --incompatible_disable_legacy_proto_provider=false --incompatible_no_support_tools_in_action_inputs=false --incompatible_new_actions_api=false --incompatible_disable_deprecated_attr_params=false ...
ERROR: file 'libjava_grpc_library__external_repo_test-src.jar' is generated by these conflicting actions:
Label: //:java_grpc_library__external_repo_test
RuleClass: _java_rpc_library rule
Configuration: 95bb1aedea26948ffe58c23d29c70794
Mnemonic: JavaSourceJar, SkylarkAction
Action key: 5b5319dd6c3f0145f6b764f6674009d9, 08093f6d3f865df5a75d8a1b3a460353
Progress message: Building source jar libjava_grpc_library__external_repo_test-src.jar, SkylarkAction libjava_grpc_library__external_repo_test-src.jar
PrimaryInput: File:[[<execution_root>]bazel-out/k8-fastbuild/bin]libjava_grpc_library__external_repo_test-src.jar, File:[[<execution_root>]bazel-out/k8-fastbuild/genfiles]external/com_google_protobuf/google/protobuf/api.proto
PrimaryOutput: File:[[<execution_root>]bazel-out/k8-fastbuild/bin]libjava_grpc_library__external_repo_test-src.jar
ERROR: Analysis of target '//:java_grpc_library__external_repo_test' failed; build aborted: for libjava_grpc_library__external_repo_test-src.jar, previous action: action 'SkylarkAction libjava_grpc_library__external_repo_test-src.jar', attempted action: action 'Building source jar libjava_grpc_library__external_repo_test-src.jar'
INFO: Elapsed time: 0.191s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

@laurentlb
Copy link
Contributor Author

Sorry about that. This conflict is a mistake on our side (see bazelbuild/bazel#7551). You've received a PR about it. Bazelisk should now pick it correctly and I've added the flag to the release announcement.

The release announcement about 0.23 is now published here: https://blog.bazel.build/2019/02/26/bazel-0.23.html

It mentions Bazelisk. The tool is still new, we're iterating on it and we should make it more visible on our website. At the moment, I think running bazelisk --migrate after each update is the best solution to detect errors sooner (bazel also has a flag --all_incompatible_flags, but it's less precise).

@ejona86
Copy link
Member

ejona86 commented Feb 26, 2019

I see #5395, and it makes sense why 1) it would be an ugly error and 2) why it failed. That was something that was done internally that I hadn't been able to externalize due to bazel versions.

Ah, okay, so bazelisk is an official unofficial thing.

Yeah, I don't trust --all_incompatible_flags because some incompatible flags never "survive."

drigz added a commit to drigz/grpc-java that referenced this issue Feb 28, 2019
Also pass in the binary correctly as a tool. This is required for grpc#5383.

I have tested the build with older Bazel versions and this doesn't
appear to affect compatibility, ie grpc-java continues to be compatible
with Bazel >=0.19.
@drigz
Copy link
Contributor

drigz commented Feb 28, 2019

--incompatible_disable_legacy_proto_provider might be flipped in 0.24.00.25.0: bazelbuild/bazel#7152. @ejona86, would supporting only Bazel >=0.22.0 be acceptable? AFAICT the alternatives are a compatibility layer (bazelbuild/rules_go#1933) or asking to delay the flip.

EDIT: the flip has been postponed.

@ejona86
Copy link
Member

ejona86 commented Feb 28, 2019

Supporting Bazel 0.22.0+ would be acceptable, but Kokoro is not updating Bazel any more, so we are apparently stuck at Bazel 0.20.0. We will have to swap how we get/select Bazel for the CI.

@drigz
Copy link
Contributor

drigz commented Feb 28, 2019

@ejona86 Have you considered using Kokoro's use_bazel.sh script? I'll send a PR in case that helps.

drigz added a commit to drigz/grpc-java that referenced this issue Feb 28, 2019
This is part of grpc#5383. As Bazel 0.22.0 is the only supported version
now, use this in the Kokoro build.
@ejona86
Copy link
Member

ejona86 commented Feb 28, 2019

@drigz, no, I wasn't aware of that. That looks excellent. I do wish it wasn't Kokoro-specific, because that will cause some issues given how our scripts are currently designed, but it seems like it will work.

@ejona86
Copy link
Member

ejona86 commented Feb 28, 2019

nm. Oh, silly me. It is easy to do for our bazel build because we aren't using unix.sh (I thought we were, but obviously we would be.)

ejona86 pushed a commit that referenced this issue Mar 1, 2019
Also pass in the binary correctly as a tool. This is required for #5383.

I have tested the build with older Bazel versions and this doesn't
appear to affect compatibility, ie grpc-java continues to be compatible
with Bazel >=0.19.
ejona86 pushed a commit that referenced this issue Mar 1, 2019
This is part of #5383. As Bazel 0.22.0 is the only supported version
now, use this in the Kokoro build.
@drigz
Copy link
Contributor

drigz commented Mar 1, 2019

Thanks for merging the changes! I think the next step is to upgrade to protobuf 3.7.0, which will introduce a dependency on @bazel_skylib, but I haven't tried this out yet.

@ejona86
Copy link
Member

ejona86 commented Mar 5, 2019

I've started work on upgrading Protobuf. I've gotten the Bazel pieces in place (it was a bit of a PITA though). I will update the rest of the build and then send out a PR.

@laurentlb
Copy link
Contributor Author

We can add grpc-java to the Bazel CI, see: https://github.com/bazelbuild/continuous-integration/issues/new/choose

When it's done, we'll test the project every night with Bazel at head and we'll make sure we're not breaking you. It will also be tested with every flag and show up here: https://buildkite.com/bazel/bazelisk-plus-incompatible-flags/builds/26

@ejona86
Copy link
Member

ejona86 commented Mar 6, 2019

Can't upgrade protobuf to 3.7.0 yet because the Java release process looks incomplete; there aren't any artifacts on Maven Central. protocolbuffers/protobuf#5845

@ejona86
Copy link
Member

ejona86 commented Mar 6, 2019

@cushon, I can't figure out how to make --incompatible_use_toolchain_providers_in_java_common happy. I make this change on master:

diff --git a/java_grpc_library.bzl b/java_grpc_library.bzl
index 4601d4d78..ff8abd422 100644
--- a/java_grpc_library.bzl
+++ b/java_grpc_library.bzl
@@ -1,3 +1,5 @@
+load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_runtime_toolchain", "find_java_toolchain")
+
 # "repository" here is for Bazel builds that span multiple WORKSPACES.
 def _path_ignoring_repository(f):
     if len(f.owner.workspace_root) == 0:
@@ -40,8 +42,8 @@ def _java_rpc_library_impl(ctx):
 
     java_info = java_common.compile(
         ctx,
-        java_toolchain = ctx.attr._java_toolchain,
-        host_javabase = ctx.attr._host_javabase,
+        java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain),
+        host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase),
         source_jars = [srcjar],
         output_source_jar = ctx.outputs.srcjar,
         output = ctx.outputs.jar,

But building still fails:

$ bazel version
Build label: 0.23.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Mar 4 10:37:56 2019 (1551695876)
Build timestamp: 1551695876
Build timestamp as int: 1551695876
$ bazel build --incompatible_use_toolchain_providers_in_java_common ... --nobuild
ERROR: /home/ejona/clients/grpc-java/BUILD.bazel:22:1: in _java_rpc_library rule //:java_grpc_library__external_repo_test: 
Traceback (most recent call last):
	File "/home/ejona/clients/grpc-java/BUILD.bazel", line 22
		_java_rpc_library(name = 'java_grpc_library__external_repo_test')
	File "/home/ejona/clients/grpc-java/java_grpc_library.bzl", line 43, in _java_rpc_library_impl
		java_common.compile(ctx, java_toolchain = find_java_to...), <5 more arguments>)
com.google.devtools.build.lib.rules.AliasConfiguredTarget@78b15d79 pass a java_common.JavaRuntimeInfo instead of a configured target; see https://github.com/bazelbuild/bazel/issues/7186.
ERROR: Analysis of target '//:java_grpc_library__external_repo_test' failed; build aborted: Analysis of target '//:java_grpc_library__external_repo_test' failed; build aborted
INFO: Elapsed time: 0.944s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (93 packages loaded, 1726 targets configured)

@cushon
Copy link
Contributor

cushon commented Mar 7, 2019

@ejona86 it looks like the final implementation of find_java_toolchain and find_java_runtime_toolchain didn't make it in to 0.23. The implementation of those macros in 0.24 and newer includes the change that avoids the error with --incompatible_use_toolchain_providers_in_java_common. It should be possible to verify the fix with 0.24.

It's still safe to start using the macros with 0.23, and they'll ensure things keep working once the flag flips in 0.25.

@ejona86
Copy link
Member

ejona86 commented Mar 7, 2019

Protobuf 3.7.0 doesn't compile with Bazel because it is missing a dependency on error-prone-annotations. Specifically com.google.errorprone.annotations.CanIgnoreReturnValue. Seems it is filed as protocolbuffers/protobuf#5795

@ejona86 ejona86 added this to the 1.20 milestone Mar 7, 2019
ejona86 added a commit to ejona86/grpc-java that referenced this issue Mar 8, 2019
…in_providers_in_java_common

This doesn't actually yet work with
--incompatible_use_toolchain_providers_in_java_common, as Bazel 0.23 didn't
include enough pieces. But this will work in 0.24 with the flag flipped. In
both cases it will continue working if the flag is not specified.

See grpc#5383 (comment) and
bazelbuild/bazel#7186
ejona86 added a commit that referenced this issue Mar 8, 2019
…in_providers_in_java_common

This doesn't actually yet work with
--incompatible_use_toolchain_providers_in_java_common, as Bazel 0.23 didn't
include enough pieces. But this will work in 0.24 with the flag flipped. In
both cases it will continue working if the flag is not specified.

See #5383 (comment) and
bazelbuild/bazel#7186
ejona86 added a commit to ejona86/grpc-java that referenced this issue Mar 9, 2019
This version of Protobuf works with Bazel's
--incompatible_disable_deprecated_attr_params. It also avoids a noisy
reflective access warning in JDK 9+ (nothing was broken before; the warning was
overzealous).

Fixes grpc#5383
ejona86 added a commit to ejona86/grpc-java that referenced this issue Mar 9, 2019
This version of Protobuf works with Bazel's
--incompatible_disable_deprecated_attr_params. It also avoids a noisy
reflective access warning in JDK 9+ (nothing was broken before; the warning was
overzealous).

Fixes grpc#5383
@ejona86 ejona86 self-assigned this Mar 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants