Skip to content

Commit

Permalink
Put protoc label to a constant.
Browse files Browse the repository at this point in the history
Renamed StrictProtoDepsViolationMessage to ProtoConstants and added protoc label there.

PiperOrigin-RevId: 409142099
  • Loading branch information
comius authored and copybara-github committed Nov 11, 2021
1 parent 34c7146 commit bb2e0ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
public class ProtoCompileActionBuilder {
@VisibleForTesting
public static final String STRICT_DEPS_FLAG_TEMPLATE =
"--direct_dependencies_violation_msg=" + StrictProtoDepsViolationMessage.MESSAGE;
"--direct_dependencies_violation_msg=" + ProtoConstants.STRICT_PROTO_DEPS_VIOLATION_MESSAGE;

private static final String MNEMONIC = "GenProto";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// configuration fragment in aspect definitions.
@RequiresOptions(options = {ProtoConfiguration.Options.class})
public class ProtoConfiguration extends Fragment implements ProtoConfigurationApi {

/** Command line options. */
public static class Options extends FragmentOptions {
@Option(
Expand Down Expand Up @@ -81,7 +82,7 @@ public static class Options extends FragmentOptions {

@Option(
name = "proto_compiler",
defaultValue = "@com_google_protobuf//:protoc",
defaultValue = ProtoConstants.DEFAULT_PROTOC_LABEL,
converter = CoreOptionConverters.LabelConverter.class,
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.LOADING_AND_ANALYSIS},
Expand Down Expand Up @@ -219,7 +220,10 @@ public boolean runExperimentalProtoExtraActions() {
return options.experimentalProtoExtraActions;
}

@StarlarkConfigurationField(name = "proto_compiler", doc = "Label for the proto compiler.")
@StarlarkConfigurationField(
name = "proto_compiler",
doc = "Label for the proto compiler.",
defaultLabel = ProtoConstants.DEFAULT_PROTOC_LABEL)
public Label protoCompiler() {
return options.protoCompiler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@

package com.google.devtools.build.lib.rules.proto;

/**
* This class is used in ProtoCompileActionBuilder to generate an error message that's displayed
* when a strict proto deps violation occurs.
*
* <p>%1$s is replaced with the label of the proto_library rule that's currently being built.
*
* <p>%%s is replaced with the literal "%s", which is passed to the proto-compiler, which replaces
* it with the .proto file that violates strict proto deps.
*/
public class StrictProtoDepsViolationMessage {
static final String MESSAGE =
/** Constants used in Proto rules. */
public final class ProtoConstants {
/** Default label for proto compiler. */
static final String DEFAULT_PROTOC_LABEL = "@com_google_protobuf//:protoc";

/**
* This constant is used in ProtoCompileActionBuilder to generate an error message that's
* displayed when a strict proto deps violation occurs.
*
* <p>%1$s is replaced with the label of the proto_library rule that's currently being built.
*
* <p>%%s is replaced with the literal "%s", which is passed to the proto-compiler, which replaces
* it with the .proto file that violates strict proto deps.
*/
static final String STRICT_PROTO_DEPS_VIOLATION_MESSAGE =
"%%s is imported, but %1$s doesn't directly depend on a proto_library that 'srcs' it.";

private ProtoConstants() {}
}

0 comments on commit bb2e0ae

Please sign in to comment.