aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/standalone
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2016-09-30 11:44:20 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-09-30 14:11:25 +0000
commite898023ffc6c47a27312c4d3659dbeeccdb3cd37 (patch)
tree09ee6e816484b8789cbe46ae1a402bcd562576df /src/main/java/com/google/devtools/build/lib/standalone
parentd59bcb6333be731d82c51c20211ecabebe194f19 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/standalone')
-rw-r--r--src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java44
-rw-r--r--src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java8
2 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java
new file mode 100644
index 0000000000..beb1125475
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java
@@ -0,0 +1,44 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.standalone;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Multimap;
+import com.google.devtools.build.lib.actions.ActionContextConsumer;
+import com.google.devtools.build.lib.actions.Executor.ActionContext;
+import com.google.devtools.build.lib.actions.SpawnActionContext;
+
+/**
+ * {@link ActionContextConsumer} that requests the action contexts necessary for standalone
+ * execution.
+ */
+public class StandaloneActionContextConsumer implements ActionContextConsumer {
+
+ @Override
+ public ImmutableMap<String, String> getSpawnActionContexts() {
+ // This makes the "sandboxed" strategy the default Spawn strategy, unless it is overridden by a
+ // later BlazeModule.
+ return ImmutableMap.of("", "standalone");
+ }
+
+ @Override
+ public Multimap<Class<? extends ActionContext>, String> getActionContexts() {
+ // This makes the "standalone" strategy available via --spawn_strategy=standalone, but it is not
+ // necessarily the default.
+ return ImmutableMultimap.<Class<? extends ActionContext>, String>of(
+ SpawnActionContext.class, "standalone");
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
index a8118ea367..58145b0ad3 100644
--- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
+++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
@@ -15,12 +15,14 @@ package com.google.devtools.build.lib.standalone;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.Subscribe;
+import com.google.devtools.build.lib.actions.ActionContextConsumer;
import com.google.devtools.build.lib.actions.ActionContextProvider;
import com.google.devtools.build.lib.buildtool.BuildRequest;
import com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent;
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
+import com.google.devtools.build.lib.util.Preconditions;
/**
* StandaloneModule provides pluggable functionality for blaze.
@@ -30,6 +32,12 @@ public class StandaloneModule extends BlazeModule {
private BuildRequest buildRequest;
@Override
+ public Iterable<ActionContextConsumer> getActionContextConsumers() {
+ Preconditions.checkNotNull(env);
+ return ImmutableList.<ActionContextConsumer>of(new StandaloneActionContextConsumer());
+ }
+
+ @Override
public Iterable<ActionContextProvider> getActionContextProviders() {
return ImmutableList.<ActionContextProvider>of(
new StandaloneActionContextProvider(env, buildRequest));