Skip to content

Conversation

@fmeum
Copy link
Collaborator

@fmeum fmeum commented Mar 17, 2023

The name part of the target label embedded in JARs by the Java rules for the purpose of generating fixup commands for strict deps violations is now set to the macro name if the current target has been generated by a macro. Since tools such buildozer operate on the level of parsed but unevaluated BUILD files, they only see the macro name, not the name of the generated target that violated strict deps.

This change is backwards compatible in the sense that fixup command that worked before will continue to work: If the macro name is identical to the target name, nothing has changed, if it differs, the fixup command couldn't have worked before assuming the macro followed the style guide convention to only generate targets with its own name plus optionally a suffix.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 17, 2023

This gets buildozer fixup commands to work on macros from rules_jvm, rules_fuzzing and rules_jni, but really any that still have a deps attribute that they forward to the generated java target(s).

@fmeum fmeum requested a review from cushon March 17, 2023 09:46
@fmeum fmeum marked this pull request as ready for review March 17, 2023 09:46
@fmeum fmeum requested a review from lberki as a code owner March 17, 2023 09:46
The name part of the target label embedded in JARs by the Java rules for
the purpose of generating fixup commands for strict deps violations is
now set to the macro name if the current target has been generated by a
macro. Since tools such buildozer operate on the level of parsed but
unevaluated BUILD files, they only see the macro name, not the name of
the generated target that violated strict deps.

This change is backwards compatible in the sense that fixup command that
worked before will continue to work: If the macro name is identical to
the target name, nothing has changed, if it differs, the fixup command
couldn't have worked before.
@sgowroji sgowroji added team-Rules-Java Issues for Java rules awaiting-review PR is awaiting review from an assigned reviewer labels Mar 17, 2023
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 29, 2023

@cushon Would you be available to review this PR?

@cushon
Copy link
Contributor

cushon commented Mar 29, 2023

The approach we take to this is to use a small wrapper around buildozer that does a blaze query to convert labels to positions in build files, which handles macros and list comprehensions. That wrapper also has some logic to check visibility and handle export edges. How does that approach strike you?

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 29, 2023

@cushon That sounds great! Any chance that wrapper could be open-sourced, at least partially?

@fmeum
Copy link
Collaborator Author

fmeum commented Jun 6, 2023

@cushon Friendly ping. If you could share (parts of) the wrapper you are using internally, I could look for an OSS home for it.

@cushon
Copy link
Contributor

cushon commented Jul 11, 2023

@cushon Friendly ping. If you could share (parts of) the wrapper you are using internally, I could look for an OSS home for it.

I would like to do this, but I don't know when I'm going to be able to make time for it :(

The approach the wrapper takes is applicable to Bazel, but some of the details are not very portable

@meisterT
Copy link
Member

meisterT commented May 8, 2025

Closing this in favor of bazelbuild/buildtools#1269

@meisterT meisterT closed this May 8, 2025
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Rules-Java Issues for Java rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants