Skip to content

Commit

Permalink
Delete Preprocessor.Factory.Supplier
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 152882585
  • Loading branch information
laurentlb authored and buchgr committed Apr 12, 2017
1 parent ec83f0d commit 2e1b904
Show file tree
Hide file tree
Showing 15 changed files with 10 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,6 @@
public interface Preprocessor {
/** Factory for {@link Preprocessor} instances. */
interface Factory {
/** Supplier for {@link Factory} instances. */
interface Supplier {
/**
* Returns a Preprocessor factory to use for getting Preprocessor instances.
*
* @param loc a package locator for preprocessors to look up other BUILD files
* @param outputBase allows non-hermetic access to the file system and output base; use with
* extreme caution
*/
Factory getFactory(CachingPackageLocator loc, Path outputBase);

/** Supplier that always returns {@code NullFactory.INSTANCE}. */
static class NullSupplier implements Supplier {

public static final NullSupplier INSTANCE = new NullSupplier();

private NullSupplier() {
}

@Override
public Factory getFactory(CachingPackageLocator loc, Path outputBase) {
return NullFactory.INSTANCE;
}
}
}

/**
* Returns whether this {@link Factory} is still suitable for providing {@link Preprocessor}s.
* If not, all previous preprocessing results should be assumed to be invalid and a new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction;
import com.google.devtools.build.lib.analysis.config.BinTools;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.skyframe.DiffAwareness;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.skyframe.PrecomputedValue.Injected;
Expand Down Expand Up @@ -51,7 +50,6 @@ public final class WorkspaceBuilder {
private final ImmutableList.Builder<DiffAwareness.Factory> diffAwarenessFactories =
ImmutableList.builder();
private Predicate<PathFragment> allowedMissingInputs;
private Preprocessor.Factory.Supplier preprocessorFactorySupplier;
// We use an immutable map builder for the nice side effect that it throws if a duplicate key
// is inserted.
private final ImmutableMap.Builder<SkyFunctionName, SkyFunction> skyFunctions =
Expand Down Expand Up @@ -79,9 +77,6 @@ BlazeWorkspace build(
if (allowedMissingInputs == null) {
allowedMissingInputs = Predicates.alwaysFalse();
}
if (preprocessorFactorySupplier == null) {
preprocessorFactorySupplier = Preprocessor.Factory.Supplier.NullSupplier.INSTANCE;
}

SkyframeExecutor skyframeExecutor = skyframeExecutorFactory.create(
packageFactory,
Expand All @@ -91,7 +86,6 @@ BlazeWorkspace build(
ruleClassProvider.getBuildInfoFactories(),
diffAwarenessFactories.build(),
allowedMissingInputs,
preprocessorFactorySupplier,
skyFunctions.build(),
precomputedValues.build(),
customDirtinessCheckers.build(),
Expand Down Expand Up @@ -150,23 +144,6 @@ public WorkspaceBuilder setAllowedMissingInputs(Predicate<PathFragment> allowedM
return this;
}

/**
* Sets a supplier that provides factories for the Preprocessor to apply. Only one factory per
* workspace is allowed.
*
* <p>The factory yielded by the supplier will be checked with
* {@link Preprocessor.Factory#isStillValid} at the beginning of each incremental build. This
* allows modules to have preprocessors customizable by flags.
*/
public WorkspaceBuilder setPreprocessorFactorySupplier(
Preprocessor.Factory.Supplier preprocessorFactorySupplier) {
Preconditions.checkState(this.preprocessorFactorySupplier == null,
"At most one module defines a preprocessor factory supplier. But found two: %s and %s",
this.preprocessorFactorySupplier, preprocessorFactorySupplier);
this.preprocessorFactorySupplier = Preconditions.checkNotNull(preprocessorFactorySupplier);
return this;
}

/** Add an "extra" SkyFunction for SkyValues. */
public WorkspaceBuilder addSkyFunction(SkyFunctionName name, SkyFunction skyFunction) {
Preconditions.checkNotNull(name);
Expand Down Expand Up @@ -207,4 +184,4 @@ public WorkspaceBuilder addCustomDirtinessChecker(
this.customDirtinessCheckers.add(Preconditions.checkNotNull(customDirtinessChecker));
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.profiler.AutoProfiler;
Expand Down Expand Up @@ -119,7 +118,6 @@ private SequencedSkyframeExecutor(
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
Predicate<PathFragment> allowedMissingInputs,
Preprocessor.Factory.Supplier preprocessorFactorySupplier,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
Expand All @@ -135,7 +133,6 @@ private SequencedSkyframeExecutor(
workspaceStatusActionFactory,
buildInfoFactories,
allowedMissingInputs,
preprocessorFactorySupplier,
extraSkyFunctions,
extraPrecomputedValues,
ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS,
Expand All @@ -155,7 +152,6 @@ public static SequencedSkyframeExecutor create(
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
Predicate<PathFragment> allowedMissingInputs,
Preprocessor.Factory.Supplier preprocessorFactorySupplier,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
Expand All @@ -170,7 +166,6 @@ public static SequencedSkyframeExecutor create(
buildInfoFactories,
diffAwarenessFactories,
allowedMissingInputs,
preprocessorFactorySupplier,
extraSkyFunctions,
extraPrecomputedValues,
customDirtinessCheckers,
Expand All @@ -188,7 +183,6 @@ private static SequencedSkyframeExecutor create(
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
Predicate<PathFragment> allowedMissingInputs,
Preprocessor.Factory.Supplier preprocessorFactorySupplier,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
Expand All @@ -206,7 +200,6 @@ private static SequencedSkyframeExecutor create(
buildInfoFactories,
diffAwarenessFactories,
allowedMissingInputs,
preprocessorFactorySupplier,
extraSkyFunctions,
extraPrecomputedValues,
customDirtinessCheckers,
Expand All @@ -219,14 +212,15 @@ private static SequencedSkyframeExecutor create(
}

@VisibleForTesting
public static SequencedSkyframeExecutor create(PackageFactory pkgFactory,
BlazeDirectories directories, BinTools binTools,
public static SequencedSkyframeExecutor create(
PackageFactory pkgFactory,
BlazeDirectories directories,
BinTools binTools,
WorkspaceStatusAction.Factory workspaceStatusActionFactory,
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
PathFragment blacklistedPackagePrefixesFile,
String productName,
Preprocessor.Factory.Supplier preprocessorFactorySupplier) {
String productName) {
return create(
pkgFactory,
directories,
Expand All @@ -235,7 +229,6 @@ public static SequencedSkyframeExecutor create(PackageFactory pkgFactory,
buildInfoFactories,
diffAwarenessFactories,
Predicates.<PathFragment>alwaysFalse(),
preprocessorFactorySupplier,
ImmutableMap.<SkyFunctionName, SkyFunction>of(),
ImmutableList.<PrecomputedValue.Injected>of(),
ImmutableList.<SkyValueDirtinessChecker>of(),
Expand Down
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.BinTools;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.skyframe.PackageLookupFunction.CrossRepositoryLabelViolationStrategy;
import com.google.devtools.build.lib.skyframe.PackageLookupValue.BuildFileName;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand All @@ -42,7 +41,6 @@ public SkyframeExecutor create(
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
Predicate<PathFragment> allowedMissingInputs,
Preprocessor.Factory.Supplier preprocessorFactorySupplier,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
Expand All @@ -55,7 +53,6 @@ public SkyframeExecutor create(
buildInfoFactories,
diffAwarenessFactories,
allowedMissingInputs,
preprocessorFactorySupplier,
extraSkyFunctions,
extraPrecomputedValues,
customDirtinessCheckers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.Package.Builder;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.packages.Preprocessor.AstAfterPreprocessing;
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.packages.RuleVisibility;
Expand Down Expand Up @@ -244,9 +243,6 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
protected boolean active = true;
private final SkyframePackageManager packageManager;

private final Preprocessor.Factory.Supplier preprocessorFactorySupplier;
private Preprocessor.Factory preprocessorFactory;

private final ResourceManager resourceManager;

/** Used to lock evaluator on legacy calls to get existing values. */
Expand Down Expand Up @@ -301,7 +297,6 @@ protected SkyframeExecutor(
Factory workspaceStatusActionFactory,
ImmutableList<BuildInfoFactory> buildInfoFactories,
Predicate<PathFragment> allowedMissingInputs,
Preprocessor.Factory.Supplier preprocessorFactorySupplier,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues,
ExternalFileAction externalFileAction,
Expand All @@ -323,7 +318,6 @@ protected SkyframeExecutor(
this.directories = Preconditions.checkNotNull(directories);
this.buildInfoFactories = buildInfoFactories;
this.allowedMissingInputs = allowedMissingInputs;
this.preprocessorFactorySupplier = preprocessorFactorySupplier;
this.extraSkyFunctions = extraSkyFunctions;
this.extraPrecomputedValues = extraPrecomputedValues;
this.externalFileAction = externalFileAction;
Expand Down Expand Up @@ -982,7 +976,6 @@ public void preparePackageLoading(
this.pkgFactory.setGlobbingThreads(packageCacheOptions.globbingThreads);
this.pkgFactory.setMaxDirectoriesToEagerlyVisitInGlobbing(
packageCacheOptions.maxDirectoriesToEagerlyVisitInGlobbing);
checkPreprocessorFactory();
emittedEventState.clear();

// If the PackageFunction was interrupted, there may be stale entries here.
Expand Down Expand Up @@ -1012,17 +1005,6 @@ private void setPackageLocator(PathPackageLocator pkgLocator) {
protected abstract void onNewPackageLocator(PathPackageLocator oldLocator,
PathPackageLocator pkgLocator);

private void checkPreprocessorFactory() {
if (preprocessorFactory == null) {
preprocessorFactory =
preprocessorFactorySupplier.getFactory(packageManager, directories.getOutputBase());
} else if (!preprocessorFactory.isStillValid()) {
preprocessorFactory =
preprocessorFactorySupplier.getFactory(packageManager, directories.getOutputBase());
invalidate(SkyFunctionName.functionIs(SkyFunctions.PACKAGE));
}
}

public SkyframeBuildView getSkyframeBuildView() {
return skyframeBuildView;
}
Expand Down
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.BinTools;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyFunction;
Expand All @@ -43,7 +42,6 @@ public interface SkyframeExecutorFactory {
* @param buildInfoFactories list of BuildInfoFactories
* @param diffAwarenessFactories
* @param allowedMissingInputs
* @param preprocessorFactorySupplier
* @param extraSkyFunctions
* @param extraPrecomputedValues
* @param customDirtinessCheckers
Expand All @@ -59,7 +57,6 @@ SkyframeExecutor create(
ImmutableList<BuildInfoFactory> buildInfoFactories,
Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories,
Predicate<PathFragment> allowedMissingInputs,
Preprocessor.Factory.Supplier preprocessorFactorySupplier,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.util.MockToolsConfig;
import com.google.devtools.build.lib.pkgcache.LoadingOptions;
Expand Down Expand Up @@ -175,7 +174,6 @@ protected void useRuleClassProvider(ConfiguredRuleClassProvider ruleClassProvide
ruleClassProvider.getBuildInfoFactories(),
ImmutableList.<DiffAwareness.Factory>of(),
Predicates.<PathFragment>alwaysFalse(),
Preprocessor.Factory.Supplier.NullSupplier.INSTANCE,
analysisMock.getSkyFunctions(),
getPrecomputedValues(),
ImmutableList.<SkyValueDirtinessChecker>of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
import com.google.devtools.build.lib.packages.OutputFile;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.packages.RawAttributeMapper;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.Target;
Expand Down Expand Up @@ -227,7 +226,6 @@ public final void initializeSkyframeExecutor() throws Exception {
ruleClassProvider.getBuildInfoFactories(),
ImmutableList.<DiffAwareness.Factory>of(),
Predicates.<PathFragment>alwaysFalse(),
getPreprocessorFactorySupplier(),
analysisMock.getSkyFunctions(),
getPrecomputedValues(),
ImmutableList.<SkyValueDirtinessChecker>of(),
Expand Down Expand Up @@ -276,10 +274,6 @@ protected ImmutableList<PrecomputedValue.Injected> getPrecomputedValues() {
return ImmutableList.of();
}

protected Preprocessor.Factory.Supplier getPreprocessorFactorySupplier() {
return Preprocessor.Factory.Supplier.NullSupplier.INSTANCE;
}

protected ResourceSet getStartingResources() {
// Effectively disable ResourceManager by default.
return ResourceSet.createWithRamCpuIo(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.packages.util.MockToolsConfig;
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
Expand Down Expand Up @@ -111,7 +110,6 @@ public final void initializeSkyframeExecutor() throws Exception {
ruleClassProvider.getBuildInfoFactories(),
ImmutableList.<DiffAwareness.Factory>of(),
Predicates.<PathFragment>alwaysFalse(),
Preprocessor.Factory.Supplier.NullSupplier.INSTANCE,
analysisMock.getSkyFunctions(),
ImmutableList.<PrecomputedValue.Injected>of(),
ImmutableList.<SkyValueDirtinessChecker>of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.devtools.build.lib.packages.NoSuchTargetException;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension;
import com.google.devtools.build.lib.packages.Preprocessor;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleVisibility;
import com.google.devtools.build.lib.packages.Target;
Expand Down Expand Up @@ -88,7 +87,7 @@ public final void initializeSkyframeExecutor() throws Exception {
loadingMock
.getPackageFactoryForTesting()
.create(ruleClassProvider, null, getEnvironmentExtensions(), scratch.getFileSystem());
skyframeExecutor = createSkyframeExecutor(getPreprocessorFactorySupplier());
skyframeExecutor = createSkyframeExecutor();
setUpSkyframe(parsePackageCacheOptions());
}

Expand All @@ -97,8 +96,7 @@ protected List<RuleDefinition> getExtraRules() {
return ImmutableList.of();
}

private SkyframeExecutor createSkyframeExecutor(
Preprocessor.Factory.Supplier preprocessorFactorySupplier) {
private SkyframeExecutor createSkyframeExecutor() {
SkyframeExecutor skyframeExecutor =
SequencedSkyframeExecutor.create(
packageFactory,
Expand All @@ -109,7 +107,6 @@ private SkyframeExecutor createSkyframeExecutor(
ruleClassProvider.getBuildInfoFactories(),
ImmutableList.<DiffAwareness.Factory>of(),
Predicates.<PathFragment>alwaysFalse(),
preprocessorFactorySupplier,
ImmutableMap.<SkyFunctionName, SkyFunction>of(),
ImmutableList.<PrecomputedValue.Injected>of(),
ImmutableList.<SkyValueDirtinessChecker>of(),
Expand All @@ -123,10 +120,6 @@ protected Iterable<EnvironmentExtension> getEnvironmentExtensions() {
return ImmutableList.<EnvironmentExtension>of();
}

protected Preprocessor.Factory.Supplier getPreprocessorFactorySupplier() {
return Preprocessor.Factory.Supplier.NullSupplier.INSTANCE;
}

protected void setUpSkyframe(RuleVisibility defaultVisibility, String defaultsPackageContents) {
PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
packageCacheOptions.defaultVisibility = defaultVisibility;
Expand Down
Loading

0 comments on commit 2e1b904

Please sign in to comment.