From dba3c8337efdf1c032f71bd49e04ed9baa9f2b9f Mon Sep 17 00:00:00 2001 From: Ulf Adams Date: Wed, 21 Dec 2016 16:50:02 +0000 Subject: Move some classes to lib.exec in preparation for layering enforcement This change is part of the mu-bazel effort, which aims to build a minimally useful Bazel binary with most extraneous functionality removed. As part of that, we want to enforce layering of packages. In particular, lib.actions must not depend on lib.rules or lib.exec. lib.rules must not depend on lib.exec. Moving these classes is a necessary step to enforce that layering. -- PiperOrigin-RevId: 142668172 MOS_MIGRATED_REVID=142668172 --- .../build/lib/actions/ActionContextConsumer.java | 63 ------ .../build/lib/actions/ActionContextProvider.java | 51 ----- .../devtools/build/lib/actions/BlazeExecutor.java | 222 -------------------- .../build/lib/actions/ExecutorBuilder.java | 81 -------- .../lib/actions/SimpleActionContextProvider.java | 34 ---- .../lib/bazel/BazelWorkspaceStatusModule.java | 2 +- .../bazel/rules/BazelActionContextConsumer.java | 2 +- .../build/lib/bazel/rules/BazelRulesModule.java | 2 +- .../build/lib/buildtool/ExecutionTool.java | 10 +- .../build/lib/exec/ActionContextConsumer.java | 63 ++++++ .../build/lib/exec/ActionContextProvider.java | 55 +++++ .../devtools/build/lib/exec/BlazeExecutor.java | 225 +++++++++++++++++++++ .../devtools/build/lib/exec/ExecutorBuilder.java | 83 ++++++++ .../build/lib/exec/FilesetActionContextImpl.java | 87 ++++++++ .../lib/exec/SimpleActionContextProvider.java | 34 ++++ .../lib/remote/RemoteActionContextProvider.java | 2 +- .../devtools/build/lib/remote/RemoteModule.java | 2 +- .../rules/fileset/FilesetActionContextImpl.java | 89 -------- .../devtools/build/lib/runtime/BlazeModule.java | 2 +- .../lib/sandbox/SandboxActionContextConsumer.java | 2 +- .../lib/sandbox/SandboxActionContextProvider.java | 2 +- .../devtools/build/lib/sandbox/SandboxModule.java | 2 +- .../StandaloneActionContextConsumer.java | 2 +- .../StandaloneActionContextProvider.java | 2 +- .../build/lib/standalone/StandaloneModule.java | 2 +- .../lib/worker/WorkerActionContextConsumer.java | 2 +- .../lib/worker/WorkerActionContextProvider.java | 2 +- .../devtools/build/lib/worker/WorkerModule.java | 2 +- 28 files changed, 567 insertions(+), 560 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/actions/ActionContextConsumer.java delete mode 100644 src/main/java/com/google/devtools/build/lib/actions/ActionContextProvider.java delete mode 100644 src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java delete mode 100644 src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java delete mode 100644 src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/ActionContextConsumer.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/ActionContextProvider.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/ExecutorBuilder.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/FilesetActionContextImpl.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/SimpleActionContextProvider.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetActionContextImpl.java (limited to 'src/main/java/com/google') diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionContextConsumer.java b/src/main/java/com/google/devtools/build/lib/actions/ActionContextConsumer.java deleted file mode 100644 index 4c34fec5e3..0000000000 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionContextConsumer.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2014 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.actions; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Multimap; -import com.google.devtools.build.lib.actions.Executor.ActionContext; - -/** - * An object describing that actions require a particular implementation of an - * {@link ActionContext}. - * - *

This is expected to be implemented by modules that also implement actions which need these - * contexts. Other modules will provide implementations for various action contexts by implementing - * {@link ActionContextProvider}. - * - *

Example: a module requires {@code SpawnActionContext} to do its job, and it creates - * actions with the mnemonic C++. Then the {@link #getSpawnActionContexts} method of - * this module would return a map with the key "C++" in it. - * - *

The module can either decide for itself which implementation is needed and make the value - * associated with this key a constant or defer that decision to the user, for example, by - * providing a command line option and setting the value in the map based on that. - * - *

Other modules are free to provide different implementations of {@code SpawnActionContext}. - * This can be used, for example, to implement sandboxed or distributed execution of - * {@code SpawnAction}s in different ways, while giving the user control over how exactly they - * are executed. - */ -public interface ActionContextConsumer { - /** - * Returns a map from spawn action mnemonics created by this module to the name of the - * implementation of {@code SpawnActionContext} that the module wants to use for executing - * it. - * - *

If a spawn action is executed whose mnemonic maps to the empty string or is not - * present in the map at all, the choice of the implementation is left to Blaze. - * - *

Matching on mnemonics is done case-insensitively so it is recommended that any - * implementation of this method makes sure that no two keys that refer to the same mnemonic are - * present in the returned map. The easiest way to assure this is to use a map created using - * {@code new TreeMap<>(String.CASE_INSENSITIVE_ORDER)}. - */ - ImmutableMap getSpawnActionContexts(); - - /** - * Returns a map from action context class to the implementation required by the module. - * - *

If the implementation name is the empty string, the choice is left to Blaze. - */ - Multimap, String> getActionContexts(); -} diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/actions/ActionContextProvider.java deleted file mode 100644 index 2ac75b36a6..0000000000 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionContextProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 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.actions; - -import com.google.devtools.build.lib.actions.Executor.ActionContext; - -/** - * An object that provides execution strategies to {@link BlazeExecutor}. - * - *

For more information, see {@link ActionContextConsumer}. - */ -public abstract class ActionContextProvider { - /** - * Returns the execution strategies that are provided by this object. - * - *

These may or may not actually end up in the executor depending on the command line options - * and other factors influencing how the executor is set up. - */ - public abstract Iterable getActionContexts(); - - /** - * Called when the executor is constructed. The parameter contains all the contexts that were - * selected for this execution phase. - */ - public void executorCreated(Iterable usedContexts) throws ExecutorInitException {} - - /** - * Called when the execution phase is started. - */ - public void executionPhaseStarting( - ActionInputFileCache actionInputFileCache, - ActionGraph actionGraph, - Iterable topLevelArtifacts) - throws ExecutorInitException, InterruptedException {} - - /** - * Called when the execution phase is finished. - */ - public void executionPhaseEnding() {} -} diff --git a/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java b/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java deleted file mode 100644 index 1c7c4be539..0000000000 --- a/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2014 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.actions; - -import com.google.common.collect.ImmutableMap; -import com.google.common.eventbus.EventBus; -import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; -import com.google.devtools.build.lib.events.Event; -import com.google.devtools.build.lib.events.EventHandler; -import com.google.devtools.build.lib.events.EventKind; -import com.google.devtools.build.lib.events.Reporter; -import com.google.devtools.build.lib.profiler.Profiler; -import com.google.devtools.build.lib.profiler.ProfilerTask; -import com.google.devtools.build.lib.util.Clock; -import com.google.devtools.build.lib.util.Preconditions; -import com.google.devtools.build.lib.vfs.Path; -import com.google.devtools.common.options.OptionsClassProvider; - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * The Executor class provides a dynamic abstraction of the various actual primitive system - * operations that might be performed during a build step. - * - *

Constructions of this class might perform distributed execution, "virtual" execution for - * testing purposes, or just print out the sequence of commands that would be executed, like Make's - * "-n" option. - */ -@ThreadSafe -public final class BlazeExecutor implements Executor { - - private final boolean verboseFailures; - private final boolean showSubcommands; - private final Path execRoot; - private final Reporter reporter; - private final EventBus eventBus; - private final Clock clock; - private final OptionsClassProvider options; - private AtomicBoolean inExecutionPhase; - - private final Map spawnActionContextMap; - private final Map, ActionContext> contextMap = - new HashMap<>(); - - /** - * Constructs an Executor, bound to a specified output base path, and which - * will use the specified reporter to announce SUBCOMMAND events, - * the given event bus to delegate events and the given output streams - * for streaming output. The list of - * strategy implementation classes is used to construct instances of the - * strategies mapped by their declared abstract type. This list is uniquified - * before using. Each strategy instance is created with a reference to this - * Executor as well as the given options object. - *

- * Don't forget to call startBuildRequest() and stopBuildRequest() for each - * request, and shutdown() when you're done with this executor. - */ - public BlazeExecutor(Path execRoot, - Reporter reporter, - EventBus eventBus, - Clock clock, - OptionsClassProvider options, - boolean verboseFailures, - boolean showSubcommands, - List contextImplementations, - Map spawnActionContextMap, - Iterable contextProviders) - throws ExecutorInitException { - this.verboseFailures = verboseFailures; - this.showSubcommands = showSubcommands; - this.execRoot = execRoot; - this.reporter = reporter; - this.eventBus = eventBus; - this.clock = clock; - this.options = options; - this.inExecutionPhase = new AtomicBoolean(false); - - // We need to keep only the last occurrences of the entries in contextImplementations - // (so we respect insertion order but also instantiate them only once). - LinkedHashSet allContexts = new LinkedHashSet<>(); - allContexts.addAll(contextImplementations); - allContexts.addAll(spawnActionContextMap.values()); - this.spawnActionContextMap = ImmutableMap.copyOf(spawnActionContextMap); - - for (ActionContext context : contextImplementations) { - ExecutionStrategy annotation = context.getClass().getAnnotation(ExecutionStrategy.class); - if (annotation != null) { - contextMap.put(annotation.contextType(), context); - } - contextMap.put(context.getClass(), context); - } - - for (ActionContextProvider factory : contextProviders) { - factory.executorCreated(allContexts); - } - } - - @Override - public Path getExecRoot() { - return execRoot; - } - - @Override - public EventHandler getEventHandler() { - return reporter; - } - - @Override - public EventBus getEventBus() { - return eventBus; - } - - @Override - public Clock getClock() { - return clock; - } - - @Override - public boolean reportsSubcommands() { - return showSubcommands; - } - - /** - * Report a subcommand event to this Executor's Reporter and, if action - * logging is enabled, post it on its EventBus. - */ - @Override - public void reportSubcommand(String reason, String message) { - reporter.handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message)); - } - - /** - * This method is called before the start of the execution phase of each - * build request. - */ - public void executionPhaseStarting() { - Preconditions.checkState(!inExecutionPhase.getAndSet(true)); - Profiler.instance().startTask(ProfilerTask.INFO, "Initializing executors"); - Profiler.instance().completeTask(ProfilerTask.INFO); - } - - /** - * This method is called after the end of the execution phase of each build - * request (even if there was an interrupt). - */ - public void executionPhaseEnding() { - if (!inExecutionPhase.get()) { - return; - } - - Profiler.instance().startTask(ProfilerTask.INFO, "Shutting down executors"); - Profiler.instance().completeTask(ProfilerTask.INFO); - inExecutionPhase.set(false); - } - - public static void shutdownHelperPool(EventHandler reporter, ExecutorService pool, - String name) { - pool.shutdownNow(); - - boolean interrupted = false; - while (true) { - try { - if (!pool.awaitTermination(10, TimeUnit.SECONDS)) { - reporter.handle(Event.warn(name + " threadpool shutdown took greater than ten seconds")); - } - break; - } catch (InterruptedException e) { - interrupted = true; - } - } - - if (interrupted) { - Thread.currentThread().interrupt(); - } - } - - @Override - public T getContext(Class type) { - Preconditions.checkArgument(type != SpawnActionContext.class, - "should use getSpawnActionContext instead"); - return type.cast(contextMap.get(type)); - } - - /** - * Returns the {@link SpawnActionContext} to use for the given mnemonic. If no execution mode is - * set, then it returns the default strategy for spawn actions. - */ - @Override - public SpawnActionContext getSpawnActionContext(String mnemonic) { - SpawnActionContext context = spawnActionContextMap.get(mnemonic); - return context == null ? spawnActionContextMap.get("") : context; - } - - /** Returns true iff the --verbose_failures option was enabled. */ - @Override - public boolean getVerboseFailures() { - return verboseFailures; - } - - /** Returns the options associated with the execution. */ - @Override - public OptionsClassProvider getOptions() { - return options; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java b/src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java deleted file mode 100644 index d22bc3d332..0000000000 --- a/src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java +++ /dev/null @@ -1,81 +0,0 @@ -// 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.actions; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.Executor.ActionContext; -import com.google.devtools.build.lib.util.Preconditions; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nullable; - -/** - * Builder class to create an {@link Executor} instance. This class is part of the module API, - * which allows modules to affect how the executor is initialized. - */ -public class ExecutorBuilder { - private final List actionContextProviders = new ArrayList<>(); - private final List actionContextConsumers = new ArrayList<>(); - private ActionInputFileCache cache; - - // These methods shouldn't be public, but they have to be right now as ExecutionTool is in another - // package. - public ImmutableList getActionContextProviders() { - return ImmutableList.copyOf(actionContextProviders); - } - - public ImmutableList getActionContextConsumers() { - return ImmutableList.copyOf(actionContextConsumers); - } - - @Nullable - public ActionInputFileCache getActionInputFileCache() { - return cache; - } - - /** - * Adds the specified action context providers to the executor. - */ - public ExecutorBuilder addActionContextProvider(ActionContextProvider provider) { - this.actionContextProviders.add(provider); - return this; - } - - /** - * Adds the specified action context to the executor, by wrapping it in a simple action context - * provider implementation. - */ - public ExecutorBuilder addActionContext(ActionContext context) { - return addActionContextProvider(new SimpleActionContextProvider(context)); - } - - /** - * Adds the specified action context consumer to the executor. - */ - public ExecutorBuilder addActionContextConsumer(ActionContextConsumer consumer) { - this.actionContextConsumers.add(consumer); - return this; - } - - /** - * Sets the cache for action input files. Only one module may set the cache. If multiple modules - * set it, this method will throw an {@link IllegalStateException}. - */ - public ExecutorBuilder setActionInputFileCache(ActionInputFileCache cache) { - Preconditions.checkState(this.cache == null); - this.cache = Preconditions.checkNotNull(cache); - return this; - } -} - diff --git a/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java deleted file mode 100644 index 642bc09ada..0000000000 --- a/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java +++ /dev/null @@ -1,34 +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.actions; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.Executor.ActionContext; -import java.util.List; - -/** - * An {@link ActionContextProvider} that just provides the {@link ActionContext}s it's given. - */ -final class SimpleActionContextProvider extends ActionContextProvider { - private final List actionContexts; - - public SimpleActionContextProvider(ActionContext... contexts) { - actionContexts = ImmutableList.copyOf(contexts); - } - - @Override - public Iterable getActionContexts() { - return actionContexts; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java index 4282c762e6..a31f319a13 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java @@ -30,7 +30,6 @@ import com.google.devtools.build.lib.actions.ArtifactFactory; import com.google.devtools.build.lib.actions.ArtifactOwner; import com.google.devtools.build.lib.actions.ExecutionStrategy; import com.google.devtools.build.lib.actions.Executor; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.actions.ResourceSet; import com.google.devtools.build.lib.actions.Root; import com.google.devtools.build.lib.analysis.BlazeDirectories; @@ -40,6 +39,7 @@ import com.google.devtools.build.lib.analysis.WorkspaceStatusAction.Key; import com.google.devtools.build.lib.analysis.WorkspaceStatusAction.KeyType; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.exec.ExecutorBuilder; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelActionContextConsumer.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelActionContextConsumer.java index 57036e09ed..03bf7d471e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelActionContextConsumer.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelActionContextConsumer.java @@ -17,10 +17,10 @@ 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.exec.ActionContextConsumer; 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; diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java index 314e4404ba..4ce93cf2b1 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java @@ -16,11 +16,11 @@ package com.google.devtools.build.lib.bazel.rules; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses; import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ExecutorBuilder; import com.google.devtools.build.lib.query2.output.OutputFormatter; import com.google.devtools.build.lib.rules.android.WriteAdbArgsActionContext; import com.google.devtools.build.lib.rules.cpp.FdoSupportFunction; diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java index 81fbc3054a..397521512e 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java @@ -30,20 +30,16 @@ import com.google.common.collect.Ordering; import com.google.common.collect.Table; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionCacheChecker; -import com.google.devtools.build.lib.actions.ActionContextConsumer; import com.google.devtools.build.lib.actions.ActionContextMarker; -import com.google.devtools.build.lib.actions.ActionContextProvider; import com.google.devtools.build.lib.actions.ActionGraph; import com.google.devtools.build.lib.actions.ActionInputFileCache; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactFactory; -import com.google.devtools.build.lib.actions.BlazeExecutor; import com.google.devtools.build.lib.actions.BuildFailedException; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.ExecutionStrategy; import com.google.devtools.build.lib.actions.Executor; import com.google.devtools.build.lib.actions.Executor.ActionContext; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.actions.ExecutorInitException; import com.google.devtools.build.lib.actions.LocalHostCapacity; import com.google.devtools.build.lib.actions.ResourceManager; @@ -66,8 +62,13 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.events.Reporter; +import com.google.devtools.build.lib.exec.ActionContextConsumer; +import com.google.devtools.build.lib.exec.ActionContextProvider; +import com.google.devtools.build.lib.exec.BlazeExecutor; import com.google.devtools.build.lib.exec.CheckUpToDateFilter; import com.google.devtools.build.lib.exec.ExecutionOptions; +import com.google.devtools.build.lib.exec.ExecutorBuilder; +import com.google.devtools.build.lib.exec.FilesetActionContextImpl; import com.google.devtools.build.lib.exec.OutputService; import com.google.devtools.build.lib.exec.SingleBuildFileCache; import com.google.devtools.build.lib.exec.SymlinkTreeStrategy; @@ -76,7 +77,6 @@ import com.google.devtools.build.lib.profiler.ProfilePhase; import com.google.devtools.build.lib.profiler.Profiler; import com.google.devtools.build.lib.profiler.ProfilerTask; import com.google.devtools.build.lib.rules.fileset.FilesetActionContext; -import com.google.devtools.build.lib.rules.fileset.FilesetActionContextImpl; import com.google.devtools.build.lib.rules.test.TestActionContext; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.BlazeRuntime; diff --git a/src/main/java/com/google/devtools/build/lib/exec/ActionContextConsumer.java b/src/main/java/com/google/devtools/build/lib/exec/ActionContextConsumer.java new file mode 100644 index 0000000000..cc51a60545 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/ActionContextConsumer.java @@ -0,0 +1,63 @@ +// Copyright 2014 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.exec; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Multimap; +import com.google.devtools.build.lib.actions.Executor.ActionContext; + +/** + * An object describing that actions require a particular implementation of an + * {@link ActionContext}. + * + *

This is expected to be implemented by modules that also implement actions which need these + * contexts. Other modules will provide implementations for various action contexts by implementing + * {@link ActionContextProvider}. + * + *

Example: a module requires {@code SpawnActionContext} to do its job, and it creates + * actions with the mnemonic C++. Then the {@link #getSpawnActionContexts} method of + * this module would return a map with the key "C++" in it. + * + *

The module can either decide for itself which implementation is needed and make the value + * associated with this key a constant or defer that decision to the user, for example, by + * providing a command line option and setting the value in the map based on that. + * + *

Other modules are free to provide different implementations of {@code SpawnActionContext}. + * This can be used, for example, to implement sandboxed or distributed execution of + * {@code SpawnAction}s in different ways, while giving the user control over how exactly they + * are executed. + */ +public interface ActionContextConsumer { + /** + * Returns a map from spawn action mnemonics created by this module to the name of the + * implementation of {@code SpawnActionContext} that the module wants to use for executing + * it. + * + *

If a spawn action is executed whose mnemonic maps to the empty string or is not + * present in the map at all, the choice of the implementation is left to Blaze. + * + *

Matching on mnemonics is done case-insensitively so it is recommended that any + * implementation of this method makes sure that no two keys that refer to the same mnemonic are + * present in the returned map. The easiest way to assure this is to use a map created using + * {@code new TreeMap<>(String.CASE_INSENSITIVE_ORDER)}. + */ + ImmutableMap getSpawnActionContexts(); + + /** + * Returns a map from action context class to the implementation required by the module. + * + *

If the implementation name is the empty string, the choice is left to Blaze. + */ + Multimap, String> getActionContexts(); +} diff --git a/src/main/java/com/google/devtools/build/lib/exec/ActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/exec/ActionContextProvider.java new file mode 100644 index 0000000000..6bdd81d56a --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/ActionContextProvider.java @@ -0,0 +1,55 @@ +// Copyright 2014 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.exec; + +import com.google.devtools.build.lib.actions.ActionGraph; +import com.google.devtools.build.lib.actions.ActionInputFileCache; +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.Executor.ActionContext; +import com.google.devtools.build.lib.actions.ExecutorInitException; + +/** + * An object that provides execution strategies to {@link BlazeExecutor}. + * + *

For more information, see {@link ActionContextConsumer}. + */ +public abstract class ActionContextProvider { + /** + * Returns the execution strategies that are provided by this object. + * + *

These may or may not actually end up in the executor depending on the command line options + * and other factors influencing how the executor is set up. + */ + public abstract Iterable getActionContexts(); + + /** + * Called when the executor is constructed. The parameter contains all the contexts that were + * selected for this execution phase. + */ + public void executorCreated(Iterable usedContexts) throws ExecutorInitException {} + + /** + * Called when the execution phase is started. + */ + public void executionPhaseStarting( + ActionInputFileCache actionInputFileCache, + ActionGraph actionGraph, + Iterable topLevelArtifacts) + throws ExecutorInitException, InterruptedException {} + + /** + * Called when the execution phase is finished. + */ + public void executionPhaseEnding() {} +} diff --git a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java new file mode 100644 index 0000000000..3d25dba0b6 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java @@ -0,0 +1,225 @@ +// Copyright 2014 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.exec; + +import com.google.common.collect.ImmutableMap; +import com.google.common.eventbus.EventBus; +import com.google.devtools.build.lib.actions.ExecutionStrategy; +import com.google.devtools.build.lib.actions.Executor; +import com.google.devtools.build.lib.actions.ExecutorInitException; +import com.google.devtools.build.lib.actions.SpawnActionContext; +import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; +import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.events.EventHandler; +import com.google.devtools.build.lib.events.EventKind; +import com.google.devtools.build.lib.events.Reporter; +import com.google.devtools.build.lib.profiler.Profiler; +import com.google.devtools.build.lib.profiler.ProfilerTask; +import com.google.devtools.build.lib.util.Clock; +import com.google.devtools.build.lib.util.Preconditions; +import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.common.options.OptionsClassProvider; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * The Executor class provides a dynamic abstraction of the various actual primitive system + * operations that might be performed during a build step. + * + *

Constructions of this class might perform distributed execution, "virtual" execution for + * testing purposes, or just print out the sequence of commands that would be executed, like Make's + * "-n" option. + */ +@ThreadSafe +public final class BlazeExecutor implements Executor { + + private final boolean verboseFailures; + private final boolean showSubcommands; + private final Path execRoot; + private final Reporter reporter; + private final EventBus eventBus; + private final Clock clock; + private final OptionsClassProvider options; + private AtomicBoolean inExecutionPhase; + + private final Map spawnActionContextMap; + private final Map, ActionContext> contextMap = + new HashMap<>(); + + /** + * Constructs an Executor, bound to a specified output base path, and which + * will use the specified reporter to announce SUBCOMMAND events, + * the given event bus to delegate events and the given output streams + * for streaming output. The list of + * strategy implementation classes is used to construct instances of the + * strategies mapped by their declared abstract type. This list is uniquified + * before using. Each strategy instance is created with a reference to this + * Executor as well as the given options object. + *

+ * Don't forget to call startBuildRequest() and stopBuildRequest() for each + * request, and shutdown() when you're done with this executor. + */ + public BlazeExecutor(Path execRoot, + Reporter reporter, + EventBus eventBus, + Clock clock, + OptionsClassProvider options, + boolean verboseFailures, + boolean showSubcommands, + List contextImplementations, + Map spawnActionContextMap, + Iterable contextProviders) + throws ExecutorInitException { + this.verboseFailures = verboseFailures; + this.showSubcommands = showSubcommands; + this.execRoot = execRoot; + this.reporter = reporter; + this.eventBus = eventBus; + this.clock = clock; + this.options = options; + this.inExecutionPhase = new AtomicBoolean(false); + + // We need to keep only the last occurrences of the entries in contextImplementations + // (so we respect insertion order but also instantiate them only once). + LinkedHashSet allContexts = new LinkedHashSet<>(); + allContexts.addAll(contextImplementations); + allContexts.addAll(spawnActionContextMap.values()); + this.spawnActionContextMap = ImmutableMap.copyOf(spawnActionContextMap); + + for (ActionContext context : contextImplementations) { + ExecutionStrategy annotation = context.getClass().getAnnotation(ExecutionStrategy.class); + if (annotation != null) { + contextMap.put(annotation.contextType(), context); + } + contextMap.put(context.getClass(), context); + } + + for (ActionContextProvider factory : contextProviders) { + factory.executorCreated(allContexts); + } + } + + @Override + public Path getExecRoot() { + return execRoot; + } + + @Override + public EventHandler getEventHandler() { + return reporter; + } + + @Override + public EventBus getEventBus() { + return eventBus; + } + + @Override + public Clock getClock() { + return clock; + } + + @Override + public boolean reportsSubcommands() { + return showSubcommands; + } + + /** + * Report a subcommand event to this Executor's Reporter and, if action + * logging is enabled, post it on its EventBus. + */ + @Override + public void reportSubcommand(String reason, String message) { + reporter.handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message)); + } + + /** + * This method is called before the start of the execution phase of each + * build request. + */ + public void executionPhaseStarting() { + Preconditions.checkState(!inExecutionPhase.getAndSet(true)); + Profiler.instance().startTask(ProfilerTask.INFO, "Initializing executors"); + Profiler.instance().completeTask(ProfilerTask.INFO); + } + + /** + * This method is called after the end of the execution phase of each build + * request (even if there was an interrupt). + */ + public void executionPhaseEnding() { + if (!inExecutionPhase.get()) { + return; + } + + Profiler.instance().startTask(ProfilerTask.INFO, "Shutting down executors"); + Profiler.instance().completeTask(ProfilerTask.INFO); + inExecutionPhase.set(false); + } + + public static void shutdownHelperPool(EventHandler reporter, ExecutorService pool, + String name) { + pool.shutdownNow(); + + boolean interrupted = false; + while (true) { + try { + if (!pool.awaitTermination(10, TimeUnit.SECONDS)) { + reporter.handle(Event.warn(name + " threadpool shutdown took greater than ten seconds")); + } + break; + } catch (InterruptedException e) { + interrupted = true; + } + } + + if (interrupted) { + Thread.currentThread().interrupt(); + } + } + + @Override + public T getContext(Class type) { + Preconditions.checkArgument(type != SpawnActionContext.class, + "should use getSpawnActionContext instead"); + return type.cast(contextMap.get(type)); + } + + /** + * Returns the {@link SpawnActionContext} to use for the given mnemonic. If no execution mode is + * set, then it returns the default strategy for spawn actions. + */ + @Override + public SpawnActionContext getSpawnActionContext(String mnemonic) { + SpawnActionContext context = spawnActionContextMap.get(mnemonic); + return context == null ? spawnActionContextMap.get("") : context; + } + + /** Returns true iff the --verbose_failures option was enabled. */ + @Override + public boolean getVerboseFailures() { + return verboseFailures; + } + + /** Returns the options associated with the execution. */ + @Override + public OptionsClassProvider getOptions() { + return options; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutorBuilder.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutorBuilder.java new file mode 100644 index 0000000000..5c90c6de49 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutorBuilder.java @@ -0,0 +1,83 @@ +// 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.exec; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.actions.ActionInputFileCache; +import com.google.devtools.build.lib.actions.Executor; +import com.google.devtools.build.lib.actions.Executor.ActionContext; +import com.google.devtools.build.lib.util.Preconditions; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; + +/** + * Builder class to create an {@link Executor} instance. This class is part of the module API, + * which allows modules to affect how the executor is initialized. + */ +public class ExecutorBuilder { + private final List actionContextProviders = new ArrayList<>(); + private final List actionContextConsumers = new ArrayList<>(); + private ActionInputFileCache cache; + + // These methods shouldn't be public, but they have to be right now as ExecutionTool is in another + // package. + public ImmutableList getActionContextProviders() { + return ImmutableList.copyOf(actionContextProviders); + } + + public ImmutableList getActionContextConsumers() { + return ImmutableList.copyOf(actionContextConsumers); + } + + @Nullable + public ActionInputFileCache getActionInputFileCache() { + return cache; + } + + /** + * Adds the specified action context providers to the executor. + */ + public ExecutorBuilder addActionContextProvider(ActionContextProvider provider) { + this.actionContextProviders.add(provider); + return this; + } + + /** + * Adds the specified action context to the executor, by wrapping it in a simple action context + * provider implementation. + */ + public ExecutorBuilder addActionContext(ActionContext context) { + return addActionContextProvider(new SimpleActionContextProvider(context)); + } + + /** + * Adds the specified action context consumer to the executor. + */ + public ExecutorBuilder addActionContextConsumer(ActionContextConsumer consumer) { + this.actionContextConsumers.add(consumer); + return this; + } + + /** + * Sets the cache for action input files. Only one module may set the cache. If multiple modules + * set it, this method will throw an {@link IllegalStateException}. + */ + public ExecutorBuilder setActionInputFileCache(ActionInputFileCache cache) { + Preconditions.checkState(this.cache == null); + this.cache = Preconditions.checkNotNull(cache); + return this; + } +} + diff --git a/src/main/java/com/google/devtools/build/lib/exec/FilesetActionContextImpl.java b/src/main/java/com/google/devtools/build/lib/exec/FilesetActionContextImpl.java new file mode 100644 index 0000000000..0be6549792 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/FilesetActionContextImpl.java @@ -0,0 +1,87 @@ +// Copyright 2014 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.exec; + +import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.devtools.build.lib.actions.ExecutionStrategy; +import com.google.devtools.build.lib.actions.Executor.ActionContext; +import com.google.devtools.build.lib.events.Reporter; +import com.google.devtools.build.lib.rules.fileset.FilesetActionContext; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * Context for Fileset manifest actions. It currently only provides a ThreadPoolExecutor. + * + *

Fileset is a legacy, google-internal mechanism to make parts of the source tree appear as a + * tree in the output directory. + */ +@ExecutionStrategy(contextType = FilesetActionContext.class) +public final class FilesetActionContextImpl implements FilesetActionContext { + // TODO(bazel-team): it would be nice if this weren't shipped in Bazel at all. + + /** + * Factory class. + */ + public static class Provider extends ActionContextProvider { + private FilesetActionContextImpl impl; + private final Reporter reporter; + private final ThreadPoolExecutor filesetPool; + + public Provider(Reporter reporter, String workspaceName) { + this.reporter = reporter; + this.filesetPool = newFilesetPool(100); + this.impl = new FilesetActionContextImpl(filesetPool, workspaceName); + } + + private static ThreadPoolExecutor newFilesetPool(int threads) { + ThreadPoolExecutor pool = new ThreadPoolExecutor(threads, threads, 3L, TimeUnit.SECONDS, + new LinkedBlockingQueue()); + // Do not consume threads when not in use. + pool.allowCoreThreadTimeOut(true); + pool.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("Fileset worker %d").build()); + return pool; + } + + @Override + public Iterable getActionContexts() { + return ImmutableList.of(impl); + } + + @Override + public void executionPhaseEnding() { + BlazeExecutor.shutdownHelperPool(reporter, filesetPool, "Fileset"); + } + } + + private final ThreadPoolExecutor filesetPool; + private final String workspaceName; + + private FilesetActionContextImpl(ThreadPoolExecutor filesetPool, String workspaceName) { + this.filesetPool = filesetPool; + this.workspaceName = workspaceName; + } + + @Override + public ThreadPoolExecutor getFilesetPool() { + return filesetPool; + } + + @Override + public String getWorkspaceName() { + return workspaceName; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/exec/SimpleActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/exec/SimpleActionContextProvider.java new file mode 100644 index 0000000000..a0f8aaef37 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/SimpleActionContextProvider.java @@ -0,0 +1,34 @@ +// 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.exec; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.actions.Executor.ActionContext; +import java.util.List; + +/** + * An {@link ActionContextProvider} that just provides the {@link ActionContext}s it's given. + */ +final class SimpleActionContextProvider extends ActionContextProvider { + private final List actionContexts; + + public SimpleActionContextProvider(ActionContext... contexts) { + actionContexts = ImmutableList.copyOf(contexts); + } + + @Override + public Iterable getActionContexts() { + return actionContexts; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java index d4c160d685..b7c2830a62 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java @@ -16,9 +16,9 @@ package com.google.devtools.build.lib.remote; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; -import com.google.devtools.build.lib.actions.ActionContextProvider; import com.google.devtools.build.lib.actions.Executor.ActionContext; import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.ExecutionOptions; import com.google.devtools.build.lib.runtime.CommandEnvironment; diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java index dc9e351a5c..163294745e 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java @@ -16,9 +16,9 @@ package com.google.devtools.build.lib.remote; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.Subscribe; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent; +import com.google.devtools.build.lib.exec.ExecutorBuilder; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; diff --git a/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetActionContextImpl.java b/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetActionContextImpl.java deleted file mode 100644 index 3ddc3aa0ed..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetActionContextImpl.java +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2014 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.rules.fileset; - -import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.google.devtools.build.lib.actions.ActionContextProvider; -import com.google.devtools.build.lib.actions.BlazeExecutor; -import com.google.devtools.build.lib.actions.ExecutionStrategy; -import com.google.devtools.build.lib.actions.Executor.ActionContext; -import com.google.devtools.build.lib.events.Reporter; - -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * Context for Fileset manifest actions. It currently only provides a ThreadPoolExecutor. - * - *

Fileset is a legacy, google-internal mechanism to make parts of the source tree appear as a - * tree in the output directory. - */ -@ExecutionStrategy(contextType = FilesetActionContext.class) -public final class FilesetActionContextImpl implements FilesetActionContext { - // TODO(bazel-team): it would be nice if this weren't shipped in Bazel at all. - - /** - * Factory class. - */ - public static class Provider extends ActionContextProvider { - private FilesetActionContextImpl impl; - private final Reporter reporter; - private final ThreadPoolExecutor filesetPool; - - public Provider(Reporter reporter, String workspaceName) { - this.reporter = reporter; - this.filesetPool = newFilesetPool(100); - this.impl = new FilesetActionContextImpl(filesetPool, workspaceName); - } - - private static ThreadPoolExecutor newFilesetPool(int threads) { - ThreadPoolExecutor pool = new ThreadPoolExecutor(threads, threads, 3L, TimeUnit.SECONDS, - new LinkedBlockingQueue()); - // Do not consume threads when not in use. - pool.allowCoreThreadTimeOut(true); - pool.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("Fileset worker %d").build()); - return pool; - } - - @Override - public Iterable getActionContexts() { - return ImmutableList.of(impl); - } - - @Override - public void executionPhaseEnding() { - BlazeExecutor.shutdownHelperPool(reporter, filesetPool, "Fileset"); - } - } - - private final ThreadPoolExecutor filesetPool; - private final String workspaceName; - - private FilesetActionContextImpl(ThreadPoolExecutor filesetPool, String workspaceName) { - this.filesetPool = filesetPool; - this.workspaceName = workspaceName; - } - - @Override - public ThreadPoolExecutor getFilesetPool() { - return filesetPool; - } - - @Override - public String getWorkspaceName() { - return workspaceName; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java index 9fbd0ff7d8..dde71d48b8 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.runtime; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; @@ -22,6 +21,7 @@ import com.google.devtools.build.lib.analysis.ServerDirectories; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.exec.ActionInputPrefetcher; +import com.google.devtools.build.lib.exec.ExecutorBuilder; import com.google.devtools.build.lib.exec.OutputService; import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.packages.Package; 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 index ad2d0652ba..2a33771186 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextConsumer.java @@ -17,9 +17,9 @@ package com.google.devtools.build.lib.sandbox; 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; +import com.google.devtools.build.lib.exec.ActionContextConsumer; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.OS; diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java index 4af6ebf317..d27bd5517f 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java @@ -15,10 +15,10 @@ package com.google.devtools.build.lib.sandbox; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.ActionContextProvider; import com.google.devtools.build.lib.actions.Executor.ActionContext; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.ExecutionOptions; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.OS; 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 a8b67139b1..14c853ae98 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 @@ -15,8 +15,8 @@ package com.google.devtools.build.lib.sandbox; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ExecutorBuilder; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; 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 index beb1125475..663c02928a 100644 --- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java +++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextConsumer.java @@ -17,9 +17,9 @@ 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; +import com.google.devtools.build.lib.exec.ActionContextConsumer; /** * {@link ActionContextConsumer} that requests the action contexts necessary for standalone diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java index 668e76b313..1e74c9b530 100644 --- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java @@ -16,13 +16,13 @@ package com.google.devtools.build.lib.standalone; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import com.google.devtools.build.lib.actions.Action; -import com.google.devtools.build.lib.actions.ActionContextProvider; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactResolver; import com.google.devtools.build.lib.actions.ExecutionStrategy; import com.google.devtools.build.lib.actions.Executor.ActionContext; import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.ExecutionOptions; import com.google.devtools.build.lib.exec.FileWriteStrategy; import com.google.devtools.build.lib.exec.StandaloneTestStrategy; 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 bde53f0a5e..b60f47aa1e 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 @@ -13,8 +13,8 @@ // limitations under the License. package com.google.devtools.build.lib.standalone; -import com.google.devtools.build.lib.actions.ExecutorBuilder; import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ExecutorBuilder; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.CommandEnvironment; diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextConsumer.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextConsumer.java index 91d278b174..5ca7aaa4d7 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextConsumer.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextConsumer.java @@ -17,9 +17,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap.Builder; 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; +import com.google.devtools.build.lib.exec.ActionContextConsumer; /** * {@link ActionContextConsumer} that requests the action contexts necessary for worker process 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 index e15af06b3e..8f2fda7acb 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java @@ -15,9 +15,9 @@ 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.ActionContextProvider; import com.google.devtools.build.lib.actions.Executor.ActionContext; import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.ExecutionOptions; import com.google.devtools.build.lib.rules.test.TestActionContext; import com.google.devtools.build.lib.runtime.CommandEnvironment; 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 1ec0122146..e575d8204b 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 @@ -15,12 +15,12 @@ package com.google.devtools.build.lib.worker; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.Subscribe; -import com.google.devtools.build.lib.actions.ExecutorBuilder; 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; 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.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; -- cgit v1.2.3