aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java69
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java1
3 files changed, 44 insertions, 31 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
index f6745d3e91..ddc14accb8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -95,8 +95,7 @@ public class PackageFunction implements SkyFunction {
// Not final only for testing.
@Nullable private SkylarkImportLookupFunction skylarkImportLookupFunctionForInlining;
- static final String DEFAULTS_PACKAGE_NAME = "tools/defaults";
- public static final String EXTERNAL_PACKAGE_NAME = "external";
+ static final PathFragment DEFAULTS_PACKAGE_NAME = new PathFragment("tools/defaults");
public PackageFunction(
PackageFactory packageFactory,
@@ -412,27 +411,33 @@ public class PackageFunction implements SkyFunction {
Transience.PERSISTENT);
}
+ boolean isDefaultsPackage = packageNameFragment.equals(DEFAULTS_PACKAGE_NAME)
+ && packageId.getRepository().isDefault();
+
PathFragment buildFileFragment = packageNameFragment.getChild("BUILD");
RootedPath buildFileRootedPath = RootedPath.toRootedPath(packageLookupValue.getRoot(),
buildFileFragment);
- FileValue buildFileValue;
- try {
- buildFileValue = (FileValue) env.getValueOrThrow(FileValue.key(buildFileRootedPath),
- IOException.class, FileSymlinkException.class,
- InconsistentFilesystemException.class);
- } catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
- throw new IllegalStateException("Package lookup succeeded but encountered error when "
- + "getting FileValue for BUILD file directly.", e);
- }
- if (buildFileValue == null) {
- return null;
+ FileValue buildFileValue = null;
+ if (!isDefaultsPackage) {
+ try {
+ buildFileValue = (FileValue) env.getValueOrThrow(FileValue.key(buildFileRootedPath),
+ IOException.class, FileSymlinkException.class,
+ InconsistentFilesystemException.class);
+ } catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
+ throw new IllegalStateException("Package lookup succeeded but encountered error when "
+ + "getting FileValue for BUILD file directly.", e);
+ }
+ if (buildFileValue == null) {
+ return null;
+ }
+ Preconditions.checkState(buildFileValue.exists(),
+ "Package lookup succeeded but BUILD file doesn't exist");
}
- Preconditions.checkState(buildFileValue.exists(),
- "Package lookup succeeded but BUILD file doesn't exist");
+
Path buildFilePath = buildFileRootedPath.asPath();
String replacementContents = null;
- if (packageName.equals(DEFAULTS_PACKAGE_NAME) && packageId.getRepository().isDefault()) {
+ if (isDefaultsPackage) {
replacementContents = PrecomputedValue.DEFAULTS_PACKAGE_CONTENTS.get(env);
if (replacementContents == null) {
return null;
@@ -460,22 +465,26 @@ public class PackageFunction implements SkyFunction {
List<Statement> preludeStatements = astLookupValue.getAST() == null
? ImmutableList.<Statement>of() : astLookupValue.getAST().getStatements();
- // Load the BUILD file AST and handle Skylark dependencies. This way BUILD files are
- // only loaded twice if there are unavailable Skylark or package dependencies or an
- // IOException occurs. Note that the BUILD files are still parsed two times.
ParserInputSource inputSource;
- try {
- if (showLoadingProgress.get() && packageFunctionCache.getIfPresent(packageId) == null) {
- // TODO(bazel-team): don't duplicate the loading message if there are unavailable
- // Skylark dependencies.
- env.getListener().handle(Event.progress("Loading package: " + packageName));
+ if (replacementContents != null) {
+ inputSource = ParserInputSource.create(replacementContents, buildFileFragment);
+ } else {
+ // Load the BUILD file AST and handle Skylark dependencies. This way BUILD files are
+ // only loaded twice if there are unavailable Skylark or package dependencies or an
+ // IOException occurs. Note that the BUILD files are still parsed two times.
+ try {
+ if (showLoadingProgress.get() && packageFunctionCache.getIfPresent(packageId) == null) {
+ // TODO(bazel-team): don't duplicate the loading message if there are unavailable
+ // Skylark dependencies.
+ env.getListener().handle(Event.progress("Loading package: " + packageName));
+ }
+ inputSource = ParserInputSource.create(buildFilePath, buildFileValue.getSize());
+ } catch (IOException e) {
+ env.getListener().handle(Event.error(Location.fromFile(buildFilePath), e.getMessage()));
+ // Note that we did this work, so we should conservatively report this error as transient.
+ throw new PackageFunctionException(new BuildFileContainsErrorsException(
+ packageId, e.getMessage()), Transience.TRANSIENT);
}
- inputSource = ParserInputSource.create(buildFilePath, buildFileValue.getSize());
- } catch (IOException e) {
- env.getListener().handle(Event.error(Location.fromFile(buildFilePath), e.getMessage()));
- // Note that we did this work, so we should conservatively report this error as transient.
- throw new PackageFunctionException(new BuildFileContainsErrorsException(
- packageId, e.getMessage()), Transience.TRANSIENT);
}
Package.LegacyBuilder legacyPkgBuilder =
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
index 5c612ca1b8..cd6578d281 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
@@ -51,6 +51,11 @@ public class PackageLookupFunction implements SkyFunction {
public SkyValue compute(SkyKey skyKey, Environment env) throws PackageLookupFunctionException {
PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
PackageIdentifier packageKey = (PackageIdentifier) skyKey.argument();
+ if (packageKey.getRepository().isDefault()
+ && packageKey.getPackageFragment().equals(PackageFunction.DEFAULTS_PACKAGE_NAME)) {
+ return PackageLookupValue.success(pkgLocator.getPathEntries().get(0));
+ }
+
if (!packageKey.getRepository().equals(PackageIdentifier.MAIN_REPOSITORY_NAME)
&& !packageKey.getRepository().isDefault()) {
return computeExternalPackageLookupValue(skyKey, env, packageKey);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index 88c019da89..811ac6374a 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -83,7 +83,6 @@ public class BazelAnalysisMock extends AnalysisMock {
}
config.overwrite("WORKSPACE", workspaceContents.toArray(new String[workspaceContents.size()]));
- config.create("tools/defaults/BUILD");
config.create("tools/jdk/BUILD",
"package(default_visibility=['//visibility:public'])",
"java_toolchain(name = 'toolchain', encoding = 'UTF-8', source_version = '8', ",