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 --- .../StandaloneActionContextConsumer.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java (limited to 'src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java') 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 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, String> getActionContexts() { + // This makes the "standalone" strategy available via --spawn_strategy=standalone, but it is not + // necessarily the default. + return ImmutableMultimap., String>of( + SpawnActionContext.class, "standalone"); + } +} -- cgit v1.2.3