Skip to content

Commit

Permalink
Remove proto_library_target from proto_common
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 460406536
Change-Id: I10021f32fb40e163ded02ebab8297902b63760fa
  • Loading branch information
comius authored and copybara-github committed Jul 12, 2022
1 parent 95f0135 commit caddaf1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 34 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 */ Starlark.NONE,
/* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
/* extension */ extension),
ImmutableMap.of("proto_info", protoTarget.get(ProtoInfo.PROVIDER)));
ImmutableMap.of());
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 */ Starlark.NONE,
/* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
/* extension */ extension,
/* experimental_python_names */ pythonMapper),
ImmutableMap.of("proto_info", protoTarget.get(ProtoInfo.PROVIDER)));
ImmutableMap.of());
try {
return Sequence.cast(outputs, Artifact.class, "declare_generated_files").getImmutableList();
} catch (EvalException e) {
Expand All @@ -185,6 +185,7 @@ public static void compile(
compile,
ImmutableList.of(
/* actions */ ruleContext.getStarlarkRuleContext().actions(),
/* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
/* proto_lang_toolchain_info */ protoLangToolchainInfo,
/* generated_files */ StarlarkList.immutableCopyOf(generatedFiles),
/* plugin_output */ pluginOutput == null ? Starlark.NONE : pluginOutput,
Expand All @@ -195,8 +196,7 @@ public static void compile(
: Depset.of(
Artifact.TYPE, NestedSetBuilder.wrap(Order.STABLE_ORDER, additionalInputs)),
/* resource_set */ resourceSet == null ? Starlark.NONE : resourceSet,
/* experimental_progress_message */ progressMessage,
/* proto_info */ protoTarget.get(ProtoInfo.PROVIDER)),
/* experimental_progress_message */ progressMessage),
ImmutableMap.of());
}

Expand All @@ -215,14 +215,11 @@ public static void compile(
compile,
ImmutableList.of(
/* actions */ ruleContext.getStarlarkRuleContext().actions(),
/* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
/* proto_lang_toolchain_info */ protoLangToolchainInfo,
/* generated_files */ StarlarkList.immutableCopyOf(generatedFiles),
/* plugin_output */ pluginOutput == null ? Starlark.NONE : pluginOutput),
ImmutableMap.of(
"experimental_progress_message",
progressMessage,
"proto_info",
protoTarget.get(ProtoInfo.PROVIDER)));
ImmutableMap.of("experimental_progress_message", progressMessage));
}

public static boolean shouldGenerateCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def _aspect_impl(target, ctx):
source_jar = ctx.actions.declare_file(ctx.label.name + "-lite-src.jar")
proto_common.compile(
ctx.actions,
target[ProtoInfo],
proto_toolchain_info,
[source_jar],
source_jar,
proto_info = target[ProtoInfo],
)
runtime = proto_toolchain_info.runtime
if runtime:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def _bazel_java_proto_aspect_impl(target, ctx):
source_jar = ctx.actions.declare_file(ctx.label.name + "-speed-src.jar")
proto_common.compile(
ctx.actions,
target[ProtoInfo],
proto_toolchain_info,
[source_jar],
source_jar,
proto_info = target[ProtoInfo],
)

# Compile Java sources (or just merge if there aren't any)
Expand Down
23 changes: 5 additions & 18 deletions src/main/starlark/builtins_bzl/common/proto/proto_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ def _Iimport_path_equals_fullpath(proto_source):

def _compile(
actions,
proto_info,
proto_lang_toolchain_info,
generated_files,
plugin_output = None,
additional_args = None,
additional_tools = [],
additional_inputs = depset(),
resource_set = None,
experimental_progress_message = None,
proto_info = None,
proto_library_target = None):
experimental_progress_message = None):
"""Creates proto compile action for compiling *.proto files to language specific sources.
Args:
Expand All @@ -71,12 +70,7 @@ def _compile(
the callback.
experimental_progress_message: Overrides progres_message from the toolchain.
Don't use this parameter. It's only intended for the transition.
proto_library_target: (Target) Deprecated: use proto_info instead.
Exactly one need to be set: `proto_info` or `proto_library_target`.
"""
if not proto_info:
proto_info = proto_library_target[_builtins.toplevel.ProtoInfo]

args = actions.args()
args.use_param_file(param_file_arg = "@%s")
args.set_param_file_format("multiline")
Expand Down Expand Up @@ -189,10 +183,9 @@ def _experimental_should_generate_code(

def _declare_generated_files(
actions,
proto_library_target = None,
extension = None,
name_mapper = None,
proto_info = None):
proto_info,
extension,
name_mapper = None):
"""Declares generated files with a specific extension.
Use this in lang_proto_library-es when protocol compiler generates files
Expand All @@ -208,16 +201,10 @@ def _declare_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.
"""
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
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ def _write_descriptor_set(ctx, direct_sources, deps, exports, proto_info, descri
)
proto_common.compile(
ctx.actions,
proto_info,
proto_lang_toolchain_info,
generated_files = [descriptor_set],
plugin_output = descriptor_set,
additional_inputs = dependencies_descriptor_sets,
additional_args = args,
proto_info = proto_info,
)

proto_library = rule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public final void setup() throws Exception {
" kwargs['experimental_progress_message'] = ctx.attr.progress_message",
" proto_common_do_not_use.compile(",
" ctx.actions,",
" ctx.attr.proto_dep[ProtoInfo],",
" ctx.attr.toolchain[proto_common_do_not_use.ProtoLangToolchainInfo],",
" [outfile],",
" proto_info = ctx.attr.proto_dep[ProtoInfo],",
" **kwargs)",
" return [DefaultInfo(files = depset([outfile]))]",
"generate_rule = rule(_impl,",
Expand Down Expand Up @@ -149,7 +149,7 @@ public final void setup() throws Exception {
"def _impl(ctx):",
" files = proto_common_do_not_use.declare_generated_files(",
" ctx.actions,",
" ctx.attr.proto_dep,",
" ctx.attr.proto_dep[ProtoInfo],",
" ctx.attr.extension,",
" (lambda s: s.replace('-','_').replace('.','/')) if ctx.attr.python_names else None)",
" for f in files:",
Expand Down

0 comments on commit caddaf1

Please sign in to comment.