forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bazelbuild#1849: Sandboxing on OS X should be turned off by defau…
…lt 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
- Loading branch information
Showing
7 changed files
with
149 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/com/google/devtools/build/lib/bazel/rules/BazelActionContextConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// 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.bazel.rules; | ||
|
||
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.analysis.actions.FileWriteActionContext; | ||
import com.google.devtools.build.lib.bazel.rules.BazelRulesModule.BazelExecutionOptions; | ||
import com.google.devtools.build.lib.rules.android.WriteAdbArgsActionContext; | ||
import com.google.devtools.build.lib.rules.cpp.CppCompileActionContext; | ||
import com.google.devtools.build.lib.rules.cpp.CppLinkActionContext; | ||
import com.google.devtools.build.lib.rules.cpp.IncludeScanningContext; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* An object describing the {@link ActionContext} implementation that some actions require in Bazel. | ||
*/ | ||
public class BazelActionContextConsumer implements ActionContextConsumer { | ||
private final BazelExecutionOptions options; | ||
|
||
protected BazelActionContextConsumer(BazelExecutionOptions options) { | ||
this.options = options; | ||
} | ||
|
||
@Override | ||
public ImmutableMap<String, String> getSpawnActionContexts() { | ||
Map<String, String> contexts = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
|
||
// Default strategies for certain mnemonics - they can be overridden by --strategy= flags. | ||
contexts.put("Javac", "worker"); | ||
|
||
for (Map.Entry<String, String> strategy : options.strategy) { | ||
String strategyName = strategy.getValue(); | ||
// TODO(philwo) - remove this when the standalone / local mess is cleaned up. | ||
// Some flag expansions use "local" as the strategy name, but the strategy is now called | ||
// "standalone", so we'll translate it here. | ||
if (strategyName.equals("local")) { | ||
strategyName = "standalone"; | ||
} | ||
contexts.put(strategy.getKey(), strategyName); | ||
} | ||
|
||
if (!options.genruleStrategy.isEmpty()) { | ||
contexts.put("Genrule", options.genruleStrategy); | ||
} | ||
|
||
// TODO(bazel-team): put this in getActionContexts (key=SpawnActionContext.class) instead | ||
if (!options.spawnStrategy.isEmpty()) { | ||
contexts.put("", options.spawnStrategy); | ||
} | ||
|
||
return ImmutableMap.copyOf(contexts); | ||
} | ||
|
||
@Override | ||
public Multimap<Class<? extends ActionContext>, String> getActionContexts() { | ||
return ImmutableMultimap.<Class<? extends ActionContext>, String>builder() | ||
.put(CppCompileActionContext.class, "") | ||
.put(CppLinkActionContext.class, "") | ||
.put(IncludeScanningContext.class, "") | ||
.put(FileWriteActionContext.class, "") | ||
.put(WriteAdbArgsActionContext.class, "") | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters