From e898023ffc6c47a27312c4d3659dbeeccdb3cd37 Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Fri, 30 Sep 2016 11:44:20 +0000 Subject: Fix #1849: Sandboxing on OS X should be turned off by default for 0.3.2. This restructures the way we set the default Spawn strategy so that each BlazeModule supplying a SpawnActionContext has an ActionContextConsumer that sets its own SpawnActionContext as the default, with the BazelRulesModule being put as the last module loaded in BazelMain, so that it can override that decision - it only does, if the user explicitly specifies a --spawn_strategy flag. IMHO this is a much saner approach than the older one. So the flow is essentially this: - StandaloneActionContextConsumer sets the default strategy to "standalone". - SandboxActionContextConsumer sets the default strategy to "sandboxed", but only on Linux - BazelRulesModule sets the default strategy to the value of the --spawn_strategy flag, if it is set. -- MOS_MIGRATED_REVID=134770427 --- .../build/lib/sandbox/SandboxActionContextConsumer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java') diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java index cd468fd1f9..403b8b9837 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java @@ -30,22 +30,33 @@ import com.google.devtools.build.lib.util.OS; final class SandboxActionContextConsumer implements ActionContextConsumer { private final ImmutableMultimap, String> contexts; + private final ImmutableMap spawnContexts; public SandboxActionContextConsumer(CommandEnvironment env) { ImmutableMultimap.Builder, String> contexts = ImmutableMultimap.builder(); + ImmutableMap.Builder spawnContexts = ImmutableMap.builder(); + // This makes the "sandboxed" strategy available via --spawn_strategy=sandboxed, + // but it is not necessarily the default. if ((OS.getCurrent() == OS.LINUX && LinuxSandboxedStrategy.isSupported(env)) || (OS.getCurrent() == OS.DARWIN && DarwinSandboxRunner.isSupported())) { contexts.put(SpawnActionContext.class, "sandboxed"); + + // This makes the "sandboxed" strategy the default Spawn strategy on Linux, unless it is + // overridden by a later BlazeModule. + if (OS.getCurrent() == OS.LINUX) { + spawnContexts.put("", "sandboxed"); + } } this.contexts = contexts.build(); + this.spawnContexts = spawnContexts.build(); } @Override public ImmutableMap getSpawnActionContexts() { - return ImmutableMap.of(); + return spawnContexts; } @Override -- cgit v1.2.3