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

Fix empty package() calls appearing in non-BUILD files #1150

Merged
merged 3 commits into from
Apr 24, 2023

Conversation

fmeum
Copy link
Contributor

@fmeum fmeum commented Mar 18, 2023

Caused by 9c3c1fc, but only relevant if users use the pseudo-target __pkg__ with non-BUILD files as recommended for file-level operations.

Work towards #1149
Work towards bazelbuild/bazel#17908

@fmeum
Copy link
Contributor Author

fmeum commented Mar 18, 2023

@laurentlb

Edit: Noticed that per-file commands always skip per-target processing.

@Wyverald
Copy link
Member

is there precedent for editing other non-BUILD files? I find the syntax //MODULE.bazel:__pkg__ very unappealing. I'm guessing that //:MODULE.bazel is off the table since it would try to edit the MODULE.bazel target in the BUILD file?

@fmeum
Copy link
Contributor Author

fmeum commented Mar 30, 2023

//MODULE.bazel:all also works and is what I am currently using. Maybe we could make //MODULE.bazel work? It could also be referring to a bazel_dep(name = "MODULE.bazel") though.

@Wyverald
Copy link
Member

Maybe we could make //MODULE.bazel work? It could also be referring to a bazel_dep(name = "MODULE.bazel") though.

Did you maybe mean java_library(name = "MODULE.bazel") or something? I didn't know that each individual bazel_dep could be referred to.

Caused by bazelbuild@9c3c1fc,
but only relevant if users use the target `__pkg__` to skip target-level
processing for non-BUILD files.
@fmeum
Copy link
Contributor Author

fmeum commented Mar 30, 2023

Did you maybe mean java_library(name = "MODULE.bazel") or something? I didn't know that each individual bazel_dep could be referred to.

From the point of view of buildozer, all calls are rules and all rules are the same. As long as your tags have a name attribute, you can even operate on them. We are using this to emit migration commands in Gazelle that look like this:

new go_deps.gazelle_override gopkg.in/yaml.v3|//MODULE.bazel:all
add directives gazelle:go_naming_convention\ go_default_library|//MODULE.bazel:gopkg.in/yaml.v3
rename name path|//MODULE.bazel:gopkg.in/yaml.v3
remove build_naming_convention|//MODULE.bazel:%go_deps.module
remove build_file_proto_mode|//MODULE.bazel:%go_deps.module

But having anything in MODULE.bazel with name = "MODULE.bazel" would still be very weird.

@Wyverald
Copy link
Member

Ah I see. I guess my main gripe is that //MODULE.bazel:foo changes the foo "target" in the file /MODULE.bazel, instead of the foo target in the file /MODULE.bazel/BUILD.

I think I'd prefer a special syntax, something like //:__module__, for the MODULE.bazel file. That means you'd need difference syntax to operate on the stuff in there, but we're already kind of doing that (with use_repo_add, for example).

@fmeum
Copy link
Contributor Author

fmeum commented Apr 17, 2023

@vladmos Could you take a look at this fix? I would submit a separate PR that proposes special syntax to identify the MODULE.bazel file.

@fmeum fmeum mentioned this pull request Apr 17, 2023
@vladmos vladmos merged commit aa477c7 into bazelbuild:master Apr 24, 2023
@fmeum fmeum deleted the fix-module-pkg branch April 24, 2023 20:35
apattidb pushed a commit to databricks/buildtools that referenced this pull request May 10, 2024
…1150)

* Fix empty `package()` calls appearing in non-BUILD files

Caused by bazelbuild@9c3c1fc,
but only relevant if users use the target `__pkg__` to skip target-level
processing for non-BUILD files.
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

Successfully merging this pull request may close these issues.

3 participants