use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method assertFileTraversalForFileSymlink.
private void assertFileTraversalForFileSymlink(SymlinkBehavior symlinks) throws Exception {
Artifact file = createSourceArtifact("foo/file.real");
Artifact symlink = getSourceArtifact("foo/file.sym");
symlink.getPath().createSymbolicLink(new PathFragment("file.real"));
FilesetTraversalParams params = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//foo"), /*fileToTraverse=*/
symlink, /*destPath=*/
new PathFragment("output-name"), /*symlinkBehaviorMode=*/
symlinks, /*pkgBoundaryMode=*/
DONT_CROSS);
switch(symlinks) {
case COPY:
assertSymlinksInOrder(params, symlink("output-name", "file.real"));
break;
case DEREFERENCE:
assertSymlinksInOrder(params, symlink("output-name", file));
break;
default:
throw new IllegalStateException(symlinks.toString());
}
}
use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method assertExclusionOfDanglingSymlink.
private void assertExclusionOfDanglingSymlink(SymlinkBehavior symlinkBehavior) throws Exception {
Artifact buildFile = getSourceArtifact("foo/BUILD");
createFile(buildFile);
Artifact linkName = getSourceArtifact("foo/file.sym");
Artifact linkTarget = getSourceArtifact("foo/file.actual");
createFile(linkTarget);
linkName.getPath().createSymbolicLink(new PathFragment("file.actual"));
// Ensure the symlink and its target would be included if they weren't explicitly excluded.
FilesetTraversalParams params = FilesetTraversalParamsFactory.recursiveTraversalOfPackage(/* ownerLabel */
label("//foo"), /* buildFile */
buildFile, /* destPath */
new PathFragment("output-name"), /* excludes */
ImmutableSet.<String>of(), /* symlinkBehaviorMode */
symlinkBehavior, /* pkgBoundaryMode */
PackageBoundaryMode.DONT_CROSS);
assertSymlinksInOrder(params, symlink("output-name/BUILD", buildFile), symlink("output-name/file.actual", linkTarget), symlinkBehavior == SymlinkBehavior.COPY ? symlink("output-name/file.sym", "file.actual") : symlink("output-name/file.sym", linkTarget));
// Delete the symlink's target to make it dangling.
// Exclude the symlink and make sure it's not included.
linkTarget.getPath().delete();
differencer.invalidate(ImmutableList.of(FileStateValue.key(rootedPath(linkTarget))));
params = FilesetTraversalParamsFactory.recursiveTraversalOfPackage(/* ownerLabel */
label("//foo"), /* buildFile */
buildFile, /* destPath */
new PathFragment("output-name"), /* excludes */
ImmutableSet.of("file.sym"), /* symlinkBehaviorMode */
symlinkBehavior, /* pkgBoundaryMode */
PackageBoundaryMode.DONT_CROSS);
assertSymlinksInOrder(params, symlink("output-name/BUILD", buildFile));
}
use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method assertRecursiveTraversalForPackage.
private void assertRecursiveTraversalForPackage(SymlinkBehavior symlinks, PackageBoundaryMode pkgBoundaryMode) throws Exception {
Artifact buildFile = createSourceArtifact("foo/BUILD");
Artifact subpkgBuildFile = createSourceArtifact("foo/subpkg/BUILD");
Artifact subpkgSymlink = getSourceArtifact("foo/subpkg_sym");
RootedPath fileA = createFile(siblingOf(buildFile, "file.a"), "blah");
RootedPath fileAsym = siblingOf(buildFile, "subdir/file.a.sym");
RootedPath fileB = createFile(siblingOf(subpkgBuildFile, "file.b"), "blah");
scratch.dir(fileAsym.asPath().getParentDirectory().getPathString());
fileAsym.asPath().createSymbolicLink(new PathFragment("../file.a"));
subpkgSymlink.getPath().createSymbolicLink(new PathFragment("subpkg"));
FilesetOutputSymlink outBuild = symlink("output-name/BUILD", buildFile);
FilesetOutputSymlink outA = symlink("output-name/file.a", fileA);
FilesetOutputSymlink outAsym = null;
FilesetOutputSymlink outSubpkgBuild = symlink("output-name/subpkg/BUILD", subpkgBuildFile);
FilesetOutputSymlink outSubpkgB = symlink("output-name/subpkg/file.b", fileB);
FilesetOutputSymlink outSubpkgSymBuild;
switch(symlinks) {
case COPY:
outAsym = symlink("output-name/subdir/file.a.sym", "../file.a");
outSubpkgSymBuild = symlink("output-name/subpkg_sym", "subpkg");
break;
case DEREFERENCE:
outAsym = symlink("output-name/subdir/file.a.sym", fileA);
outSubpkgSymBuild = symlink("output-name/subpkg_sym", getSourceArtifact("foo/subpkg"));
break;
default:
throw new IllegalStateException(symlinks.toString());
}
FilesetTraversalParams params = FilesetTraversalParamsFactory.recursiveTraversalOfPackage(/*ownerLabel=*/
label("//foo"), /*directoryToTraverse=*/
buildFile, /*destPath=*/
new PathFragment("output-name"), /*excludes=*/
null, /*symlinkBehaviorMode=*/
symlinks, /*pkgBoundaryMode=*/
pkgBoundaryMode);
switch(pkgBoundaryMode) {
case CROSS:
assertSymlinksInOrder(params, outBuild, outA, outSubpkgSymBuild, outAsym, outSubpkgBuild, outSubpkgB);
break;
case DONT_CROSS:
assertSymlinksInOrder(params, outBuild, outA, outAsym);
break;
case REPORT_ERROR:
SkyKey key = FilesetEntryValue.key(params);
EvaluationResult<SkyValue> result = eval(key);
assertThat(result.hasError()).isTrue();
assertThat(result.getError(key).getException().getMessage()).contains("'foo' crosses package boundary into package rooted at foo/subpkg");
break;
default:
throw new IllegalStateException(pkgBoundaryMode.toString());
}
}
use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method testFileTraversalForFile.
@Test
public void testFileTraversalForFile() throws Exception {
Artifact file = createSourceArtifact("foo/file.real");
FilesetTraversalParams params = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//foo"), /*fileToTraverse=*/
file, /*destPath=*/
new PathFragment("output-name"), /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
assertSymlinksInOrder(params, symlink("output-name", file));
}
use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method testNestedFileFilesetTraversal.
@Test
public void testNestedFileFilesetTraversal() throws Exception {
Artifact path = getSourceArtifact("foo/bar.file");
createFile(path, "blah");
FilesetTraversalParams inner = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//foo"), /*fileToTraverse=*/
path, /*destPath=*/
new PathFragment("inner-out"), /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
FilesetTraversalParams outer = FilesetTraversalParamsFactory.nestedTraversal(/*ownerLabel=*/
label("//foo:bar"), /*nested=*/
inner, /*destDir=*/
new PathFragment("outer-out"), /*excludes=*/
null);
assertSymlinksInOrder(outer, symlink("outer-out/inner-out", rootedPath(path)));
}
Aggregations