aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/sandbox
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-06-11 01:38:33 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-11 01:40:17 -0700
commit2c89206a407d8cae0945abe7eb179ee6bb77d9de (patch)
tree1314352acb1ccda52be27d8d063104eae891669c /src/main/java/com/google/devtools/build/lib/sandbox
parentce9aafcf63dd198fe16c682dfeedc444f07b5669 (diff)
Remove ActionContextConsumer
Instead, add some simple APIs to ExecutorBuilder and inline all the previous subclasses into their corresponding modules. This removes a bunch of boilerplate. PiperOrigin-RevId: 200017162
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/sandbox')
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java60
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java14
2 files changed, 13 insertions, 61 deletions
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
deleted file mode 100644
index 08547c306f..0000000000
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2015 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.sandbox;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.devtools.build.lib.actions.ActionContext;
-import com.google.devtools.build.lib.actions.SpawnActionContext;
-import com.google.devtools.build.lib.exec.ActionContextConsumer;
-import com.google.devtools.build.lib.exec.SpawnActionContextMaps;
-import com.google.devtools.build.lib.runtime.CommandEnvironment;
-
-/**
- * {@link ActionContextConsumer} that requests the action contexts necessary for sandboxed
- * execution.
- */
-final class SandboxActionContextConsumer implements ActionContextConsumer {
-
- private final ImmutableMultimap<Class<? extends ActionContext>, String> contexts;
- private final ImmutableMap<String, String> spawnContexts;
-
- public SandboxActionContextConsumer(CommandEnvironment cmdEnv) {
- ImmutableMultimap.Builder<Class<? extends ActionContext>, String> contexts =
- ImmutableMultimap.builder();
- ImmutableMap.Builder<String, String> spawnContexts = ImmutableMap.builder();
-
- if (LinuxSandboxedSpawnRunner.isSupported(cmdEnv)
- || DarwinSandboxedSpawnRunner.isSupported(cmdEnv)
- || ProcessWrapperSandboxedSpawnRunner.isSupported(cmdEnv)) {
- // This makes the "sandboxed" strategy available via --spawn_strategy=sandboxed,
- // but it is not necessarily the default.
- contexts.put(SpawnActionContext.class, "sandboxed");
-
- // This makes the "sandboxed" strategy the default Spawn strategy, unless it is
- // overridden by a later BlazeModule.
- spawnContexts.put("", "sandboxed");
- }
-
- this.contexts = contexts.build();
- this.spawnContexts = spawnContexts.build();
- }
-
- @Override
- public void populate(SpawnActionContextMaps.Builder builder) {
- builder.strategyByMnemonicMap().putAll(spawnContexts.entrySet());
- builder.strategyByContextMap().putAll(contexts.entries());
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
index a8fb190e48..14abac497b 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkState;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.Subscribe;
import com.google.devtools.build.lib.actions.ExecutorInitException;
+import com.google.devtools.build.lib.actions.SpawnActionContext;
import com.google.devtools.build.lib.buildtool.BuildRequest;
import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent;
import com.google.devtools.build.lib.buildtool.buildevent.BuildInterruptedEvent;
@@ -133,7 +134,18 @@ public final class SandboxModule extends BlazeModule {
throw new ExecutorInitException("Failed to initialize sandbox", e);
}
builder.addActionContextProvider(provider);
- builder.addActionContextConsumer(new SandboxActionContextConsumer(cmdEnv));
+
+ if (LinuxSandboxedSpawnRunner.isSupported(cmdEnv)
+ || DarwinSandboxedSpawnRunner.isSupported(cmdEnv)
+ || ProcessWrapperSandboxedSpawnRunner.isSupported(cmdEnv)) {
+ // This makes the "sandboxed" strategy available via --spawn_strategy=sandboxed,
+ // but it is not necessarily the default.
+ builder.addStrategyByContext(SpawnActionContext.class, "sandboxed");
+
+ // This makes the "sandboxed" strategy the default Spawn strategy, unless it is
+ // overridden by a later BlazeModule.
+ builder.addStrategyByMnemonic("", "sandboxed");
+ }
// Do not remove the sandbox base when --sandbox_debug was specified so that people can check
// out the contents of the generated sandbox directories.