Skip to content

Commit

Permalink
Handle targets provided in deps as a result of GoSource.resolver (#4063)
Browse files Browse the repository at this point in the history
**What type of PR is this?**
Starlark fixup

**What does this PR do? Why is it needed?**
Make the migration process a little smoother

**Which issues(s) does this PR fix?**
#4030 (comment)

**Other notes for review**
  • Loading branch information
dzbarsky authored Aug 27, 2024
1 parent 59235b4 commit 4a66ec6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _dedup_archives(archives):
deduped_archives.append(arc)
return deduped_archives

def _library_to_source(go, attr, library, coverage_instrumented):
def _library_to_source(go, attr, library, coverage_instrumented, verify_resolver_deps = True):
#TODO: stop collapsing a depset in this line...
attr_srcs = [f for t in getattr(attr, "srcs", []) for f in as_iterable(t.files)]
generated_srcs = getattr(library, "srcs", [])
Expand Down Expand Up @@ -311,6 +311,19 @@ def _library_to_source(go, attr, library, coverage_instrumented):
if library.resolve:
library.resolve(go, attr, source, _merge_embed)

# TODO(zbarsky): Remove this once downstream has a chance to migrate.
if verify_resolver_deps:
has_targets = False
for dep in source["deps"]:
if type(dep) == "Target":
has_targets = True
break
if has_targets:
print('Detected Targets in `source["deps"]` as a result of _resolver. ' +
"Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. " +
"This will be an error in the future.")
source["deps"] = [get_archive(dep) for dep in source["deps"]]

return GoSource(**source)

def _collect_runfiles(go, data, deps):
Expand Down
2 changes: 1 addition & 1 deletion proto/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _go_proto_library_impl(ctx):
resolver = _proto_library_to_source,
srcs = go_srcs,
)
source = go.library_to_source(go, ctx.attr, library, False)
source = go.library_to_source(go, ctx.attr, library, False, verify_resolver_deps = False)
providers = [library, source]
output_groups = {
"go_generated_srcs": go_srcs,
Expand Down

0 comments on commit 4a66ec6

Please sign in to comment.