aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/platform
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-12-19 13:21:05 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-19 13:22:34 -0800
commit43f45b58acf10beadbb1221b71dfa06fa1341510 (patch)
tree55b4ae3f44fdd370d2a74a0cd138f959e2869ad3 /src/main/java/com/google/devtools/build/lib/rules/platform
parent7fb53228b56c08785fdb474784b402cecfb4d8a8 (diff)
Have the RemoteSpawnRunner use the execution platform present in the Spawn to get the remote execution properties.
Fixes #4128. Change-Id: I7e71caef2465204d2dd8225448d54e52366807e6 PiperOrigin-RevId: 179595126
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/platform')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java b/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
index 99cc90b436..07196bb41d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.rules.platform;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
+import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.analysis.RuleContext;
@@ -39,22 +40,40 @@ public class Platform implements RuleConfiguredTargetFactory {
PlatformInfo.Builder platformBuilder = PlatformInfo.builder().setLabel(ruleContext.getLabel());
- if (ruleContext.attributes().get(PlatformRule.HOST_PLATFORM_ATTR, Type.BOOLEAN)) {
+ Boolean isHostPlatform =
+ ruleContext.attributes().get(PlatformRule.HOST_PLATFORM_ATTR, Type.BOOLEAN);
+ Boolean isTargetPlatform =
+ ruleContext.attributes().get(PlatformRule.TARGET_PLATFORM_ATTR, Type.BOOLEAN);
+ if (isHostPlatform && isTargetPlatform) {
+ ruleContext.attributeError(
+ PlatformRule.HOST_PLATFORM_ATTR,
+ "A single platform cannot have both host_platform and target_platform set.");
+ return null;
+ } else if (isHostPlatform) {
// Create default constraints based on the current host OS and CPU values.
String cpuOption = ruleContext.getConfiguration().getHostCpu();
autodetectConstraints(cpuOption, ruleContext, platformBuilder);
- } else if (ruleContext.attributes().get(PlatformRule.TARGET_PLATFORM_ATTR, Type.BOOLEAN)) {
+ } else if (isTargetPlatform) {
// Create default constraints based on the current OS and CPU values.
String cpuOption = ruleContext.getConfiguration().getCpu();
autodetectConstraints(cpuOption, ruleContext, platformBuilder);
- } else {
- platformBuilder.addConstraints(
- PlatformProviderUtils.constraintValues(
- ruleContext.getPrerequisites(PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK)));
}
+ // Add the declared constraints. Because setting the host_platform or target_platform attribute
+ // to true on a platform automatically includes the detected CPU and OS constraints, if the
+ // constraint_values attribute tries to add those, this will throw an error.
+ platformBuilder.addConstraints(
+ PlatformProviderUtils.constraintValues(
+ ruleContext.getPrerequisites(PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK)));
+
String remoteExecutionProperties =
ruleContext.attributes().get(PlatformRule.REMOTE_EXECUTION_PROPS_ATTR, Type.STRING);
+ if (platformBuilder.getRemoteExecutionProperties() == null && isHostPlatform) {
+ // Use the default override.
+ PlatformOptions platformOptions =
+ ruleContext.getConfiguration().getOptions().get(PlatformOptions.class);
+ remoteExecutionProperties = platformOptions.hostPlatformRemotePropertiesOverride;
+ }
platformBuilder.setRemoteExecutionProperties(remoteExecutionProperties);
PlatformInfo platformInfo;