Skip to content

Commit

Permalink
Add experimental_progress_message parameter to proto_common.compile.
Browse files Browse the repository at this point in the history
This will make migration to the new call easier (because we don't have progress_message set yet on the proto_lang_toolchain rules).

Design doc: https://docs.google.com/document/d/1dY_jfRvnH8SjRXGIfg8av-vquyWsvIZydXJOywvaR1A/edit

PiperOrigin-RevId: 440098602
  • Loading branch information
comius authored and copybara-github committed Apr 7, 2022
1 parent 982bbce commit d7a3836
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/starlark/builtins_bzl/common/proto/proto_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def _compile(
additional_args = None,
additional_tools = [],
additional_inputs = depset(),
resource_set = None):
resource_set = None,
experimental_progress_message = None):
"""Creates proto compile action for compiling *.proto files to language specific sources.
Args:
Expand All @@ -120,6 +121,8 @@ def _compile(
(func) A callback function that is passed to the created action.
See `ctx.actions.run`, `resource_set` parameter for full definition of
the callback.
experimental_progress_message: Overrides progres_message from the toolchain.
Don't use this parameter. It's only intended for the transition.
"""
proto_info = proto_library_target[_builtins.toplevel.ProtoInfo]

Expand Down Expand Up @@ -154,7 +157,7 @@ def _compile(

actions.run(
mnemonic = proto_lang_toolchain_info.mnemonic,
progress_message = proto_lang_toolchain_info.progress_message,
progress_message = experimental_progress_message if experimental_progress_message else proto_lang_toolchain_info.progress_message,
executable = proto_lang_toolchain_info.proto_compiler,
arguments = [additional_args, args] if additional_args else [args],
inputs = depset(transitive = [proto_info.transitive_sources, additional_inputs]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public final void setup() throws Exception {
" kwargs['additional_inputs'] = depset(ctx.files.additional_inputs)",
" if ctx.attr.use_resource_set:",
" kwargs['resource_set'] = _resource_set_callback",
" if ctx.attr.progress_message:",
" kwargs['experimental_progress_message'] = ctx.attr.progress_message",
" proto_common_do_not_use.compile(",
" ctx.actions,",
" ctx.attr.proto_dep,",
Expand All @@ -111,6 +113,7 @@ public final void setup() throws Exception {
" 'additional_tools': attr.label_list(cfg = 'exec'),",
" 'additional_inputs': attr.label_list(allow_files = True),",
" 'use_resource_set': attr.bool(),",
" 'progress_message': attr.string(),",
" })");
}

Expand Down Expand Up @@ -461,4 +464,29 @@ public void generateCode_externalProtoLibrary(
"bar/A.proto")
.inOrder();
}

/** Verifies <code>experimental_progress_message</code> parameters. */
@Test
public void generateCode_overrideProgressMessage() throws Exception {
scratch.file(
"bar/BUILD",
TestConstants.LOAD_PROTO_LIBRARY,
"load('//foo:generate.bzl', 'generate_rule')",
"proto_library(name = 'proto', srcs = ['A.proto'])",
"generate_rule(name = 'simple', proto_dep = ':proto', progress_message = 'My %{label}')");

ConfiguredTarget target = getConfiguredTarget("//bar:simple");

SpawnAction spawnAction = getGeneratingSpawnAction(getBinArtifact("out", target));
List<String> cmdLine = spawnAction.getRemainingArguments();
assertThat(cmdLine)
.comparingElementsUsing(MATCHES_REGEX)
.containsExactly(
"--plugin=bl?azel?-out/[^/]*-exec-[^/]*/bin/third_party/x/plugin",
"-Ibar/A.proto=bar/A.proto",
"bar/A.proto")
.inOrder();
assertThat(spawnAction.getMnemonic()).isEqualTo("MyMnemonic");
assertThat(spawnAction.getProgressMessage()).isEqualTo("My //bar:simple");
}
}

0 comments on commit d7a3836

Please sign in to comment.