diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java index 7f4b2daa3ec174..3b27faea755aa9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java @@ -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"; diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java index 466bbe713aa289..7b1e2c018bb67a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java @@ -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( @@ -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}, @@ -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; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/StrictProtoDepsViolationMessage.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConstants.java similarity index 51% rename from src/main/java/com/google/devtools/build/lib/rules/proto/StrictProtoDepsViolationMessage.java rename to src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConstants.java index 6d6d03844d1b64..419756cae76a92 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/StrictProtoDepsViolationMessage.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConstants.java @@ -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. - * - *

%1$s is replaced with the label of the proto_library rule that's currently being built. - * - *

%%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. + * + *

%1$s is replaced with the label of the proto_library rule that's currently being built. + * + *

%%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() {} }