diff options
author | 2015-10-19 08:22:23 +0000 | |
---|---|---|
committer | 2015-10-19 13:43:01 +0000 | |
commit | b018ee34b3540ff7864c48091118696dc48b4b80 (patch) | |
tree | b8aad13ea740408f95ed92673270142847737e7b /src | |
parent | ea2cb007f3aec0b219fbc6395dd35bde9ece5afb (diff) |
Make bazel not require a tools/defaults/BUILD file.
--
MOS_MIGRATED_REVID=105734972
Diffstat (limited to 'src')
3 files changed, 34 insertions, 18 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 26e35b1388..d8e8230f99 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 @@ -412,25 +412,15 @@ public class PackageFunction implements SkyFunction { RootedPath buildFileRootedPath = RootedPath.toRootedPath(packageLookupValue.getRoot(), buildFileFragment); FileValue buildFileValue = null; - 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"); - Path buildFilePath = buildFileRootedPath.asPath(); - String replacementContents = null; - if (packageId.getPackageFragment().equals(DEFAULTS_PACKAGE_NAME) - && packageId.getRepository().isDefault()) { + + if (!isDefaultsPackage(packageId)) { + buildFileValue = getBuildFileValue(env, buildFileRootedPath); + if (buildFileValue == null) { + return null; + } + } else { replacementContents = PrecomputedValue.DEFAULTS_PACKAGE_CONTENTS.get(env); if (replacementContents == null) { return null; @@ -515,6 +505,24 @@ public class PackageFunction implements SkyFunction { return new PackageValue(pkg); } + private FileValue getBuildFileValue(Environment env, RootedPath buildFileRootedPath) { + 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; + } + Preconditions.checkState(buildFileValue.exists(), + "Package lookup succeeded but BUILD file doesn't exist"); + return buildFileValue; + } + @Nullable private SkylarkImportResult discoverSkylarkImports( Path buildFilePath, @@ -993,4 +1001,9 @@ public class PackageFunction implements SkyFunction { this.fileDependencies = fileDependencies; } } + + static boolean isDefaultsPackage(PackageIdentifier packageIdentifier) { + return packageIdentifier.getRepository().isDefault() + && packageIdentifier.getPackageFragment().equals(DEFAULTS_PACKAGE_NAME); + } } 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 b49742a3ac..903d99e687 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,10 @@ 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 (PackageFunction.isDefaultsPackage(packageKey)) { + 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 0cc8497d5d..0849ac1261 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 @@ -85,7 +85,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', ", |