diff options
author | 2017-06-06 06:01:51 -0400 | |
---|---|---|
committer | 2017-06-06 09:51:03 -0400 | |
commit | 8099d2bf0f1ccc5f95ddb659ce600634602e35a8 (patch) | |
tree | baa2433947471d69526faf07e6ebec18d4c8b8f1 /src/main | |
parent | 284a611ce8e70861d7d812c964e2aac7fc086385 (diff) |
Add a tag to ExecutionRequirements that allows disabling local prefetch
Remove SpawnExecutionPolicy.shouldPrefetchInputsForLocalExecution in favor of
a static helper method in Spawns.
PiperOrigin-RevId: 158119993
Diffstat (limited to 'src/main')
4 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java b/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java index a31f4d1e50..ad324fd805 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java @@ -107,6 +107,9 @@ public class ExecutionRequirements { /** If an action would not successfully run other than on Darwin. */ public static final String REQUIRES_DARWIN = "requires-darwin"; + /** Whether we should disable prefetching of inputs before running a local action. */ + public static final String DISABLE_LOCAL_PREFETCH = "disable-local-prefetch"; + /** How many hardware threads an action requires for execution. */ public static final ParseableRequirement CPU = ParseableRequirement.create( diff --git a/src/main/java/com/google/devtools/build/lib/actions/Spawns.java b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java index af8ca07881..be4a0db1ad 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Spawns.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java @@ -48,6 +48,16 @@ public final class Spawns { } } + /** + * Returns whether a local {@link Spawn} runner implementation should prefetch the inputs before + * execution, based on the spawns execution info. + */ + public static boolean shouldPrefetchInputsForLocalExecution(Spawn spawn) { + String disablePrefetchRequest = + spawn.getExecutionInfo().get(ExecutionRequirements.DISABLE_LOCAL_PREFETCH); + return (disablePrefetchRequest == null) || disablePrefetchRequest.equals("0"); + } + /** Convert a spawn into a Bourne shell command. */ public static String asShellCommand(Spawn spawn, Path workingDirectory) { return asShellCommand(spawn.getArguments(), workingDirectory, spawn.getEnvironment()); diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnRunner.java index da25744ff4..a95f144ecc 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnRunner.java @@ -119,13 +119,6 @@ public interface SpawnRunner { * be used by different threads, so they MUST not call any shared non-thread-safe objects. */ public interface SpawnExecutionPolicy { - /** - * Returns whether inputs should be prefetched to the local machine using {@link - * ActionInputPrefetcher} if the spawn is executed locally (with or without sandboxing). - */ - // TODO(ulfjack): Use an execution info value instead. - boolean shouldPrefetchInputsForLocalExecution(Spawn spawn); - /** The input file cache for this specific spawn. */ ActionInputFileCache getActionInputFileCache(); diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java index b96a2269ca..7580a25a2c 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.actions.ActionExecutionMetadata; import com.google.devtools.build.lib.actions.ResourceManager; import com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle; import com.google.devtools.build.lib.actions.Spawn; +import com.google.devtools.build.lib.actions.Spawns; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.exec.ActionInputPrefetcher; import com.google.devtools.build.lib.exec.SpawnResult; @@ -223,7 +224,7 @@ public final class LocalSpawnRunner implements SpawnRunner { .build(); } - if (policy.shouldPrefetchInputsForLocalExecution(spawn)) { + if (Spawns.shouldPrefetchInputsForLocalExecution(spawn)) { stepLog(INFO, "prefetching inputs for local execution"); setState(State.PREFETCHING_LOCAL_INPUTS); actionInputPrefetcher.prefetchFiles(policy.getInputMapping().values()); |