Search in sources :

Example 11 with FilesetTraversalParams

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));
    }
}
Also used : FilesetTraversalParams(com.google.devtools.build.lib.actions.FilesetTraversalParams) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 12 with FilesetTraversalParams

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());
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) FilesetTraversalParams(com.google.devtools.build.lib.actions.FilesetTraversalParams) FilesetOutputSymlink(com.google.devtools.build.lib.actions.FilesetOutputSymlink) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 13 with FilesetTraversalParams

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());
    }
}
Also used : FilesetTraversalParams(com.google.devtools.build.lib.actions.FilesetTraversalParams) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 14 with FilesetTraversalParams

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);
}
Also used : FilesetTraversalParams(com.google.devtools.build.lib.actions.FilesetTraversalParams) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 15 with FilesetTraversalParams

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();
}
Also used : FilesetTraversalParams(com.google.devtools.build.lib.actions.FilesetTraversalParams) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Test(org.junit.Test)

Aggregations

FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)16 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)16 Artifact (com.google.devtools.build.lib.actions.Artifact)14 Test (org.junit.Test)8 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)7 FilesetOutputSymlink (com.google.devtools.build.lib.actions.FilesetOutputSymlink)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 SkyValue (com.google.devtools.build.skyframe.SkyValue)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 DirectTraversal (com.google.devtools.build.lib.actions.FilesetTraversalParams.DirectTraversal)1 DanglingSymlinkException (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalFunction.DanglingSymlinkException)1 ResolvedFile (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1