Skip to content

Commit 1f99352

Browse files
authored
wrap_sdk: make root_files a string_keyed_label_dict (#4419)
**What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** I'm trying to use an extension-generated repo as a wrapped sdk using `root_files`. I get a package load error similar to bazelbuild/bazel#19301. **Which issues(s) does this PR fix?** I saw in the comments (specifically bazelbuild/bazel#19301 (comment)) that this would probably work if `root_files` used a `string_keyed_label_dict` and, when I tried it locally it did. Fixes #4418 **Other notes for review** bazelbuild/bazel#19301
1 parent 4957aa3 commit 1f99352

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

go/private/extensions.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,20 @@ Uses the same format as 'visibility', i.e., every entry must be a label that end
9898
},
9999
)
100100

101+
# string_keyed_label_dict was added in 8.0.0
102+
_maybe_string_keyed_label_dict = getattr(
103+
attr,
104+
"string_keyed_label_dict",
105+
attr.string_dict,
106+
)
107+
101108
_wrap_tag = tag_class(
102109
attrs = {
103110
"root_file": attr.label(
104111
mandatory = False,
105112
doc = "A file in the SDK root directory. Use to determine GOROOT.",
106113
),
107-
"root_files": attr.string_dict(
114+
"root_files": _maybe_string_keyed_label_dict(
108115
mandatory = False,
109116
doc = "A set of mappings from the host platform to a file in the SDK's root directory.",
110117
),
@@ -234,7 +241,7 @@ def _go_sdk_impl(ctx):
234241
if key not in ["go_mod"]
235242
}
236243
download_tag["version"] = version
237-
additional_download_tags += [struct(**download_tag)]
244+
additional_download_tags.append(struct(**download_tag))
238245

239246
for index, download_tag in enumerate(module.tags.download + additional_download_tags):
240247
# SDKs without an explicit version are fetched even when not selected by toolchain

go/private/sdk.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,20 @@ def _go_wrap_sdk_impl(ctx):
371371
_sdk_build_file(ctx, platform, version, ctx.attr.experiments)
372372
_local_sdk(ctx, goroot)
373373

374+
# string_keyed_label_dict was added in 8.0.0
375+
_maybe_string_keyed_label_dict = getattr(
376+
attr,
377+
"string_keyed_label_dict",
378+
attr.string_dict,
379+
)
374380
go_wrap_sdk_rule = repository_rule(
375381
implementation = _go_wrap_sdk_impl,
376382
attrs = {
377383
"root_file": attr.label(
378384
mandatory = False,
379385
doc = "A file in the SDK root direcotry. Used to determine GOROOT.",
380386
),
381-
"root_files": attr.string_dict(
387+
"root_files": _maybe_string_keyed_label_dict(
382388
mandatory = False,
383389
doc = "A set of mappings from the host platform to a file in the SDK's root directory",
384390
),

0 commit comments

Comments
 (0)