aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar nharmata <nharmata@google.com>2017-11-28 08:25:33 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-11-28 08:26:51 -0800
commitb64119807b014d9f3b99fb8a02e22daf1a8299b6 (patch)
tree1d0300023d6786aa6b8e7a294db34b54962b56d8 /src/main/java/com/google/devtools
parentc478aea4c872b7ce3395746fd86168376f909284 (diff)
Change BlacklistedPackagesPrefixesFunction to take a pair of a hardcoded set of directories and a file path containing more directories to blacklist. The current usage of PrecomputedValue#BLACKLISTED_PACKAGE_PREFIXES_FILE is overly general and is only meaningfully used by unit tests; in practice, the blacklist file path can never change over the lifetime of the Bazel server. Perform a minor simplifying refactor as a result of this.
RELNOTES: None. PiperOrigin-RevId: 177164057
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/BazelSkyframeExecutorConstants.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java71
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java6
7 files changed, 73 insertions, 56 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BazelSkyframeExecutorConstants.java b/src/main/java/com/google/devtools/build/lib/skyframe/BazelSkyframeExecutorConstants.java
index 6b892a8319..5d4d272eb9 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BazelSkyframeExecutorConstants.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BazelSkyframeExecutorConstants.java
@@ -14,15 +14,23 @@
package com.google.devtools.build.lib.skyframe;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.skyframe.PackageFunction.ActionOnIOExceptionReadingBuildFile;
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;
/** Hardcoded constants describing bazel-on-skyframe behavior. */
public class BazelSkyframeExecutorConstants {
private BazelSkyframeExecutorConstants() {
}
+ public static final ImmutableSet<PathFragment> HARDCODED_BLACKLISTED_PACKAGE_PREFIXES =
+ ImmutableSet.of();
+
+ public static final PathFragment ADDITIONAL_BLACKLISTED_PACKAGE_PREFIXES_FILE =
+ PathFragment.EMPTY_FRAGMENT;
+
public static final CrossRepositoryLabelViolationStrategy
CROSS_REPOSITORY_LABEL_VIOLATION_STRATEGY = CrossRepositoryLabelViolationStrategy.ERROR;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java
index a3c6768c96..02c9ae824d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java
@@ -32,50 +32,63 @@ import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
/**
- * A function that retrieves a set of blacklisted package pattern prefixes from the file given by
- * PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.
+ * A function that returns the union of a set of hardcoded blacklisted package prefixes and the
+ * contents of a hardcoded filepath whose contents is a blacklisted package prefix on each line.
*/
public class BlacklistedPackagePrefixesFunction implements SkyFunction {
+ private ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes;
+ private PathFragment additionalBlacklistedPackagePrefixesFile;
+
+ public BlacklistedPackagePrefixesFunction(
+ ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes,
+ PathFragment additionalBlacklistedPackagePrefixesFile) {
+ this.hardcodedBlacklistedPackagePrefixes = hardcodedBlacklistedPackagePrefixes;
+ this.additionalBlacklistedPackagePrefixesFile = additionalBlacklistedPackagePrefixesFile;
+ }
+
@Nullable
@Override
public SkyValue compute(SkyKey key, Environment env)
throws SkyFunctionException, InterruptedException {
- PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
- PathFragment patternsFile = PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.get(env);
- if (env.valuesMissing()) {
- return null;
- }
+ ImmutableSet.Builder<PathFragment> blacklistedPackagePrefixesBuilder = ImmutableSet.builder();
- if (patternsFile.equals(PathFragment.EMPTY_FRAGMENT)) {
- return new BlacklistedPackagePrefixesValue(ImmutableSet.<PathFragment>of());
- }
+ blacklistedPackagePrefixesBuilder.addAll(hardcodedBlacklistedPackagePrefixes);
- for (Path packagePathEntry : pkgLocator.getPathEntries()) {
- RootedPath rootedPatternFile = RootedPath.toRootedPath(packagePathEntry, patternsFile);
- FileValue patternFileValue = (FileValue) env.getValue(FileValue.key(rootedPatternFile));
- if (patternFileValue == null) {
+ if (!additionalBlacklistedPackagePrefixesFile.equals(PathFragment.EMPTY_FRAGMENT)) {
+ PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
+ if (env.valuesMissing()) {
return null;
}
- if (patternFileValue.isFile()) {
- try {
- try (InputStreamReader reader =
- new InputStreamReader(rootedPatternFile.asPath().getInputStream(),
- StandardCharsets.UTF_8)) {
- return new BlacklistedPackagePrefixesValue(
- CharStreams.readLines(reader, new PathFragmentLineProcessor()));
+
+ for (Path packagePathEntry : pkgLocator.getPathEntries()) {
+ RootedPath rootedPatternFile =
+ RootedPath.toRootedPath(packagePathEntry, additionalBlacklistedPackagePrefixesFile);
+ FileValue patternFileValue = (FileValue) env.getValue(FileValue.key(rootedPatternFile));
+ if (patternFileValue == null) {
+ return null;
+ }
+ if (patternFileValue.isFile()) {
+ try {
+ try (InputStreamReader reader =
+ new InputStreamReader(rootedPatternFile.asPath().getInputStream(),
+ StandardCharsets.UTF_8)) {
+ blacklistedPackagePrefixesBuilder.addAll(
+ CharStreams.readLines(reader, new PathFragmentLineProcessor()));
+ break;
+ }
+ } catch (IOException e) {
+ String errorMessage = e.getMessage() != null
+ ? "error '" + e.getMessage() + "'" : "an error";
+ throw new BlacklistedPatternsFunctionException(
+ new InconsistentFilesystemException(
+ rootedPatternFile.asPath() + " is not readable because: " + errorMessage
+ + ". Was it modified mid-build?"));
}
- } catch (IOException e) {
- String errorMessage = e.getMessage() != null
- ? "error '" + e.getMessage() + "'" : "an error";
- throw new BlacklistedPatternsFunctionException(
- new InconsistentFilesystemException(
- rootedPatternFile.asPath() + " is not readable because: " + errorMessage
- + ". Was it modified mid-build?"));
}
}
}
- return new BlacklistedPackagePrefixesValue(ImmutableSet.<PathFragment>of());
+ return new BlacklistedPackagePrefixesValue(blacklistedPackagePrefixesBuilder.build());
}
private static final class PathFragmentLineProcessor
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
index 0d21adc540..8f5277a98a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
@@ -26,7 +26,6 @@ import com.google.devtools.build.lib.packages.RuleVisibility;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException;
import com.google.devtools.build.lib.syntax.SkylarkSemantics;
-import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.Injectable;
import com.google.devtools.build.skyframe.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyFunction;
@@ -78,10 +77,6 @@ public final class PrecomputedValue implements SkyValue {
public static final Precomputed<String> DEFAULTS_PACKAGE_CONTENTS =
new Precomputed<>(LegacySkyKey.create(SkyFunctions.PRECOMPUTED, "default_pkg"));
- public static final Precomputed<PathFragment> BLACKLISTED_PACKAGE_PREFIXES_FILE =
- new Precomputed<>(
- LegacySkyKey.create(SkyFunctions.PRECOMPUTED, "blacklisted_package_prefixes_file"));
-
public static final Precomputed<RuleVisibility> DEFAULT_VISIBILITY =
new Precomputed<>(LegacySkyKey.create(SkyFunctions.PRECOMPUTED, "default_visibility"));
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
index 5dac255451..8f8a0c8144 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
@@ -139,7 +139,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
Predicate<PathFragment> allowedMissingInputs,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
- PathFragment blacklistedPackagePrefixesFile,
+ ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes,
+ PathFragment additionalBlacklistedPackagePrefixesFile,
CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy,
List<BuildFileName> buildFilesByPriority,
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile) {
@@ -153,7 +154,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
allowedMissingInputs,
extraSkyFunctions,
ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS,
- blacklistedPackagePrefixesFile,
+ hardcodedBlacklistedPackagePrefixes,
+ additionalBlacklistedPackagePrefixesFile,
crossRepositoryLabelViolationStrategy,
buildFilesByPriority,
actionOnIOExceptionReadingBuildFile);
@@ -171,7 +173,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
Predicate<PathFragment> allowedMissingInputs,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
Iterable<SkyValueDirtinessChecker> customDirtinessCheckers,
- PathFragment blacklistedPackagePrefixesFile,
+ ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes,
+ PathFragment additionalBlacklistedPackagePrefixesFile,
CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy,
List<BuildFileName> buildFilesByPriority,
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile) {
@@ -187,7 +190,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
allowedMissingInputs,
extraSkyFunctions,
customDirtinessCheckers,
- blacklistedPackagePrefixesFile,
+ hardcodedBlacklistedPackagePrefixes,
+ additionalBlacklistedPackagePrefixesFile,
crossRepositoryLabelViolationStrategy,
buildFilesByPriority,
actionOnIOExceptionReadingBuildFile);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java
index 0b645fb34b..a6cd8115ea 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java
@@ -51,7 +51,8 @@ public class SequencedSkyframeExecutorFactory implements SkyframeExecutorFactory
allowedMissingInputs,
extraSkyFunctions,
customDirtinessCheckers,
- PathFragment.EMPTY_FRAGMENT,
+ 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);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index ec365660ce..47c091bd4d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -274,7 +274,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
private MutableSupplier<ImmutableList<ConfigurationFragmentFactory>> configurationFragments =
new MutableSupplier<>();
- private final PathFragment blacklistedPackagePrefixesFile;
+ private final ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes;
+ private final PathFragment additionalBlacklistedPackagePrefixesFile;
private final RuleClassProvider ruleClassProvider;
@@ -299,7 +300,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
Predicate<PathFragment> allowedMissingInputs,
ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions,
ExternalFileAction externalFileAction,
- PathFragment blacklistedPackagePrefixesFile,
+ ImmutableSet<PathFragment> hardcodedBlacklistedPackagePrefixes,
+ PathFragment additionalBlacklistedPackagePrefixesFile,
CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy,
List<BuildFileName> buildFilesByPriority,
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile) {
@@ -324,7 +326,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
this.allowedMissingInputs = allowedMissingInputs;
this.extraSkyFunctions = extraSkyFunctions;
this.externalFileAction = externalFileAction;
- this.blacklistedPackagePrefixesFile = blacklistedPackagePrefixesFile;
+ this.hardcodedBlacklistedPackagePrefixes = hardcodedBlacklistedPackagePrefixes;
+ this.additionalBlacklistedPackagePrefixesFile = additionalBlacklistedPackagePrefixesFile;
this.ruleClassProvider = pkgFactory.getRuleClassProvider();
this.skyframeBuildView = new SkyframeBuildView(
@@ -383,7 +386,9 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
map.put(
SkyFunctions.COLLECT_PACKAGES_UNDER_DIRECTORY,
new CollectPackagesUnderDirectoryFunction(directories));
- map.put(SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES, new BlacklistedPackagePrefixesFunction());
+ map.put(SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES,
+ new BlacklistedPackagePrefixesFunction(
+ hardcodedBlacklistedPackagePrefixes, additionalBlacklistedPackagePrefixesFile));
map.put(SkyFunctions.TESTS_IN_SUITE, new TestsInSuiteFunction());
map.put(SkyFunctions.TEST_SUITE_EXPANSION, new TestSuiteExpansionFunction());
map.put(SkyFunctions.TARGET_PATTERN_PHASE, new TargetPatternPhaseFunction());
@@ -573,11 +578,6 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
}
}
- @VisibleForTesting
- public PathFragment getBlacklistedPackagePrefixesFile() {
- return blacklistedPackagePrefixesFile;
- }
-
class BuildViewProvider {
/**
* Returns the current {@link SkyframeBuildView} instance.
@@ -991,11 +991,6 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
@VisibleForTesting // productionVisibility = Visibility.PRIVATE
public abstract void setDeletedPackages(Iterable<PackageIdentifier> pkgs);
- @VisibleForTesting
- public final void setBlacklistedPackagePrefixesFile(PathFragment blacklistedPkgFile) {
- PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.set(injectable(), blacklistedPkgFile);
- }
-
/**
* Prepares the evaluator for loading.
*
@@ -1019,7 +1014,6 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
setCommandId(commandId);
PrecomputedValue.ACTION_ENV.set(injectable(), actionEnv);
this.clientEnv.set(clientEnv);
- setBlacklistedPackagePrefixesFile(getBlacklistedPackagePrefixesFile());
setShowLoadingProgress(packageCacheOptions.showLoadingProgress);
setDefaultVisibility(packageCacheOptions.defaultVisibility);
setSkylarkSemantics(skylarkSemanticsOptions);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
index ec0769bb40..fb00cf11c2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
@@ -267,7 +267,6 @@ public abstract class AbstractPackageLoader implements PackageLoader {
PrecomputedValue.DEFAULT_VISIBILITY.set(injectable, ConstantRuleVisibility.PRIVATE);
PrecomputedValue.SKYLARK_SEMANTICS.set(injectable, skylarkSemantics);
PrecomputedValue.DEFAULTS_PACKAGE_CONTENTS.set(injectable, defaultsPackageContents);
- PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.set(injectable, PathFragment.EMPTY_FRAGMENT);
return new ImmutableDiff(ImmutableList.<SkyKey>of(), valuesToInject);
}
@@ -375,7 +374,10 @@ public abstract class AbstractPackageLoader implements PackageLoader {
/* deletedPackages= */ new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()),
getCrossRepositoryLabelViolationStrategy(),
getBuildFilesByPriority()))
- .put(SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES, new BlacklistedPackagePrefixesFunction())
+ .put(SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES,
+ new BlacklistedPackagePrefixesFunction(
+ /*hardcodedBlacklistedPackagePrefixes=*/ ImmutableSet.of(),
+ /*additionalBlacklistedPackagePrefixesFile=*/ PathFragment.EMPTY_FRAGMENT))
.put(SkyFunctions.CONTAINING_PACKAGE_LOOKUP, new ContainingPackageLookupFunction())
.put(SkyFunctions.AST_FILE_LOOKUP, new ASTFileLookupFunction(ruleClassProvider))
.put(