use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method testFileTraversalForDirectory.
@Test
public void testFileTraversalForDirectory() throws Exception {
Artifact dir = getSourceArtifact("foo/dir_real");
RootedPath fileA = createFile(childOf(dir, "file.a"), "hello");
RootedPath fileB = createFile(childOf(dir, "sub/file.b"), "world");
FilesetTraversalParams params = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//foo"), /*fileToTraverse=*/
dir, /*destPath=*/
new PathFragment("output-name"), /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
assertSymlinksInOrder(params, symlink("output-name/file.a", fileA), symlink("output-name/sub/file.b", fileB));
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class FilesetEntryFunctionTest method testFileTraversalForDanglingSymlink.
@Test
public void testFileTraversalForDanglingSymlink() throws Exception {
Artifact linkName = getSourceArtifact("foo/dangling.sym");
RootedPath linkTarget = createFile(siblingOf(linkName, "target.file"), "blah");
linkName.getPath().createSymbolicLink(new PathFragment("target.file"));
linkTarget.asPath().delete();
FilesetTraversalParams params = FilesetTraversalParamsFactory.fileTraversal(/*ownerLabel=*/
label("//foo"), /*fileToTraverse=*/
linkName, /*destPath=*/
new PathFragment("output-name"), /*symlinkBehaviorMode=*/
SymlinkBehavior.COPY, /*pkgBoundaryMode=*/
DONT_CROSS);
// expect empty results
assertSymlinksInOrder(params);
}
use of com.google.devtools.build.lib.vfs.RootedPath 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.vfs.RootedPath in project bazel by bazelbuild.
the class FileFunctionTest method valueForPathHelper.
private FileValue valueForPathHelper(Path root, Path path) throws InterruptedException {
PathFragment pathFragment = path.relativeTo(root);
RootedPath rootedPath = RootedPath.toRootedPath(root, pathFragment);
SequentialBuildDriver driver = makeDriver();
SkyKey key = FileValue.key(rootedPath);
EvaluationResult<FileValue> result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
assertFalse(result.hasError());
return result.get(key);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class NewLocalRepositoryFunction method fetch.
@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws SkyFunctionException, InterruptedException {
NewRepositoryBuildFileHandler buildFileHandler = new NewRepositoryBuildFileHandler(directories.getWorkspace());
if (!buildFileHandler.prepareBuildFile(rule, env)) {
return null;
}
PathFragment pathFragment = getTargetPath(rule, directories.getWorkspace());
FileSystem fs = directories.getOutputBase().getFileSystem();
Path path = fs.getPath(pathFragment);
RootedPath dirPath = RootedPath.toRootedPath(fs.getRootDirectory(), path);
try {
FileValue dirFileValue = (FileValue) env.getValueOrThrow(FileValue.key(dirPath), IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
if (dirFileValue == null) {
return null;
}
if (!dirFileValue.exists()) {
throw new RepositoryFunctionException(new IOException("Expected directory at " + dirPath.asPath().getPathString() + " but it does not exist."), Transience.PERSISTENT);
}
if (!dirFileValue.isDirectory()) {
// Someone tried to create a local repository from a file.
throw new RepositoryFunctionException(new IOException("Expected directory at " + dirPath.asPath().getPathString() + " but it is not a directory."), Transience.PERSISTENT);
}
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
} catch (FileSymlinkException e) {
throw new RepositoryFunctionException(new IOException(e), Transience.PERSISTENT);
} catch (InconsistentFilesystemException e) {
throw new RepositoryFunctionException(new IOException(e), Transience.PERSISTENT);
}
// fetch() creates symlinks to each child under 'path' and DiffAwareness handles checking all
// of these files and directories for changes. However, if a new file/directory is added
// directly under 'path', Bazel doesn't know that this has to be symlinked in. Thus, this
// creates a dependency on the contents of the 'path' directory.
SkyKey dirKey = DirectoryListingValue.key(dirPath);
DirectoryListingValue directoryValue;
try {
directoryValue = (DirectoryListingValue) env.getValueOrThrow(dirKey, InconsistentFilesystemException.class);
} catch (InconsistentFilesystemException e) {
throw new RepositoryFunctionException(new IOException(e), Transience.PERSISTENT);
}
if (directoryValue == null) {
return null;
}
// Link x/y/z to /some/path/to/y/z.
if (!symlinkLocalRepositoryContents(outputDirectory, path)) {
return null;
}
buildFileHandler.finishBuildFile(outputDirectory);
// If someone specified *new*_local_repository, we can assume they didn't want the existing
// repository info.
Path workspaceFile = outputDirectory.getRelative("WORKSPACE");
if (workspaceFile.exists()) {
try {
workspaceFile.delete();
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
}
createWorkspaceFile(outputDirectory, rule.getTargetKind(), rule.getName());
return RepositoryDirectoryValue.builder().setPath(outputDirectory).setSourceDir(directoryValue);
}
Aggregations