use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.
the class FileFunctionTest method makeDriver.
private SequentialBuildDriver makeDriver(ExternalFileAction externalFileAction) {
AtomicReference<PathPackageLocator> pkgLocatorRef = new AtomicReference<>(pkgLocator);
BlazeDirectories directories = new BlazeDirectories(pkgRoot, outputBase, pkgRoot, TestConstants.PRODUCT_NAME);
ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocatorRef, externalFileAction, directories);
differencer = new RecordingDifferencer();
MemoizingEvaluator evaluator = new InMemoryMemoizingEvaluator(ImmutableMap.<SkyFunctionName, SkyFunction>builder().put(SkyFunctions.FILE_STATE, new FileStateFunction(new AtomicReference<TimestampGranularityMonitor>(), externalFilesHelper)).put(SkyFunctions.FILE_SYMLINK_CYCLE_UNIQUENESS, new FileSymlinkCycleUniquenessFunction()).put(SkyFunctions.FILE_SYMLINK_INFINITE_EXPANSION_UNIQUENESS, new FileSymlinkInfiniteExpansionUniquenessFunction()).put(SkyFunctions.FILE, new FileFunction(pkgLocatorRef)).put(SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null)).put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD))).put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())).put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(TestRuleClassProvider.getRuleClassProvider(), TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create(TestRuleClassProvider.getRuleClassProvider(), fs), directories)).put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()).put(SkyFunctions.LOCAL_REPOSITORY_LOOKUP, new LocalRepositoryLookupFunction()).build(), differencer);
PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator);
return new SequentialBuildDriver(evaluator);
}
use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testSwitchPackageRootsWhenUsingMultiplePackagePaths.
@Test
public void testSwitchPackageRootsWhenUsingMultiplePackagePaths() throws Exception {
// Layout:
// pp1://a/BUILD
// pp1://a/file.a
// pp1://a/b.sym -> b/ (only created later)
// pp1://a/b/
// pp1://a/b/file.fake
// pp1://a/subdir/file.b
//
// pp2://a/BUILD
// pp2://a/b/
// pp2://a/b/BUILD
// pp2://a/b/file.a
// pp2://a/subdir.fake/
// pp2://a/subdir.fake/file.fake
//
// Notice that pp1://a/b will be overlaid by pp2://a/b as the latter has a BUILD file and that
// takes precedence. On the other hand the package definition pp2://a/BUILD will be ignored
// since package //a is already defined under pp1.
//
// Notice also that pp1://a/b.sym is a relative symlink pointing to b/. This should be resolved
// to the definition of //a/b/ under pp1, not under pp2.
// Set the package paths.
pkgLocator.set(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory.getRelative("pp1"), rootDirectory.getRelative("pp2"))));
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
Artifact aBuildArtifact = sourceArtifactUnderPackagePath("a/BUILD", "pp1");
Artifact bBuildArtifact = sourceArtifactUnderPackagePath("a/b/BUILD", "pp2");
RootedPath pp1aBuild = createFile(rootedPath(aBuildArtifact));
RootedPath pp1aFileA = createFile(siblingOf(pp1aBuild, "file.a"));
RootedPath pp1bFileFake = createFile(siblingOf(pp1aBuild, "b/file.fake"));
RootedPath pp1aSubdirFileB = createFile(siblingOf(pp1aBuild, "subdir/file.b"));
RootedPath pp2aBuild = createFile(rootedPath("a/BUILD", "pp2"));
RootedPath pp2bBuild = createFile(rootedPath(bBuildArtifact));
RootedPath pp2bFileA = createFile(siblingOf(pp2bBuild, "file.a"));
createFile(siblingOf(pp2aBuild, "subdir.fake/file.fake"));
// Traverse //a including subpackages. The result should contain the pp1-definition of //a and
// the pp2-definition of //a/b.
traverseAndAssertFiles(pkgRoot(parentOf(rootedPath(aBuildArtifact)), CROSS), regularFileForTesting(pp1aBuild), regularFileForTesting(pp1aFileA), regularFileForTesting(pp1aSubdirFileB), regularFileForTesting(pp2bBuild), regularFileForTesting(pp2bFileA));
// Traverse //a excluding subpackages. The result should only contain files from //a and not
// from //a/b.
traverseAndAssertFiles(pkgRoot(parentOf(rootedPath(aBuildArtifact)), DONT_CROSS), regularFileForTesting(pp1aBuild), regularFileForTesting(pp1aFileA), regularFileForTesting(pp1aSubdirFileB));
// Create a relative symlink pp1://a/b.sym -> b/. It will be resolved to the subdirectory
// pp1://a/b, even though a package definition pp2://a/b exists.
RootedPath pp1aBsym = siblingOf(pp1aFileA, "b.sym");
pp1aBsym.asPath().createSymbolicLink(new PathFragment("b"));
invalidateDirectory(parentOf(pp1aBsym));
// Traverse //a excluding subpackages. The relative symlink //a/b.sym points to the subdirectory
// a/b, i.e. the pp1-definition, even though there is a pp2-defined package //a/b and we expect
// to see b.sym/b.fake (not b/b.fake).
traverseAndAssertFiles(pkgRoot(parentOf(rootedPath(aBuildArtifact)), DONT_CROSS), regularFileForTesting(pp1aBuild), regularFileForTesting(pp1aFileA), regularFileForTesting(childOf(pp1aBsym, "file.fake")), symlinkToDirectoryForTesting(parentOf(pp1bFileFake), pp1aBsym, new PathFragment("b")), regularFileForTesting(pp1aSubdirFileB));
}
Aggregations