use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class WorkspaceASTFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException, WorkspaceASTFunctionException {
RootedPath workspaceRoot = (RootedPath) skyKey.argument();
FileValue workspaceFileValue = (FileValue) env.getValue(FileValue.key(workspaceRoot));
if (workspaceFileValue == null) {
return null;
}
Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath());
try {
BuildFileAST ast = BuildFileAST.parseBuildFile(ParserInputSource.create(ruleClassProvider.getDefaultWorkspacePrefix(), new PathFragment("/DEFAULT.WORKSPACE")), env.getListener());
if (ast.containsErrors()) {
throw new WorkspaceASTFunctionException(new BuildFileContainsErrorsException(Label.EXTERNAL_PACKAGE_IDENTIFIER, "Failed to parse default WORKSPACE file"), Transience.PERSISTENT);
}
if (workspaceFileValue.exists()) {
ast = BuildFileAST.parseBuildFile(ParserInputSource.create(repoWorkspace), ast.getStatements(), env.getListener());
if (ast.containsErrors()) {
throw new WorkspaceASTFunctionException(new BuildFileContainsErrorsException(Label.EXTERNAL_PACKAGE_IDENTIFIER, "Failed to parse WORKSPACE file"), Transience.PERSISTENT);
}
}
ast = BuildFileAST.parseBuildFile(ParserInputSource.create(ruleClassProvider.getDefaultWorkspaceSuffix(), new PathFragment("/DEFAULT.WORKSPACE.SUFFIX")), ast.getStatements(), env.getListener());
if (ast.containsErrors()) {
throw new WorkspaceASTFunctionException(new BuildFileContainsErrorsException(Label.EXTERNAL_PACKAGE_IDENTIFIER, "Failed to parse default WORKSPACE file suffix"), Transience.PERSISTENT);
}
return new WorkspaceASTValue(splitAST(ast));
} catch (IOException ex) {
throw new WorkspaceASTFunctionException(ex, Transience.TRANSIENT);
}
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversePackage.
@Test
public void testTraversePackage() throws Exception {
Artifact buildFile = sourceArtifact("pkg/BUILD");
RootedPath buildFilePath = createFile(rootedPath(buildFile));
RootedPath file1 = createFile(siblingOf(buildFile, "subdir/file.a"));
traverseAndAssertFiles(pkgRoot(parentOf(buildFilePath), DONT_CROSS), regularFileForTesting(buildFilePath), regularFileForTesting(file1));
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversalOfTransitiveSymlinkToFile.
@Test
public void testTraversalOfTransitiveSymlinkToFile() throws Exception {
Artifact directLinkArtifact = sourceArtifact("direct/file.sym");
Artifact transitiveLinkArtifact = sourceArtifact("transitive/sym.sym");
RootedPath fileA = createFile(rootedPath(sourceArtifact("a/file.a")));
RootedPath directLink = rootedPath(directLinkArtifact);
RootedPath transitiveLink = rootedPath(transitiveLinkArtifact);
PathFragment directLinkPath = new PathFragment("../a/file.a");
PathFragment transitiveLinkPath = new PathFragment("../direct/file.sym");
parentOf(directLink).asPath().createDirectory();
parentOf(transitiveLink).asPath().createDirectory();
directLink.asPath().createSymbolicLink(directLinkPath);
transitiveLink.asPath().createSymbolicLink(transitiveLinkPath);
traverseAndAssertFiles(fileLikeRoot(directLinkArtifact, DONT_CROSS), symlinkToFileForTesting(fileA, directLink, directLinkPath));
traverseAndAssertFiles(fileLikeRoot(transitiveLinkArtifact, DONT_CROSS), symlinkToFileForTesting(fileA, transitiveLink, transitiveLinkPath));
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversalOfTransitiveSymlinkToDirectory.
@Test
public void testTraversalOfTransitiveSymlinkToDirectory() throws Exception {
Artifact directLinkArtifact = sourceArtifact("direct/dir.sym");
Artifact transitiveLinkArtifact = sourceArtifact("transitive/sym.sym");
RootedPath fileA = createFile(rootedPath(sourceArtifact("a/file.a")));
RootedPath directLink = rootedPath(directLinkArtifact);
RootedPath transitiveLink = rootedPath(transitiveLinkArtifact);
PathFragment directLinkPath = new PathFragment("../a");
PathFragment transitiveLinkPath = new PathFragment("../direct/dir.sym");
parentOf(directLink).asPath().createDirectory();
parentOf(transitiveLink).asPath().createDirectory();
directLink.asPath().createSymbolicLink(directLinkPath);
transitiveLink.asPath().createSymbolicLink(transitiveLinkPath);
// Expect the file as if was a child of the direct symlink, not of the actual directory.
traverseAndAssertFiles(fileLikeRoot(directLinkArtifact, DONT_CROSS), symlinkToDirectoryForTesting(parentOf(fileA), directLink, directLinkPath), regularFileForTesting(childOf(directLinkArtifact, "file.a")));
// Expect the file as if was a child of the transitive symlink, not of the actual directory.
traverseAndAssertFiles(fileLikeRoot(transitiveLinkArtifact, DONT_CROSS), symlinkToDirectoryForTesting(parentOf(fileA), transitiveLink, transitiveLinkPath), regularFileForTesting(childOf(transitiveLinkArtifact, "file.a")));
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method assertTraverseSubpackages.
private void assertTraverseSubpackages(PackageBoundaryMode traverseSubpackages) throws Exception {
Artifact pkgDirArtifact = sourceArtifact("pkg1/foo");
Artifact subpkgDirArtifact = sourceArtifact("pkg1/foo/subdir/subpkg");
RootedPath pkgBuildFile = childOf(pkgDirArtifact, "BUILD");
RootedPath subpkgBuildFile = childOf(subpkgDirArtifact, "BUILD");
scratch.dir(rootedPath(pkgDirArtifact).asPath().getPathString());
scratch.dir(rootedPath(subpkgDirArtifact).asPath().getPathString());
createFile(pkgBuildFile);
createFile(subpkgBuildFile);
TraversalRequest traversalRoot = pkgRoot(parentOf(pkgBuildFile), traverseSubpackages);
ResolvedFile expected1 = regularFileForTesting(pkgBuildFile);
ResolvedFile expected2 = regularFileForTesting(subpkgBuildFile);
switch(traverseSubpackages) {
case CROSS:
traverseAndAssertFiles(traversalRoot, expected1, expected2);
break;
case DONT_CROSS:
traverseAndAssertFiles(traversalRoot, expected1);
break;
case REPORT_ERROR:
SkyKey key = rftvSkyKey(traversalRoot);
EvaluationResult<SkyValue> result = eval(key);
assertThat(result.hasError()).isTrue();
assertThat(result.getError().getException().getMessage()).contains("crosses package boundary into package rooted at");
break;
default:
throw new IllegalStateException(traverseSubpackages.toString());
}
}
Aggregations