use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method derivedArtifact.
private Artifact derivedArtifact(String path) {
PathFragment execPath = new PathFragment("out").getRelative(path);
Path fullPath = rootDirectory.getRelative(execPath);
Artifact output = new Artifact(fullPath, Root.asDerivedRoot(rootDirectory, rootDirectory.getRelative("out")), execPath);
return output;
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversePackage.
@Test
public void testTraversePackage() throws Exception {
Artifact buildFile = sourceArtifact("pkg/BUILD");
RootedPath buildFilePath = createFile(rootedPath(buildFile));
RootedPath file1 = createFile(siblingOf(buildFile, "subdir/file.a"));
traverseAndAssertFiles(pkgRoot(parentOf(buildFilePath), DONT_CROSS), regularFileForTesting(buildFilePath), regularFileForTesting(file1));
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversalOfTransitiveSymlinkToFile.
@Test
public void testTraversalOfTransitiveSymlinkToFile() throws Exception {
Artifact directLinkArtifact = sourceArtifact("direct/file.sym");
Artifact transitiveLinkArtifact = sourceArtifact("transitive/sym.sym");
RootedPath fileA = createFile(rootedPath(sourceArtifact("a/file.a")));
RootedPath directLink = rootedPath(directLinkArtifact);
RootedPath transitiveLink = rootedPath(transitiveLinkArtifact);
PathFragment directLinkPath = new PathFragment("../a/file.a");
PathFragment transitiveLinkPath = new PathFragment("../direct/file.sym");
parentOf(directLink).asPath().createDirectory();
parentOf(transitiveLink).asPath().createDirectory();
directLink.asPath().createSymbolicLink(directLinkPath);
transitiveLink.asPath().createSymbolicLink(transitiveLinkPath);
traverseAndAssertFiles(fileLikeRoot(directLinkArtifact, DONT_CROSS), symlinkToFileForTesting(fileA, directLink, directLinkPath));
traverseAndAssertFiles(fileLikeRoot(transitiveLinkArtifact, DONT_CROSS), symlinkToFileForTesting(fileA, transitiveLink, transitiveLinkPath));
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversalOfTransitiveSymlinkToDirectory.
@Test
public void testTraversalOfTransitiveSymlinkToDirectory() throws Exception {
Artifact directLinkArtifact = sourceArtifact("direct/dir.sym");
Artifact transitiveLinkArtifact = sourceArtifact("transitive/sym.sym");
RootedPath fileA = createFile(rootedPath(sourceArtifact("a/file.a")));
RootedPath directLink = rootedPath(directLinkArtifact);
RootedPath transitiveLink = rootedPath(transitiveLinkArtifact);
PathFragment directLinkPath = new PathFragment("../a");
PathFragment transitiveLinkPath = new PathFragment("../direct/dir.sym");
parentOf(directLink).asPath().createDirectory();
parentOf(transitiveLink).asPath().createDirectory();
directLink.asPath().createSymbolicLink(directLinkPath);
transitiveLink.asPath().createSymbolicLink(transitiveLinkPath);
// Expect the file as if was a child of the direct symlink, not of the actual directory.
traverseAndAssertFiles(fileLikeRoot(directLinkArtifact, DONT_CROSS), symlinkToDirectoryForTesting(parentOf(fileA), directLink, directLinkPath), regularFileForTesting(childOf(directLinkArtifact, "file.a")));
// Expect the file as if was a child of the transitive symlink, not of the actual directory.
traverseAndAssertFiles(fileLikeRoot(transitiveLinkArtifact, DONT_CROSS), symlinkToDirectoryForTesting(parentOf(fileA), transitiveLink, transitiveLinkPath), regularFileForTesting(childOf(transitiveLinkArtifact, "file.a")));
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method assertTraverseSubpackages.
private void assertTraverseSubpackages(PackageBoundaryMode traverseSubpackages) throws Exception {
Artifact pkgDirArtifact = sourceArtifact("pkg1/foo");
Artifact subpkgDirArtifact = sourceArtifact("pkg1/foo/subdir/subpkg");
RootedPath pkgBuildFile = childOf(pkgDirArtifact, "BUILD");
RootedPath subpkgBuildFile = childOf(subpkgDirArtifact, "BUILD");
scratch.dir(rootedPath(pkgDirArtifact).asPath().getPathString());
scratch.dir(rootedPath(subpkgDirArtifact).asPath().getPathString());
createFile(pkgBuildFile);
createFile(subpkgBuildFile);
TraversalRequest traversalRoot = pkgRoot(parentOf(pkgBuildFile), traverseSubpackages);
ResolvedFile expected1 = regularFileForTesting(pkgBuildFile);
ResolvedFile expected2 = regularFileForTesting(subpkgBuildFile);
switch(traverseSubpackages) {
case CROSS:
traverseAndAssertFiles(traversalRoot, expected1, expected2);
break;
case DONT_CROSS:
traverseAndAssertFiles(traversalRoot, expected1);
break;
case REPORT_ERROR:
SkyKey key = rftvSkyKey(traversalRoot);
EvaluationResult<SkyValue> result = eval(key);
assertThat(result.hasError()).isTrue();
assertThat(result.getError().getException().getMessage()).contains("crosses package boundary into package rooted at");
break;
default:
throw new IllegalStateException(traverseSubpackages.toString());
}
}
Aggregations