use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class TreeArtifactMetadataTest method testIOExceptionEndToEnd.
/**
* Tests that ArtifactFunction rethrows transitive {@link IOException}s as
* {@link MissingInputFileException}s.
*/
@Test
public void testIOExceptionEndToEnd() throws Throwable {
final IOException exception = new IOException("boop");
setupRoot(new CustomInMemoryFs() {
@Override
public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
if (path.getBaseName().equals("one")) {
throw exception;
}
return super.stat(path, followSymlinks);
}
});
try {
Artifact artifact = createTreeArtifact("outOne");
TreeArtifactValue value = evaluateTreeArtifact(artifact, ImmutableList.of(new PathFragment("one")));
fail("MissingInputFileException expected, got " + value);
} catch (Exception e) {
assertThat(Throwables.getRootCause(e).getMessage()).contains(exception.getMessage());
}
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class FdoSupport method extractFdoZip.
/**
* Extracts the FDO zip file and collects data from it that's needed during analysis.
*
* <p>When an {@code --fdo_optimize} compile is requested, unpacks the given
* FDO gcda zip file into a clean working directory under execRoot.
*
* @throws FdoException if the FDO ZIP contains a file of unknown type
*/
private static FdoZipContents extractFdoZip(FdoMode fdoMode, LipoMode lipoMode, Path execRoot, Path fdoProfile, PathFragment fdoRootExecPath, String productName) throws IOException, FdoException {
// The execRoot != null case is only there for testing. We cannot provide a real ZIP file in
// tests because ZipFileSystem does not work with a ZIP on an in-memory file system.
// IMPORTANT: Keep in sync with #declareSkyframeDependencies to avoid incrementality issues.
ImmutableSet<PathFragment> gcdaFiles = ImmutableSet.of();
ImmutableMultimap<PathFragment, PathFragment> imports = ImmutableMultimap.of();
if (fdoProfile != null && execRoot != null) {
Path fdoDirPath = execRoot.getRelative(fdoRootExecPath);
FileSystemUtils.deleteTreesBelow(fdoDirPath);
FileSystemUtils.createDirectoryAndParents(fdoDirPath);
if (fdoMode == FdoMode.AUTO_FDO) {
if (lipoMode != LipoMode.OFF) {
imports = readAutoFdoImports(getAutoFdoImportsPath(fdoProfile));
}
FileSystemUtils.ensureSymbolicLink(execRoot.getRelative(getAutoProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
} else if (fdoMode == FdoMode.LLVM_FDO) {
FileSystemUtils.ensureSymbolicLink(execRoot.getRelative(getLLVMProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
} else {
Path zipFilePath = new ZipFileSystem(fdoProfile).getRootDirectory();
String outputSymlinkName = productName + "-out";
if (!zipFilePath.getRelative(outputSymlinkName).isDirectory()) {
throw new ZipException("FDO zip files must be zipped directly above '" + outputSymlinkName + "' for the compiler to find the profile");
}
ImmutableSet.Builder<PathFragment> gcdaFilesBuilder = ImmutableSet.builder();
ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder = ImmutableMultimap.builder();
extractFdoZipDirectory(zipFilePath, fdoDirPath, gcdaFilesBuilder, importsBuilder);
gcdaFiles = gcdaFilesBuilder.build();
imports = importsBuilder.build();
}
}
return new FdoZipContents(gcdaFiles, imports);
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class BlazeDirectoriesTest method testCreatingDirectories.
@Test
public void testCreatingDirectories() {
FileSystem fs = scratch.getFileSystem();
Path installBase = fs.getPath("/my/install");
Path outputBase = fs.getPath("/my/output");
Path workspace = fs.getPath("/my/ws");
BlazeDirectories directories = new BlazeDirectories(installBase, outputBase, workspace, "foo");
assertEquals(directories.getExecRoot(), outputBase.getChild("ws"));
workspace = null;
directories = new BlazeDirectories(installBase, outputBase, workspace, "foo");
assertEquals(directories.getExecRoot(), outputBase.getChild(BlazeDirectories.DEFAULT_EXEC_ROOT));
workspace = fs.getPath("/");
directories = new BlazeDirectories(installBase, outputBase, workspace, "foo");
assertEquals(directories.getExecRoot(), outputBase.getChild(BlazeDirectories.DEFAULT_EXEC_ROOT));
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class RunfilesSupplierImplTest method setRoot.
@Before
public final void setRoot() throws IOException {
Scratch scratch = new Scratch();
rootDir = Root.asDerivedRoot(scratch.dir("/fake/root/dont/matter"));
Path middlemanExecPath = scratch.dir("/still/fake/root/dont/matter");
middlemanRoot = Root.middlemanRoot(middlemanExecPath, middlemanExecPath.getChild("subdir"));
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class GrpcActionCache method downloadAllResults.
/**
* Download all results of a remotely executed action locally. TODO(olaola): will need to amend to
* include the {@link com.google.devtools.build.lib.remote.TreeNodeRepository} for updating.
*/
@Override
public void downloadAllResults(ActionResult result, Path execRoot) throws IOException, CacheNotFoundException {
// Send all the file requests in a single synchronous batch.
// TODO(olaola): profile to maybe replace with separate concurrent requests.
CasDownloadBlobRequest.Builder request = CasDownloadBlobRequest.newBuilder();
Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap = new HashMap<>();
for (Output output : result.getOutputList()) {
Path path = execRoot.getRelative(output.getPath());
if (output.getContentCase() == ContentCase.FILE_METADATA) {
FileMetadata fileMetadata = output.getFileMetadata();
ContentDigest digest = fileMetadata.getDigest();
if (digest.getSizeBytes() > 0) {
request.addDigest(digest);
metadataMap.put(digest, Pair.of(path, fileMetadata));
} else {
// Handle empty file locally.
FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
FileSystemUtils.writeContent(path, new byte[0]);
}
} else {
downloadTree(output.getDigest(), path);
}
}
Iterator<CasDownloadReply> replies = getBlockingStub().downloadBlob(request.build());
Set<ContentDigest> results = new HashSet<>();
while (replies.hasNext()) {
results.add(createFileFromStream(metadataMap, replies));
}
for (ContentDigest digest : metadataMap.keySet()) {
if (!results.contains(digest)) {
throw new CacheNotFoundException(digest);
}
}
}
Aggregations