Add new flag to add additional execution platforms.
Part of #4442.
Change-Id: Ie263be75b85635717aa5670cf059891e644dfaee
PiperOrigin-RevId: 182537464
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java
index bb816a7..ff12670 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java
@@ -39,6 +39,7 @@
new PlatformConfiguration_AutoCodec();
private final Label executionPlatform;
+ private final ImmutableList<Label> extraExecutionPlatforms;
private final ImmutableList<Label> targetPlatforms;
private final ImmutableList<Label> extraToolchains;
private final ImmutableMap<Label, Label> toolchainResolutionOverrides;
@@ -47,11 +48,13 @@
@AutoCodec.Constructor
PlatformConfiguration(
Label executionPlatform,
+ ImmutableList<Label> extraExecutionPlatforms,
ImmutableList<Label> targetPlatforms,
ImmutableList<Label> extraToolchains,
ImmutableMap<Label, Label> toolchainResolutionOverrides,
ImmutableList<Label> enabledToolchainTypes) {
this.executionPlatform = executionPlatform;
+ this.extraExecutionPlatforms = extraExecutionPlatforms;
this.targetPlatforms = targetPlatforms;
this.extraToolchains = extraToolchains;
this.toolchainResolutionOverrides = toolchainResolutionOverrides;
@@ -67,6 +70,11 @@
return executionPlatform;
}
+ /** Additional platforms that are available for action execution. */
+ public ImmutableList<Label> getExtraExecutionPlatforms() {
+ return extraExecutionPlatforms;
+ }
+
@SkylarkCallable(name = "platforms", structField = true, doc = "The current target platforms")
public ImmutableList<Label> getTargetPlatforms() {
return targetPlatforms;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java
index 6a1b5c2..c4f9c8b 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java
@@ -52,6 +52,7 @@
Label executionPlatform = options.hostPlatform;
return new PlatformConfiguration(
executionPlatform,
+ ImmutableList.copyOf(options.extraExecutionPlatforms),
ImmutableList.copyOf(options.platforms),
ImmutableList.copyOf(options.extraToolchains),
convertOverrides(options.toolchainResolutionOverrides),
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java
index 7f7e65f..bfd84ee 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java
@@ -68,12 +68,23 @@
)
public String hostPlatformRemotePropertiesOverride;
- // TODO(katre): Add execution platforms.
+ @Option(
+ name = "extra_execution_platforms",
+ converter = LabelListConverter.class,
+ defaultValue = "",
+ documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
+ effectTags = {OptionEffectTag.EXECUTION},
+ help =
+ "The labels of platforms that are available as execution platforms to run actions. "
+ + "These platforms will be considered before those declared in the WORKSPACE file by "
+ + "register_execution_platforms()."
+ )
+ public List<Label> extraExecutionPlatforms;
@Option(
name = "platforms",
oldName = "experimental_platforms",
- converter = BuildConfiguration.LabelListConverter.class,
+ converter = LabelListConverter.class,
defaultValue = "@bazel_tools//platforms:target_platform",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {
@@ -149,6 +160,7 @@
host.platforms =
this.hostPlatform == null ? ImmutableList.of() : ImmutableList.of(this.hostPlatform);
host.hostPlatform = this.hostPlatform;
+ host.extraExecutionPlatforms = this.extraExecutionPlatforms;
host.extraToolchains = this.extraToolchains;
host.enabledToolchainTypes = this.enabledToolchainTypes;
host.hostPlatformRemotePropertiesOverride = this.hostPlatformRemotePropertiesOverride;