Skip to content

Commit 10b45b2

Browse files
authored
Stop using Label.workspace_name (#4282)
<!-- Thanks for sending a PR! Before submitting: 1. If this is your first PR, please read CONTRIBUTING.md and sign the CLA first. We cannot review code without a signed CLA. 2. Please file an issue *first*. All features and most bug fixes should have an associated issue with a design discussed and decided upon. Small bug fixes and documentation improvements don't need issues. 3. New features and bug fixes must have tests. Documentation may need to be updated. If you're unsure what to update, send the PR, and we'll discuss in review. 4. Note that PRs updating dependencies and new Go versions are not accepted. Please file an issue instead. --> **What type of PR is this?** Other **What does this PR do? Why is it needed?** According to the Bazel documentation, it is deprecated. Label.repo_name should be used instead. https://bazel.build/rules/lib/builtins/Label#workspace_name **Which issues(s) does this PR fix?** I am working on an analysis tool for Bazel BUILD/*.bzl files. It is currently unable to process Label.workspace_name. Adding support for it is trivial, however I thought it would be a good idea to fix up existing rules instead. **Other notes for review**
1 parent 3af0c6f commit 10b45b2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

go/private/context.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def _infer_importpath(ctx, embeds, importpath, importmap):
413413
def matches_scope(label, scope):
414414
if scope == "all":
415415
return True
416-
if scope.workspace_name != label.workspace_name:
416+
if scope.repo_name != label.repo_name:
417417
return False
418418
if scope.name == "__pkg__":
419419
return scope.package == label.package

go/private/extensions.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _go_sdk_impl(ctx):
129129
for scope in nogo_tag.includes + nogo_tag.excludes:
130130
# Validate that the scope references a valid, visible repository.
131131
# buildifier: disable=no-effect
132-
scope.workspace_name
132+
scope.repo_name
133133
if scope.name != "__pkg__" and scope.name != "__subpackages__":
134134
fail(
135135
"go_sdk.nogo: all entries in includes and excludes must end with ':__pkg__' or ':__subpackages__', got '{}' in".format(scope.name),

go/private/rules/test.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ def _go_test_impl(ctx):
107107

108108
# now generate the main function
109109
repo_relative_rundir = ctx.attr.rundir or ctx.label.package or "."
110-
if ctx.label.workspace_name:
111-
# The test is contained in an external repository (Label.workspace_name is always the empty
110+
if ctx.label.repo_name:
111+
# The test is contained in an external repository (Label.repo_name is always the empty
112112
# string for the main repository, which is the canonical repository name of this repo).
113113
# The test runner cd's into the directory corresponding to the main repository, so walk up
114114
# and then down.
115-
run_dir = "../" + ctx.label.workspace_name + "/" + repo_relative_rundir
115+
run_dir = "../" + ctx.label.repo_name + "/" + repo_relative_rundir
116116
else:
117117
run_dir = repo_relative_rundir
118118

0 commit comments

Comments
 (0)