Skip to content

Commit

Permalink
Move createActionCache to ExecutorBuilder.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=137936478
  • Loading branch information
ulfjack authored and laszlocsomor committed Nov 2, 2016
1 parent 247ce2c commit 1ac1b99
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

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,
Expand All @@ -25,6 +27,7 @@
public class ExecutorBuilder {
private final List<ActionContextProvider> actionContextProviders = new ArrayList<>();
private final List<ActionContextConsumer> 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.
Expand All @@ -36,6 +39,11 @@ public ImmutableList<ActionContextConsumer> getActionContextConsumers() {
return ImmutableList.copyOf(actionContextConsumers);
}

@Nullable
public ActionInputFileCache getActionInputFileCache() {
return cache;
}

/**
* Adds the specified action context providers to the executor.
*/
Expand All @@ -60,5 +68,14 @@ public ExecutorBuilder addActionContextConsumer(ActionContextConsumer 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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.LoggingUtil;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -170,7 +169,7 @@ private String getUserFriendlyName(Class<? extends ActionContext> context) {
private final BlazeRuntime runtime;
private final BuildRequest request;
private BlazeExecutor executor;
private ActionInputFileCache fileCache;
private final ActionInputFileCache fileCache;
private final ImmutableList<ActionContextProvider> actionContextProviders;

private Map<String, SpawnActionContext> spawnStrategyMap =
Expand Down Expand Up @@ -215,6 +214,16 @@ public Multimap<Class<? extends ActionContext>, String> getActionContexts() {
}
});

ActionInputFileCache cache = builder.getActionInputFileCache();
if (cache == null) {
// Unfortunately, the exec root cache is not shared with caches in the remote execution
// client.
cache =
new SingleBuildFileCache(
env.getExecRoot().getPathString(), env.getDirectories().getFileSystem());
}
this.fileCache = cache;

this.actionContextProviders = builder.getActionContextProviders();
StrategyConverter strategyConverter = new StrategyConverter(actionContextProviders);

Expand Down Expand Up @@ -350,8 +359,7 @@ void executeBuild(UUID buildId, AnalysisResult analysisResult,
ActionCache actionCache = getActionCache();
SkyframeExecutor skyframeExecutor = env.getSkyframeExecutor();
Builder builder = createBuilder(
request, actionCache, skyframeExecutor, modifiedOutputFiles,
analysisResult.getWorkspaceName());
request, actionCache, skyframeExecutor, modifiedOutputFiles);

//
// Execution proper. All statements below are logically nested in
Expand Down Expand Up @@ -638,8 +646,7 @@ private ActionCache getActionCache() throws LocalEnvironmentException {
private Builder createBuilder(BuildRequest request,
ActionCache actionCache,
SkyframeExecutor skyframeExecutor,
ModifiedFileSet modifiedOutputFiles,
String workspaceName) {
ModifiedFileSet modifiedOutputFiles) {
BuildRequest.BuildRequestOptions options = request.getBuildOptions();
boolean verboseExplanations = options.verboseExplanations;
boolean keepGoing = request.getViewOptions().keepGoing;
Expand All @@ -652,9 +659,6 @@ private Builder createBuilder(BuildRequest request,
Preconditions.checkState(options.jobs >= -1);
int actualJobs = options.jobs == 0 ? 1 : options.jobs; // Treat 0 jobs as a single task.

// Unfortunately, the exec root cache is not shared with caches in the remote execution
// client.
fileCache = createBuildSingleFileCache(env.getDirectories().getExecRoot(workspaceName));
skyframeExecutor.setActionOutputRoot(actionOutputRoot);
ArtifactFactory artifactFactory = env.getSkyframeBuildView().getArtifactFactory();
return new SkyframeBuilder(skyframeExecutor,
Expand Down Expand Up @@ -707,25 +711,6 @@ private void saveCaches(ActionCache actionCache) {
actionCacheSaveTimeInMs, actionCacheSizeInBytes));
}

private ActionInputFileCache createBuildSingleFileCache(Path execRoot) {
String cwd = execRoot.getPathString();
FileSystem fs = env.getDirectories().getFileSystem();

ActionInputFileCache cache = null;
for (BlazeModule module : runtime.getBlazeModules()) {
ActionInputFileCache pluggable = module.createActionInputCache(cwd, fs);
if (pluggable != null) {
Preconditions.checkState(cache == null);
cache = pluggable;
}
}

if (cache == null) {
cache = new SingleBuildFileCache(cwd, fs);
}
return cache;
}

private Reporter getReporter() {
return env.getReporter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.google.devtools.build.lib.runtime;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.ActionInputFileCache;
import com.google.devtools.build.lib.actions.ExecutorBuilder;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
Expand Down Expand Up @@ -254,14 +253,6 @@ public void blazeShutdownOnCrash() {}
public void checkEnvironment(CommandEnvironment env) {
}

/**
* Optionally specializes the cache that ensures source files are looked at just once during
* a build. Only one module may do so.
*/
public ActionInputFileCache createActionInputCache(String cwd, FileSystem fs) {
return null;
}

/**
* Returns the extensions this module contributes to the global namespace of the BUILD language.
*/
Expand Down

0 comments on commit 1ac1b99

Please sign in to comment.