Skip to content

Commit

Permalink
Migrate proto_library_target to proto_info in proto_common.declare_ge…
Browse files Browse the repository at this point in the history
…nerated_files.

PiperOrigin-RevId: 456475071
Change-Id: I2882d80cd4f7fdd9b8dcba3347930eaf1f194d0a
  • Loading branch information
comius authored and copybara-github committed Jun 22, 2022
1 parent 2da0972 commit 5aafdef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public static ImmutableList<Artifact> declareGeneratedFiles(
declareGeneratedFiles,
ImmutableList.of(
/* actions */ ruleContext.getStarlarkRuleContext().actions(),
/* proto_library_target */ protoTarget,
/* proto_library_target */ Starlark.NONE,
/* extension */ extension),
ImmutableMap.of());
ImmutableMap.of("proto_info", protoTarget.get(ProtoInfo.PROVIDER)));
try {
return Sequence.cast(outputs, Artifact.class, "declare_generated_files").getImmutableList();
} catch (EvalException e) {
Expand Down Expand Up @@ -155,10 +155,10 @@ public static ImmutableList<Artifact> declareGeneratedFilesPython(
declareGeneratedFiles,
ImmutableList.of(
/* actions */ ruleContext.getStarlarkRuleContext().actions(),
/* proto_library_target */ protoTarget,
/* proto_library_target */ Starlark.NONE,
/* extension */ extension,
/* experimental_python_names */ pythonMapper),
ImmutableMap.of());
ImmutableMap.of("proto_info", protoTarget.get(ProtoInfo.PROVIDER)));
try {
return Sequence.cast(outputs, Artifact.class, "declare_generated_files").getImmutableList();
} catch (EvalException e) {
Expand Down
17 changes: 11 additions & 6 deletions src/main/starlark/builtins_bzl/common/proto/proto_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ def _experimental_should_generate_code(

def _declare_generated_files(
actions,
proto_library_target,
extension,
name_mapper = None):
proto_library_target = None,
extension = None,
name_mapper = None,
proto_info = None):
"""Declares generated files with a specific extension.
Use this in lang_proto_library-es when protocol compiler generates files
Expand All @@ -202,17 +203,21 @@ def _declare_generated_files(
Args:
actions: (ActionFactory) Obtained by ctx.actions, used to declare the files.
proto_library_target: (Target) The proto_library to generate the files for.
Obtained as the `target` parameter from an aspect's implementation.
proto_info: (ProtoInfo) The ProtoInfo to declare the files for.
extension: (str) The extension to use for generated files.
name_mapper: (str->str) A function mapped over the base filename without
the extension. Used it to replace characters in the name that
cause problems in a specific programming language.
proto_library_target: (Target) Deprecated: use proto_info instead.
Returns:
(list[File]) The list of declared files.
"""
proto_info = proto_library_target[_builtins.toplevel.ProtoInfo]
if not proto_info:
proto_info = proto_library_target[_builtins.toplevel.ProtoInfo]
if not extension:
fail("missing parameter extension")

proto_sources = proto_info.direct_sources
outputs = []

Expand Down

0 comments on commit 5aafdef

Please sign in to comment.