From 43f45b58acf10beadbb1221b71dfa06fa1341510 Mon Sep 17 00:00:00 2001 From: John Cater Date: Tue, 19 Dec 2017 13:21:05 -0800 Subject: 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 --- .../build/lib/remote/RemoteSpawnRunner.java | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java') diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java index c63975738b..695f6ea3bf 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java @@ -26,6 +26,8 @@ import com.google.devtools.build.lib.actions.SpawnResult; import com.google.devtools.build.lib.actions.SpawnResult.Status; import com.google.devtools.build.lib.actions.Spawns; import com.google.devtools.build.lib.actions.cache.VirtualActionInput; +import com.google.devtools.build.lib.analysis.platform.PlatformInfo; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; @@ -46,6 +48,8 @@ import com.google.devtools.remoteexecution.v1test.Digest; import com.google.devtools.remoteexecution.v1test.ExecuteRequest; import com.google.devtools.remoteexecution.v1test.ExecuteResponse; import com.google.devtools.remoteexecution.v1test.Platform; +import com.google.protobuf.TextFormat; +import com.google.protobuf.TextFormat.ParseException; import io.grpc.Context; import io.grpc.Status.Code; import java.io.IOException; @@ -70,8 +74,6 @@ class RemoteSpawnRunner implements SpawnRunner { private final Path execRoot; private final RemoteOptions options; - // TODO(olaola): This will be set on a per-action basis instead. - private final Platform platform; private final SpawnRunner fallbackRunner; private final boolean verboseFailures; @@ -98,7 +100,6 @@ class RemoteSpawnRunner implements SpawnRunner { DigestUtil digestUtil) { this.execRoot = execRoot; this.options = options; - this.platform = options.parseRemotePlatformOverride(); this.fallbackRunner = fallbackRunner; this.remoteCache = remoteCache; this.remoteExecutor = remoteExecutor; @@ -129,7 +130,7 @@ class RemoteSpawnRunner implements SpawnRunner { spawn.getOutputFiles(), digestUtil.compute(command), repository.getMerkleDigest(inputRoot), - platform, + spawn.getExecutionPlatform(), policy.getTimeout(), Spawns.mayBeCached(spawn)); @@ -262,9 +263,10 @@ class RemoteSpawnRunner implements SpawnRunner { Collection outputs, Digest command, Digest inputRoot, - Platform platform, + @Nullable PlatformInfo executionPlatform, Duration timeout, boolean cacheable) { + Action.Builder action = Action.newBuilder(); action.setCommandDigest(command); action.setInputRootDigest(inputRoot); @@ -275,9 +277,14 @@ class RemoteSpawnRunner implements SpawnRunner { Collections.sort(outputPaths); // TODO: output directories should be handled here, when they are supported. action.addAllOutputFiles(outputPaths); - if (platform != null) { + + // Get the remote platform properties. + if (executionPlatform != null) { + Platform platform = + parsePlatform(executionPlatform.label(), executionPlatform.remoteExecutionProperties()); action.setPlatform(platform); } + if (!timeout.isZero()) { action.setTimeout(com.google.protobuf.Duration.newBuilder().setSeconds(timeout.getSeconds())); } @@ -287,6 +294,21 @@ class RemoteSpawnRunner implements SpawnRunner { return action.build(); } + static Platform parsePlatform(Label platformLabel, @Nullable String platformDescription) { + Platform.Builder platformBuilder = Platform.newBuilder(); + try { + if (platformDescription != null) { + TextFormat.getParser().merge(platformDescription, platformBuilder); + } + } catch (ParseException e) { + throw new IllegalArgumentException( + String.format( + "Failed to parse remote_execution_properties from platform %s", platformLabel), + e); + } + return platformBuilder.build(); + } + static Command buildCommand(List arguments, ImmutableMap env) { Command.Builder command = Command.newBuilder(); command.addAllArguments(arguments); -- cgit v1.2.3