Skip to content

Use repo-relative labels wherever possible#9187

Merged
acozzette merged 2 commits intoprotocolbuffers:masterfrom
Wyverald:relative-repo
Nov 4, 2021
Merged

Use repo-relative labels wherever possible#9187
acozzette merged 2 commits intoprotocolbuffers:masterfrom
Wyverald:relative-repo

Conversation

@Wyverald
Copy link
Copy Markdown
Contributor

@Wyverald Wyverald commented Nov 4, 2021

The label @com_google_protobuf//:foo within the protobuf repo is often synonymous with just //:foo. We should prefer the latter as it allows us to use a shorter name for the module in the Bazel Central Registry (so just "protobuf" instead of "com_google_protobuf").

Note that the semantics can be subtle: in a macro, plain strings are anchored to the calling repo, so if we just use //:foo as the default value of a macro argument, it will be resolved to @myrepo//:foo if the macro is called from the repo @myrepo. In this case, it's necessary to directly call the Label() constructor to anchor the string label to the repo where the .bzl file lives.

See bazelbuild/bazel-central-registry#28 (comment) for a bit more context.

The label `@com_google_protobuf//:foo` within the protobuf repo is often synonymous with just `//:foo`. We should prefer the latter as it allows us to use a shorter name for the module in the Bazel Central Registry (so just "protobuf" instead of "com_google_protobuf").

Note that the semantics can be subtle: in a macro, plain strings are anchored to the *calling* repo, so if we just use `//:foo` as the default value of a macro argument, it will be resolved to `@myrepo//:foo` if the macro is called from the repo `@myrepo`. In this case, it's necessary to directly call the `Label()` constructor to anchor the string label to the repo where the .bzl file lives.

See bazelbuild/bazel-central-registry#28 (comment) for a bit more context.
@google-cla google-cla Bot added the cla: yes label Nov 4, 2021
@Wyverald
Copy link
Copy Markdown
Contributor Author

Wyverald commented Nov 4, 2021

cc @meteorcloudy

@acozzette
Copy link
Copy Markdown

Thanks, @Wyverald!

@Wyverald Wyverald deleted the relative-repo branch November 4, 2021 15:02
Wyverald added a commit to bazelbuild/bazel-central-registry that referenced this pull request Nov 4, 2021
Wyverald added a commit to bazelbuild/bazel-central-registry that referenced this pull request Nov 4, 2021
* Update protobuf with relative repo names patch

Essentially a "cherrypick" of protocolbuffers/protobuf#9187

* Fix presubmit build target to demonstrate fix is working
acozzette pushed a commit to acozzette/protobuf that referenced this pull request Mar 29, 2022
acozzette pushed a commit that referenced this pull request Mar 29, 2022
@acozzette
Copy link
Copy Markdown

I went ahead and rolled this back on the 3.20.x branch (which will soon be merged to master), but I would be happy to roll it forward again if someone can help figure out a solution for #9688.

musagracey added a commit to musagracey/bazel-central-registry that referenced this pull request Aug 7, 2024
* Update protobuf with relative repo names patch

Essentially a "cherrypick" of protocolbuffers/protobuf#9187

* Fix presubmit build target to demonstrate fix is working
stef-geo pushed a commit to stef-geo/bazel-central-registry that referenced this pull request Jan 13, 2026
* Update protobuf with relative repo names patch

Essentially a "cherrypick" of protocolbuffers/protobuf#9187

* Fix presubmit build target to demonstrate fix is working
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants