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

add dep commands don't work for java_proto_library #4990

Open
cushon opened this issue Apr 10, 2018 · 10 comments
Open

add dep commands don't work for java_proto_library #4990

cushon opened this issue Apr 10, 2018 · 10 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: bug

Comments

@cushon
Copy link
Contributor

cushon commented Apr 10, 2018

Description

The suggested fix for Strict Java Deps errors adds the wrong target for dependencies on java_proto_librarys. It suggests adding a dep on the underlying proto_library target, instead of on the java_proto_library target.

Repro

First, download: https://gist.github.com/cushon/0241dafdb608b7e2f37c475d3304aa18

Building fails with a strict deps error:

$ bazel build :b
...
B.java:2: error: [strict] Using type com.test.proto.P from an indirect dependency (TOOL_INFO: "//:p_proto wrapped in java_proto_library"). See command below **
  com.test.proto.P.Message m;
                ^
 ** Please add the following dependencies: 
  //:p_proto  to //:b 
 ** You can use the following buildozer command: 
buildozer 'add deps //:p_proto ' //:b 

The suggested fix is to add //p:proto, which does not fix the problem:

$ buildozer 'add deps //:p_proto ' //:b 
fixed ./sjdproto/BUILD
$ bazel build :b
B.java:2: error: [strict] Using type com.test.proto.P from an indirect dependency (TOOL_INFO: "//:p_proto wrapped in java_proto_library"). See command below **
  com.test.proto.P.Message m;

The correct dep to add is //:p_java_proto:

$ buildozer 'add deps //:p_java_proto ' //:b 
$ bazel build :b
...
INFO: Build completed successfully

What's the output of bazel info release?

$ bazel info release
release 0.11.1
@ittaiz
Copy link
Member

ittaiz commented Apr 10, 2018 via email

@cushon
Copy link
Contributor Author

cushon commented Apr 10, 2018

No, the current handling of j_p_l (and exports) predates and was unchanged by stamping.

The issue here is that the special-casing of j_p_l @tomlu described in the thread [1] doesn't work with Bazel.

[1] https://groups.google.com/d/msg/bazel-discuss/mt2llfwzmac/epJDzdY9CAAJ

@ittaiz
Copy link
Member

ittaiz commented Apr 10, 2018 via email

@lberki lberki added team-Rules-Java Issues for Java rules P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed category: rules > java labels Dec 3, 2018
@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 3 years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 28, 2023
@cheister
Copy link
Contributor

cheister commented Mar 1, 2023

Commenting to reset stale check, This is still an issue.

@sgowroji sgowroji removed the stale Issues or PRs that are stale (no activity for 30 days) label Mar 1, 2023
Copy link

github-actions bot commented May 5, 2024

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label May 5, 2024
@evis
Copy link

evis commented May 7, 2024

It's still relevant.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label May 8, 2024
@evis
Copy link

evis commented May 8, 2024

@cushon are there any plans to fix this issue? Or maybe, some tips for potential contributors, how to fix it? Links to relevant code, etc.

We'd like to turn on strict_deps_mode in our repo. But we can't do it with this issue. When we turn on strict_deps_mode, then there are lots of false-positive suggestions to add proto_library targets.

@cushon
Copy link
Contributor Author

cushon commented May 13, 2024

At Google we have a separate add_dep utility that Strict Java Deps uses for the suggested fix in the diagnostic, instead of using buildozer directly. add_dep is a simple wrapper around buildozer that handles a few special cases for these fixes, including handling the java_proto_library rules.

There's some discussion in #17805 about another case the current buildozer suggested fixes don't handle, which the add_dep wrapper does.

The long term plan here was always to open-source the add_dep wrapper.

@cushon
Copy link
Contributor Author

cushon commented May 13, 2024

I took a first pass at open-sourcing the tool in bazelbuild/buildtools#1269

Demo:

add_dep "//:p_proto java_proto_library" //:b
...
Running bazel query: visible(//:b, //:p_proto + //:b)
Loading: 0 packages loaded
Finished query in 2502ms
ADDING: //:p_java_proto (resolved from //:p_proto)
finished in 4507ms [added 1/1 dep(s)]
$ git diff
diff --git a/BUILD b/BUILD
index c2ac9c7..3efb234 100644
--- a/BUILD
+++ b/BUILD
@@ -19,6 +19,7 @@ java_library(
     srcs = ["B.java"],
     deps = [
         ":a",
+        ":p_java_proto",
         ":p_proto",
     ],
 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: bug
Projects
None yet
Development

No branches or pull requests

7 participants