Skip to content

Commit

Permalink
Implement incompatible_enable_proto_toolchain_resolution
Browse files Browse the repository at this point in the history
The flag also make proto toolchain related flags a no-op when enabled.

PiperOrigin-RevId: 566186339
Change-Id: If4ddafa4e8ba4cdf9e7b3d564c5fc72ab764c7ac
  • Loading branch information
comius authored and copybara-github committed Sep 18, 2023
1 parent 1cf392f commit 11cf1b7
Showing 1 changed file with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionMetadataTag;
import java.util.List;
import javax.annotation.Nullable;
import net.starlark.java.annot.StarlarkMethod;
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.StarlarkThread;
Expand All @@ -45,6 +46,16 @@ public class ProtoConfiguration extends Fragment implements ProtoConfigurationAp

/** Command line options. */
public static class Options extends FragmentOptions {
@Option(
name = "incompatible_enable_proto_toolchain_resolution",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help =
"If true, proto lang rules use toolchain resolution to find the toolchain. The flags"
+ " proto_compiler and proto_toolchain_for_* are a no-op.")
public boolean enableProtoToolchainResolution;

@Option(
name = "protocopt",
Expand All @@ -56,13 +67,12 @@ public static class Options extends FragmentOptions {
public List<String> protocOpts;

@Option(
name = "experimental_proto_extra_actions",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.OUTPUT_SELECTION,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.EXPERIMENTAL},
help = "Run extra actions for alternative Java api versions in a proto_library."
)
name = "experimental_proto_extra_actions",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.OUTPUT_SELECTION,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.EXPERIMENTAL},
help = "Run extra actions for alternative Java api versions in a proto_library.")
public boolean experimentalProtoExtraActions;

@Option(
Expand Down Expand Up @@ -165,6 +175,7 @@ public static class Options extends FragmentOptions {
@Override
public FragmentOptions getExec() {
Options exec = (Options) super.getExec();
exec.enableProtoToolchainResolution = enableProtoToolchainResolution;
exec.protoCompiler = protoCompiler;
exec.protocOpts = protocOpts;
exec.experimentalProtoDescriptorSetsIncludeSourceInfo =
Expand All @@ -185,10 +196,12 @@ public FragmentOptions getExec() {
private final ImmutableList<String> protocOpts;
private final ImmutableList<String> ccProtoLibraryHeaderSuffixes;
private final ImmutableList<String> ccProtoLibrarySourceSuffixes;
private final boolean enableProtoToolchainResolution;
private final Options options;

public ProtoConfiguration(BuildOptions buildOptions) {
Options options = buildOptions.get(Options.class);
this.enableProtoToolchainResolution = options.enableProtoToolchainResolution;
this.protocOpts = ImmutableList.copyOf(options.protocOpts);
this.ccProtoLibraryHeaderSuffixes = ImmutableList.copyOf(options.ccProtoLibraryHeaderSuffixes);
this.ccProtoLibrarySourceSuffixes = ImmutableList.copyOf(options.ccProtoLibrarySourceSuffixes);
Expand Down Expand Up @@ -219,8 +232,8 @@ public boolean experimentalProtoDescriptorSetsIncludeSourceInfo() {
}

/**
* Returns true if we will run extra actions for actions that are not run by default. If this
* is enabled, e.g. all extra_actions for alternative api-versions or language-flavours of a
* Returns true if we will run extra actions for actions that are not run by default. If this is
* enabled, e.g. all extra_actions for alternative api-versions or language-flavours of a
* proto_library target are run.
*/
public boolean runExperimentalProtoExtraActions() {
Expand All @@ -231,40 +244,65 @@ public boolean runExperimentalProtoExtraActions() {
name = "proto_compiler",
doc = "Label for the proto compiler.",
defaultLabel = ProtoConstants.DEFAULT_PROTOC_LABEL)
@Nullable
public Label protoCompiler() {
return options.protoCompiler;
if (enableProtoToolchainResolution) {
return null;
} else {
return options.protoCompiler;
}
}

@StarlarkConfigurationField(
name = "proto_toolchain_for_java",
doc = "Label for the java proto toolchains.",
defaultLabel = ProtoConstants.DEFAULT_JAVA_PROTO_LABEL)
@Nullable
public Label protoToolchainForJava() {
return options.protoToolchainForJava;
if (enableProtoToolchainResolution) {
return null;
} else {
return options.protoToolchainForJava;
}
}

@StarlarkConfigurationField(
name = "proto_toolchain_for_j2objc",
doc = "Label for the j2objc toolchains.",
defaultLabel = ProtoConstants.DEFAULT_J2OBJC_PROTO_LABEL)
@Nullable
public Label protoToolchainForJ2objc() {
return options.protoToolchainForJ2objc;
if (enableProtoToolchainResolution) {
return null;
} else {
return options.protoToolchainForJ2objc;
}
}

@StarlarkConfigurationField(
name = "proto_toolchain_for_java_lite",
doc = "Label for the java lite proto toolchains.",
defaultLabel = ProtoConstants.DEFAULT_JAVA_LITE_PROTO_LABEL)
@Nullable
public Label protoToolchainForJavaLite() {
return options.protoToolchainForJavaLite;
if (enableProtoToolchainResolution) {
return null;
} else {
return options.protoToolchainForJavaLite;
}
}

@StarlarkConfigurationField(
name = "proto_toolchain_for_cc",
doc = "Label for the cc proto toolchains.",
defaultLabel = ProtoConstants.DEFAULT_CC_PROTO_LABEL)
@Nullable
public Label protoToolchainForCc() {
return options.protoToolchainForCc;
if (enableProtoToolchainResolution) {
return null;
} else {
return options.protoToolchainForCc;
}
}

@StarlarkMethod(name = "strict_proto_deps", useStarlarkThread = true, documented = false)
Expand Down

0 comments on commit 11cf1b7

Please sign in to comment.