aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/worker
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-06-11 07:01:48 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-11 07:02:58 -0700
commit65173666790d6fff0190c196536d34743b419c12 (patch)
treeb16cba3ef9419c4fb8ce6fd2cc775696cf8727ce /src/main/java/com/google/devtools/build/lib/worker
parent4cf2ebdcef7b5d4c46e533a560642b89eb3f02a5 (diff)
Inline some ActionContextProvider classes into their modules
This also gets rid of some boilerplate. The ExecutionTool.addActionContext method has been around for a while, but is underused. There are still a few ActionContextProvider implementations left, which are implementing other functionality besides adding action contexts. As a side effect, this change reduces null build time with a hot server on linux by about a quarter. We were running the linux sandbox twice on every build, which takes about 70ms each (on my machine), with the total null build time around 300ms. PiperOrigin-RevId: 200045145
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/worker')
-rw-r--r--src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java74
-rw-r--r--src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java38
2 files changed, 37 insertions, 75 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java
deleted file mode 100644
index f65ee91991..0000000000
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java
+++ /dev/null
@@ -1,74 +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.worker;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.devtools.build.lib.actions.ActionContext;
-import com.google.devtools.build.lib.actions.ResourceManager;
-import com.google.devtools.build.lib.exec.ActionContextProvider;
-import com.google.devtools.build.lib.exec.SpawnRunner;
-import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider;
-import com.google.devtools.build.lib.exec.local.LocalEnvProvider;
-import com.google.devtools.build.lib.exec.local.LocalExecutionOptions;
-import com.google.devtools.build.lib.exec.local.LocalSpawnRunner;
-import com.google.devtools.build.lib.exec.local.PosixLocalEnvProvider;
-import com.google.devtools.build.lib.exec.local.WindowsLocalEnvProvider;
-import com.google.devtools.build.lib.runtime.CommandEnvironment;
-import com.google.devtools.build.lib.util.OS;
-
-/**
- * Factory for the Worker-based execution strategy.
- */
-final class WorkerActionContextProvider extends ActionContextProvider {
- private final ImmutableList<ActionContext> strategies;
-
- public WorkerActionContextProvider(CommandEnvironment env, WorkerPool workers) {
- ImmutableMultimap<String, String> extraFlags =
- ImmutableMultimap.copyOf(env.getOptions().getOptions(WorkerOptions.class).workerExtraFlags);
-
- WorkerSpawnRunner spawnRunner =
- new WorkerSpawnRunner(
- env.getExecRoot(),
- workers,
- extraFlags,
- env.getReporter(),
- createFallbackRunner(env));
-
- WorkerSpawnStrategy workerSpawnStrategy =
- new WorkerSpawnStrategy(env.getExecRoot(), spawnRunner);
- this.strategies = ImmutableList.of(workerSpawnStrategy);
- }
-
- private static SpawnRunner createFallbackRunner(CommandEnvironment env) {
- LocalExecutionOptions localExecutionOptions =
- env.getOptions().getOptions(LocalExecutionOptions.class);
- LocalEnvProvider localEnvProvider =
- OS.getCurrent() == OS.DARWIN
- ? new XcodeLocalEnvProvider(env.getClientEnv())
- : (OS.getCurrent() == OS.WINDOWS
- ? new WindowsLocalEnvProvider(env.getClientEnv())
- : new PosixLocalEnvProvider(env.getClientEnv()));
- return new LocalSpawnRunner(
- env.getExecRoot(),
- localExecutionOptions,
- ResourceManager.instance(),
- localEnvProvider);
- }
-
- @Override
- public Iterable<? extends ActionContext> getActionContexts() {
- return strategies;
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
index b75702dfe8..4a2097d16d 100644
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
@@ -16,7 +16,9 @@ package com.google.devtools.build.lib.worker;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
import com.google.common.eventbus.Subscribe;
+import com.google.devtools.build.lib.actions.ResourceManager;
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;
@@ -24,10 +26,18 @@ import com.google.devtools.build.lib.buildtool.buildevent.BuildInterruptedEvent;
import com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.exec.ExecutorBuilder;
+import com.google.devtools.build.lib.exec.SpawnRunner;
+import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider;
+import com.google.devtools.build.lib.exec.local.LocalEnvProvider;
+import com.google.devtools.build.lib.exec.local.LocalExecutionOptions;
+import com.google.devtools.build.lib.exec.local.LocalSpawnRunner;
+import com.google.devtools.build.lib.exec.local.PosixLocalEnvProvider;
+import com.google.devtools.build.lib.exec.local.WindowsLocalEnvProvider;
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.runtime.commands.CleanCommand.CleanStartingEvent;
+import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.OptionsBase;
import java.io.IOException;
@@ -125,11 +135,37 @@ public class WorkerModule extends BlazeModule {
@Override
public void executorInit(CommandEnvironment env, BuildRequest request, ExecutorBuilder builder) {
Preconditions.checkNotNull(workerPool);
- builder.addActionContextProvider(new WorkerActionContextProvider(env, workerPool));
+ ImmutableMultimap<String, String> extraFlags =
+ ImmutableMultimap.copyOf(env.getOptions().getOptions(WorkerOptions.class).workerExtraFlags);
+ WorkerSpawnRunner spawnRunner =
+ new WorkerSpawnRunner(
+ env.getExecRoot(),
+ workerPool,
+ extraFlags,
+ env.getReporter(),
+ createFallbackRunner(env));
+ builder.addActionContext(new WorkerSpawnStrategy(env.getExecRoot(), spawnRunner));
+
builder.addStrategyByContext(SpawnActionContext.class, "standalone");
builder.addStrategyByContext(SpawnActionContext.class, "worker");
}
+ private static SpawnRunner createFallbackRunner(CommandEnvironment env) {
+ LocalExecutionOptions localExecutionOptions =
+ env.getOptions().getOptions(LocalExecutionOptions.class);
+ LocalEnvProvider localEnvProvider =
+ OS.getCurrent() == OS.DARWIN
+ ? new XcodeLocalEnvProvider(env.getClientEnv())
+ : (OS.getCurrent() == OS.WINDOWS
+ ? new WindowsLocalEnvProvider(env.getClientEnv())
+ : new PosixLocalEnvProvider(env.getClientEnv()));
+ return new LocalSpawnRunner(
+ env.getExecRoot(),
+ localExecutionOptions,
+ ResourceManager.instance(),
+ localEnvProvider);
+ }
+
@Subscribe
public void buildComplete(BuildCompleteEvent event) {
if (options != null && options.workerQuitAfterBuild) {