use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method assertNestedRecursiveFilesetTraversal.
private void assertNestedRecursiveFilesetTraversal(boolean useInnerDir) throws Exception {
Artifact dir = getSourceArtifact("foo/dir");
RootedPath fileA = createFile(childOf(dir, "file.a"), "hello");
RootedPath fileB = createFile(childOf(dir, "file.b"), "hello");
RootedPath fileC = createFile(childOf(dir, "sub/file.c"), "world");
FilesetTraversalParams inner = FilesetTraversalParamsFactory.recursiveTraversalOfDirectory(/*ownerLabel=*/
label("//foo"), /*directoryToTraverse=*/
dir, /*destPath=*/
new PathFragment(useInnerDir ? "inner-dir" : ""), /*excludes=*/
null, /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
FilesetTraversalParams outer = FilesetTraversalParamsFactory.nestedTraversal(/*ownerLabel=*/
label("//foo"), /*nested=*/
inner, /*destDir=*/
new PathFragment("outer-dir"), ImmutableSet.<String>of("file.a", "sub/file.c"));
if (useInnerDir) {
assertSymlinksInOrder(outer, // no file is excluded, since no files from "inner" are top-level in the outer Fileset
symlink("outer-dir/inner-dir/file.a", fileA), symlink("outer-dir/inner-dir/file.b", fileB), // only top-level files are excluded
symlink("outer-dir/inner-dir/sub/file.c", fileC));
} else {
assertSymlinksInOrder(outer, // file.a can be excluded because it's top-level (there's no output directory for "inner")
symlink("outer-dir/file.b", fileB), // only top-level files could be excluded
symlink("outer-dir/sub/file.c", fileC));
}
}
use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method assertRecursiveTraversalForDirectory.
private void assertRecursiveTraversalForDirectory(SymlinkBehavior symlinks, PackageBoundaryMode pkgBoundaryMode) throws Exception {
Artifact dir = getSourceArtifact("foo/dir");
RootedPath fileA = createFile(childOf(dir, "file.a"), "blah");
RootedPath fileAsym = childOf(dir, "subdir/file.a.sym");
RootedPath buildFile = createFile(childOf(dir, "subpkg/BUILD"), "blah");
RootedPath fileB = createFile(childOf(dir, "subpkg/file.b"), "blah");
fileAsym.asPath().getParentDirectory().createDirectory();
fileAsym.asPath().createSymbolicLink(new PathFragment("../file.a"));
FilesetOutputSymlink outA = symlink("output-name/file.a", childOf(dir, "file.a"));
FilesetOutputSymlink outAsym = null;
FilesetOutputSymlink outBuild = symlink("output-name/subpkg/BUILD", buildFile);
FilesetOutputSymlink outB = symlink("output-name/subpkg/file.b", fileB);
switch(symlinks) {
case COPY:
outAsym = symlink("output-name/subdir/file.a.sym", "../file.a");
break;
case DEREFERENCE:
outAsym = symlink("output-name/subdir/file.a.sym", fileA);
break;
default:
throw new IllegalStateException(symlinks.toString());
}
FilesetTraversalParams params = FilesetTraversalParamsFactory.recursiveTraversalOfDirectory(/*ownerLabel=*/
label("//foo"), /*directoryToTraverse=*/
dir, /*destPath=*/
new PathFragment("output-name"), /*excludes=*/
null, /*symlinkBehaviorMode=*/
symlinks, /*pkgBoundaryMode=*/
pkgBoundaryMode);
switch(pkgBoundaryMode) {
case CROSS:
assertSymlinksInOrder(params, outA, outAsym, outBuild, outB);
break;
case DONT_CROSS:
assertSymlinksInOrder(params, 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/dir' crosses package boundary into package rooted at foo/dir/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 assertFileTraversalForDirectorySymlink.
private void assertFileTraversalForDirectorySymlink(SymlinkBehavior symlinks) throws Exception {
Artifact dir = getSourceArtifact("foo/dir_real");
Artifact symlink = getSourceArtifact("foo/dir_sym");
createFile(childOf(dir, "file.a"), "hello");
createFile(childOf(dir, "sub/file.b"), "world");
symlink.getPath().createSymbolicLink(new PathFragment("dir_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", "dir_real"));
break;
case DEREFERENCE:
assertSymlinksInOrder(params, symlink("output-name", dir));
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 testRecursiveTraversalForNonExistentFile.
@Test
public void testRecursiveTraversalForNonExistentFile() throws Exception {
Artifact path = getSourceArtifact("foo/non-existent");
FilesetTraversalParams params = FilesetTraversalParamsFactory.recursiveTraversalOfDirectory(/*ownerLabel=*/
label("//foo"), /*directoryToTraverse=*/
path, /*destPath=*/
new PathFragment("output-name"), /*excludes=*/
null, /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
// expect empty results
assertSymlinksInOrder(params);
}
use of com.google.devtools.build.lib.actions.FilesetTraversalParams in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method testFingerprintOfNestedTraversal.
@Test
public void testFingerprintOfNestedTraversal() throws Exception {
FilesetTraversalParams n1 = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//blah"), /*fileToTraverse=*/
getSourceArtifact("blah/file.a"), /*destPath=*/
new PathFragment("output-name"), /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
FilesetTraversalParams n2 = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//blah"), /*fileToTraverse=*/
getSourceArtifact("meow/file.b"), /*destPath=*/
new PathFragment("output-name"), /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
new FingerprintTester(ImmutableMap.<String, Domain>of("ownerLabel", notPartOfFingerprint("//foo", "//bar"), "nested", partOfFingerprint(n1, n2), "destDir", partOfFingerprint("out1", "out2"), "excludes", partOfFingerprint(ImmutableSet.<String>of(), ImmutableSet.<String>of("x")))) {
@SuppressWarnings("unchecked")
@Override
FilesetTraversalParams create(Map<String, ?> kwArgs) throws Exception {
return FilesetTraversalParamsFactory.nestedTraversal(label((String) kwArgs.get("ownerLabel")), (FilesetTraversalParams) kwArgs.get("nested"), new PathFragment((String) kwArgs.get("destDir")), (Set<String>) kwArgs.get("excludes"));
}
}.doTest();
}
Aggregations