Skip to content

Commit

Permalink
Create instances of SequencedSkyframeExecutor through Builder.
Browse files Browse the repository at this point in the history
Allows addition of the new arguments to SequencedSkyframeExecutor constructor without the need to modify all the places, where SequencedSkyframeExecutor is constructed (if the default value can be provided for the new argument in Builder).

PiperOrigin-RevId: 242734996
  • Loading branch information
Googler authored and copybara-github committed Apr 9, 2019
1 parent ecf2477 commit 7b2cb35
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ private BazelSkyframeExecutorConstants() {
public static final ActionOnIOExceptionReadingBuildFile
ACTION_ON_IO_EXCEPTION_READING_BUILD_FILE =
ActionOnIOExceptionReadingBuildFile.UseOriginalIOException.INSTANCE;

public static SequencedSkyframeExecutor.Builder newBazelSkyframeExecutorBuilder() {
return SequencedSkyframeExecutor.builder()
.setHardcodedBlacklistedPackagePrefixes(HARDCODED_BLACKLISTED_PACKAGE_PREFIXES)
.setAdditionalBlacklistedPackagePrefixesFile(ADDITIONAL_BLACKLISTED_PACKAGE_PREFIXES_FILE)
.setActionOnIOExceptionReadingBuildFile(ACTION_ON_IO_EXCEPTION_READING_BUILD_FILE)
.setCrossRepositoryLabelViolationStrategy(CROSS_REPOSITORY_LABEL_VIOLATION_STRATEGY)
.setBuildFilesByPriority(BUILD_FILES_BY_PRIORITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,84 +187,6 @@ private SequencedSkyframeExecutor(
this.customDirtinessCheckers = customDirtinessCheckers;
}

public static SequencedSkyframeExecutor create(
PackageFactory pkgFactory,
FileSystem fileSystem,
BlazeDirectories directories,
ActionKeyContext actionKeyContext,
Factory workspaceStatusActionFactory,
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes,
PathFragment additionalBlacklistedPackagePrefixesFile,
CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy,
List<BuildFileName> buildFilesByPriority,
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile,
BuildOptions defaultBuildOptions) {
return create(
pkgFactory,
fileSystem,
directories,
actionKeyContext,
workspaceStatusActionFactory,
buildInfoFactories,
diffAwarenessFactories,
extraSkyFunctions,
customDirtinessCheckers,
hardcodedBlacklistedPackagePrefixes,
additionalBlacklistedPackagePrefixesFile,
crossRepositoryLabelViolationStrategy,
buildFilesByPriority,
actionOnIOExceptionReadingBuildFile,
defaultBuildOptions,
new MutableArtifactFactorySupplier(),
skyframeExecutor -> {});
}

public static SequencedSkyframeExecutor create(
PackageFactory pkgFactory,
FileSystem fileSystem,
BlazeDirectories directories,
ActionKeyContext actionKeyContext,
Factory workspaceStatusActionFactory,
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes,
PathFragment additionalBlacklistedPackagePrefixesFile,
CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy,
List<BuildFileName> buildFilesByPriority,
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile,
BuildOptions defaultBuildOptions,
MutableArtifactFactorySupplier mutableArtifactFactorySupplier,
Consumer<SkyframeExecutor> skyframeExecutorConsumerOnInit) {
SequencedSkyframeExecutor skyframeExecutor =
new SequencedSkyframeExecutor(
skyframeExecutorConsumerOnInit,
InMemoryMemoizingEvaluator.SUPPLIER,
pkgFactory,
fileSystem,
directories,
actionKeyContext,
workspaceStatusActionFactory,
buildInfoFactories,
diffAwarenessFactories,
extraSkyFunctions,
customDirtinessCheckers,
hardcodedBlacklistedPackagePrefixes,
additionalBlacklistedPackagePrefixesFile,
crossRepositoryLabelViolationStrategy,
buildFilesByPriority,
actionOnIOExceptionReadingBuildFile,
defaultBuildOptions,
mutableArtifactFactorySupplier);
skyframeExecutor.init();
return skyframeExecutor;
}

@Override
protected BuildDriver getBuildDriver() {
return new SequentialBuildDriver(memoizingEvaluator);
Expand Down Expand Up @@ -876,4 +798,178 @@ public void dumpPackages(PrintStream out) {
pkg.dump(out);
}
}

public static Builder builder() {
return new Builder();
}

/**
* Builder class for {@link SequencedSkyframeExecutor}.
*
* <p>Allows addition of the new arguments to {@link SequencedSkyframeExecutor} constructor
* without the need to modify all the places, where {@link SequencedSkyframeExecutor} is
* constructed (if the default value can be provided for the new argument in Builder).
*/
public static final class Builder {
protected PackageFactory pkgFactory;
protected FileSystem fileSystem;
protected BlazeDirectories directories;
protected ActionKeyContext actionKeyContext;
protected ImmutableList<BuildInfoFactory> buildInfoFactories;
protected BuildOptions defaultBuildOptions;

private ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes;
private PathFragment additionalBlacklistedPackagePrefixesFile;
private CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy;
private List<BuildFileName> buildFilesByPriority;
private ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile;

// Fields with default values.
private ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions = ImmutableMap.of();
private Factory workspaceStatusActionFactory;
private Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories = ImmutableList.of();
private Iterable<SkyValueDirtinessChecker> customDirtinessCheckers = ImmutableList.of();
private MutableArtifactFactorySupplier mutableArtifactFactorySupplier =
new MutableArtifactFactorySupplier();
private Consumer<SkyframeExecutor> skyframeExecutorConsumerOnInit = skyframeExecutor -> {};

private Builder() {}

public SequencedSkyframeExecutor build() {
// Check that the values were explicitly set.
Preconditions.checkNotNull(pkgFactory);
Preconditions.checkNotNull(fileSystem);
Preconditions.checkNotNull(directories);
Preconditions.checkNotNull(actionKeyContext);
Preconditions.checkNotNull(buildInfoFactories);
Preconditions.checkNotNull(defaultBuildOptions);
Preconditions.checkNotNull(hardcodedBlacklistedPackagePrefixes);
Preconditions.checkNotNull(additionalBlacklistedPackagePrefixesFile);
Preconditions.checkNotNull(crossRepositoryLabelViolationStrategy);
Preconditions.checkNotNull(buildFilesByPriority);
Preconditions.checkNotNull(actionOnIOExceptionReadingBuildFile);

SequencedSkyframeExecutor skyframeExecutor =
new SequencedSkyframeExecutor(
skyframeExecutorConsumerOnInit,
InMemoryMemoizingEvaluator.SUPPLIER,
pkgFactory,
fileSystem,
directories,
actionKeyContext,
workspaceStatusActionFactory,
buildInfoFactories,
diffAwarenessFactories,
extraSkyFunctions,
customDirtinessCheckers,
hardcodedBlacklistedPackagePrefixes,
additionalBlacklistedPackagePrefixesFile,
crossRepositoryLabelViolationStrategy,
buildFilesByPriority,
actionOnIOExceptionReadingBuildFile,
defaultBuildOptions,
mutableArtifactFactorySupplier);
skyframeExecutor.init();
return skyframeExecutor;
}

public Builder modify(Consumer<Builder> consumer) {
consumer.accept(this);
return this;
}

public Builder setPkgFactory(PackageFactory pkgFactory) {
this.pkgFactory = pkgFactory;
return this;
}

public Builder setFileSystem(FileSystem fileSystem) {
this.fileSystem = fileSystem;
return this;
}

public Builder setDirectories(BlazeDirectories directories) {
this.directories = directories;
return this;
}

public Builder setActionKeyContext(ActionKeyContext actionKeyContext) {
this.actionKeyContext = actionKeyContext;
return this;
}

public Builder setBuildInfoFactories(ImmutableList<BuildInfoFactory> buildInfoFactories) {
this.buildInfoFactories = buildInfoFactories;
return this;
}

public Builder setDefaultBuildOptions(BuildOptions defaultBuildOptions) {
this.defaultBuildOptions = defaultBuildOptions;
return this;
}

public Builder setExtraSkyFunctions(
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions) {
this.extraSkyFunctions = extraSkyFunctions;
return this;
}

public Builder setWorkspaceStatusActionFactory(@Nullable Factory workspaceStatusActionFactory) {
this.workspaceStatusActionFactory = workspaceStatusActionFactory;
return this;
}

public Builder setDiffAwarenessFactories(
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories) {
this.diffAwarenessFactories = diffAwarenessFactories;
return this;
}

public Builder setCustomDirtinessCheckers(
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers) {
this.customDirtinessCheckers = customDirtinessCheckers;
return this;
}

public Builder setHardcodedBlacklistedPackagePrefixes(
ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes) {
this.hardcodedBlacklistedPackagePrefixes = hardcodedBlacklistedPackagePrefixes;
return this;
}

public Builder setAdditionalBlacklistedPackagePrefixesFile(
PathFragment additionalBlacklistedPackagePrefixesFile) {
this.additionalBlacklistedPackagePrefixesFile = additionalBlacklistedPackagePrefixesFile;
return this;
}

public Builder setCrossRepositoryLabelViolationStrategy(
CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy) {
this.crossRepositoryLabelViolationStrategy = crossRepositoryLabelViolationStrategy;
return this;
}

public Builder setBuildFilesByPriority(List<BuildFileName> buildFilesByPriority) {
this.buildFilesByPriority = buildFilesByPriority;
return this;
}

public Builder setActionOnIOExceptionReadingBuildFile(
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile) {
this.actionOnIOExceptionReadingBuildFile = actionOnIOExceptionReadingBuildFile;
return this;
}

public Builder setMutableArtifactFactorySupplier(
MutableArtifactFactorySupplier mutableArtifactFactorySupplier) {
this.mutableArtifactFactorySupplier = mutableArtifactFactorySupplier;
return this;
}

public Builder setSkyframeExecutorConsumerOnInit(
Consumer<SkyframeExecutor> skyframeExecutorConsumerOnInit) {
this.skyframeExecutorConsumerOnInit = skyframeExecutorConsumerOnInit;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor.MutableArtifactFactorySupplier;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionName;
Expand All @@ -48,23 +47,17 @@ public SkyframeExecutor create(
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers) {
return SequencedSkyframeExecutor.create(
pkgFactory,
fileSystem,
directories,
actionKeyContext,
workspaceStatusActionFactory,
buildInfoFactories,
diffAwarenessFactories,
extraSkyFunctions,
customDirtinessCheckers,
BazelSkyframeExecutorConstants.HARDCODED_BLACKLISTED_PACKAGE_PREFIXES,
BazelSkyframeExecutorConstants.ADDITIONAL_BLACKLISTED_PACKAGE_PREFIXES_FILE,
BazelSkyframeExecutorConstants.CROSS_REPOSITORY_LABEL_VIOLATION_STRATEGY,
BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY,
BazelSkyframeExecutorConstants.ACTION_ON_IO_EXCEPTION_READING_BUILD_FILE,
defaultBuildOptions,
new MutableArtifactFactorySupplier(),
skyframeExecutor -> {});
return BazelSkyframeExecutorConstants.newBazelSkyframeExecutorBuilder()
.setPkgFactory(pkgFactory)
.setFileSystem(fileSystem)
.setDirectories(directories)
.setActionKeyContext(actionKeyContext)
.setBuildInfoFactories(buildInfoFactories)
.setDefaultBuildOptions(defaultBuildOptions)
.setWorkspaceStatusActionFactory(workspaceStatusActionFactory)
.setDiffAwarenessFactories(diffAwarenessFactories)
.setExtraSkyFunctions(extraSkyFunctions)
.setCustomDirtinessCheckers(customDirtinessCheckers)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.skyframe.SequencedSkyframeExecutor;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
import com.google.devtools.build.lib.skyframe.TargetPatternPhaseValue;
import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils;
Expand Down Expand Up @@ -194,22 +193,17 @@ public final void createMocks() throws Exception {

protected SkyframeExecutor createSkyframeExecutor(
PackageFactory pkgFactory, ImmutableList<BuildInfoFactory> buildInfoFactories) {
return SequencedSkyframeExecutor.create(
pkgFactory,
fileSystem,
directories,
actionKeyContext,
workspaceStatusActionFactory,
buildInfoFactories,
ImmutableList.of(),
analysisMock.getSkyFunctions(directories),
ImmutableList.of(),
BazelSkyframeExecutorConstants.HARDCODED_BLACKLISTED_PACKAGE_PREFIXES,
BazelSkyframeExecutorConstants.ADDITIONAL_BLACKLISTED_PACKAGE_PREFIXES_FILE,
BazelSkyframeExecutorConstants.CROSS_REPOSITORY_LABEL_VIOLATION_STRATEGY,
BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY,
BazelSkyframeExecutorConstants.ACTION_ON_IO_EXCEPTION_READING_BUILD_FILE,
DefaultBuildOptionsForTesting.getDefaultBuildOptionsForTest(ruleClassProvider));
return BazelSkyframeExecutorConstants.newBazelSkyframeExecutorBuilder()
.setPkgFactory(pkgFactory)
.setFileSystem(fileSystem)
.setDirectories(directories)
.setActionKeyContext(actionKeyContext)
.setBuildInfoFactories(buildInfoFactories)
.setDefaultBuildOptions(
DefaultBuildOptionsForTesting.getDefaultBuildOptionsForTest(ruleClassProvider))
.setWorkspaceStatusActionFactory(workspaceStatusActionFactory)
.setExtraSkyFunctions(analysisMock.getSkyFunctions(directories))
.build();
}

/**
Expand Down
Loading

0 comments on commit 7b2cb35

Please sign in to comment.