Skip to content

Commit bb2e0ae

Browse files
comiuscopybara-github
authored andcommitted
Put protoc label to a constant.
Renamed StrictProtoDepsViolationMessage to ProtoConstants and added protoc label there. PiperOrigin-RevId: 409142099
1 parent 34c7146 commit bb2e0ae

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
public class ProtoCompileActionBuilder {
5454
@VisibleForTesting
5555
public static final String STRICT_DEPS_FLAG_TEMPLATE =
56-
"--direct_dependencies_violation_msg=" + StrictProtoDepsViolationMessage.MESSAGE;
56+
"--direct_dependencies_violation_msg=" + ProtoConstants.STRICT_PROTO_DEPS_VIOLATION_MESSAGE;
5757

5858
private static final String MNEMONIC = "GenProto";
5959

src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// configuration fragment in aspect definitions.
3939
@RequiresOptions(options = {ProtoConfiguration.Options.class})
4040
public class ProtoConfiguration extends Fragment implements ProtoConfigurationApi {
41+
4142
/** Command line options. */
4243
public static class Options extends FragmentOptions {
4344
@Option(
@@ -81,7 +82,7 @@ public static class Options extends FragmentOptions {
8182

8283
@Option(
8384
name = "proto_compiler",
84-
defaultValue = "@com_google_protobuf//:protoc",
85+
defaultValue = ProtoConstants.DEFAULT_PROTOC_LABEL,
8586
converter = CoreOptionConverters.LabelConverter.class,
8687
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
8788
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.LOADING_AND_ANALYSIS},
@@ -219,7 +220,10 @@ public boolean runExperimentalProtoExtraActions() {
219220
return options.experimentalProtoExtraActions;
220221
}
221222

222-
@StarlarkConfigurationField(name = "proto_compiler", doc = "Label for the proto compiler.")
223+
@StarlarkConfigurationField(
224+
name = "proto_compiler",
225+
doc = "Label for the proto compiler.",
226+
defaultLabel = ProtoConstants.DEFAULT_PROTOC_LABEL)
223227
public Label protoCompiler() {
224228
return options.protoCompiler;
225229
}

src/main/java/com/google/devtools/build/lib/rules/proto/StrictProtoDepsViolationMessage.java renamed to src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConstants.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@
1414

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

17-
/**
18-
* This class is used in ProtoCompileActionBuilder to generate an error message that's displayed
19-
* when a strict proto deps violation occurs.
20-
*
21-
* <p>%1$s is replaced with the label of the proto_library rule that's currently being built.
22-
*
23-
* <p>%%s is replaced with the literal "%s", which is passed to the proto-compiler, which replaces
24-
* it with the .proto file that violates strict proto deps.
25-
*/
26-
public class StrictProtoDepsViolationMessage {
27-
static final String MESSAGE =
17+
/** Constants used in Proto rules. */
18+
public final class ProtoConstants {
19+
/** Default label for proto compiler. */
20+
static final String DEFAULT_PROTOC_LABEL = "@com_google_protobuf//:protoc";
21+
22+
/**
23+
* This constant is used in ProtoCompileActionBuilder to generate an error message that's
24+
* displayed when a strict proto deps violation occurs.
25+
*
26+
* <p>%1$s is replaced with the label of the proto_library rule that's currently being built.
27+
*
28+
* <p>%%s is replaced with the literal "%s", which is passed to the proto-compiler, which replaces
29+
* it with the .proto file that violates strict proto deps.
30+
*/
31+
static final String STRICT_PROTO_DEPS_VIOLATION_MESSAGE =
2832
"%%s is imported, but %1$s doesn't directly depend on a proto_library that 'srcs' it.";
33+
34+
private ProtoConstants() {}
2935
}

0 commit comments

Comments
 (0)