Search in sources :

Example 6 with FilesetTraversalParams

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());
    }
}
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 7 with FilesetTraversalParams

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));
}
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 8 with FilesetTraversalParams

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());
    }
}
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 9 with FilesetTraversalParams

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));
}
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 10 with FilesetTraversalParams

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)));
}
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)

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