use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class PathPackageLocator method getPackageBuildFileNullable.
/**
* Like #getPackageBuildFile(), but returns null instead of throwing.
* @param packageIdentifier the name of the package.
* @param cache a filesystem-level cache of stat() calls.
*/
public Path getPackageBuildFileNullable(PackageIdentifier packageIdentifier, AtomicReference<? extends UnixGlob.FilesystemCalls> cache) {
Preconditions.checkArgument(!packageIdentifier.getRepository().isDefault());
if (packageIdentifier.getRepository().isMain()) {
return getFilePath(packageIdentifier.getPackageFragment().getRelative("BUILD"), cache);
} else {
Verify.verify(outputBase != null, String.format("External package '%s' needs to be loaded but this PathPackageLocator instance does not " + "support external packages", packageIdentifier));
// This works only to some degree, because it relies on the presence of the repository under
// $OUTPUT_BASE/external, which is created by the appropriate RepositoryDirectoryValue. This
// is true for the invocation in GlobCache, but not for the locator.getBuildFileForPackage()
// invocation in Parser#include().
Path buildFile = outputBase.getRelative(packageIdentifier.getSourceRoot()).getRelative("BUILD");
FileStatus stat = cache.get().statNullable(buildFile, Symlinks.FOLLOW);
if (stat != null && stat.isFile()) {
return buildFile;
} else {
return null;
}
}
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class InMemoryFileSystem method getDirectoryEntries.
@Override
protected Collection<Path> getDirectoryEntries(Path path) throws IOException {
InMemoryDirectoryInfo dirInfo;
synchronized (this) {
dirInfo = getDirectory(path);
if (!dirInfo.outOfScope()) {
FileStatus status = stat(path, false);
Preconditions.checkState(status instanceof InMemoryContentInfo);
if (!((InMemoryContentInfo) status).isReadable()) {
throw new IOException("Directory is not readable");
}
Collection<String> allChildren = dirInfo.getAllChildren();
List<Path> result = new ArrayList<>(allChildren.size());
for (String child : allChildren) {
if (!(child.equals(".") || child.equals(".."))) {
result.add(path.getChild(child));
}
}
return result;
}
}
// If we get here, we're out of scope.
return getDelegatedPath(dirInfo.getEscapingPath()).getDirectoryEntries();
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class SkyframeLabelVisitorTest method testRootCauseOnInconsistentFilesystem.
// Regression test for: "ClassCastException in SkyframeLabelVisitor.sync()"
@Test
public void testRootCauseOnInconsistentFilesystem() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("foo/BUILD", "sh_library(name = 'foo', deps = ['//bar:baz/fizz'])");
Path barBuildFile = scratch.file("bar/BUILD", "sh_library(name = 'bar/baz')");
Path bazDir = barBuildFile.getParentDirectory().getRelative("baz");
scratch.file("bar/baz/BUILD");
FileStatus inconsistentParentFileStatus = new FileStatus() {
@Override
public boolean isFile() {
return true;
}
@Override
public boolean isSpecialFile() {
return false;
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isSymbolicLink() {
return false;
}
@Override
public long getSize() throws IOException {
return 0;
}
@Override
public long getLastModifiedTime() throws IOException {
return 0;
}
@Override
public long getLastChangeTime() throws IOException {
return 0;
}
@Override
public long getNodeId() throws IOException {
return 0;
}
};
fs.stubStat(bazDir, inconsistentParentFileStatus);
Set<Label> labels = ImmutableSet.of(Label.parseAbsolute("//foo:foo"));
getSkyframeExecutor().getPackageManager().newTransitiveLoader().sync(reporter, labels, /*keepGoing=*/
true, /*parallelThreads=*/
100);
assertContainsEvent("Inconsistent filesystem operations");
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testDigestInjection.
// This is more a smoke test than anything, because it turns out that:
// 1) there is no easy way to turn fast digests on/off for these test cases, and
// 2) injectDigest() doesn't really complain if you inject bad digests or digests
// for nonexistent files. Instead some weird error shows up down the line.
// In fact, there are no tests for injectDigest anywhere in the codebase.
// So all we're really testing here is that injectDigest() doesn't throw a weird exception.
// TODO(bazel-team): write real tests for injectDigest, here and elsewhere.
@Test
public void testDigestInjection() throws Exception {
TreeArtifactTestAction action = new TreeArtifactTestAction(outOne) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
try {
writeFile(outOneFileOne, "one");
writeFile(outOneFileTwo, "two");
MetadataHandler md = actionExecutionContext.getMetadataHandler();
FileStatus stat = outOneFileOne.getPath().stat(Symlinks.NOFOLLOW);
md.injectDigest(outOneFileOne, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("one", Charset.forName("UTF-8")).asBytes());
stat = outOneFileTwo.getPath().stat(Symlinks.NOFOLLOW);
md.injectDigest(outOneFileTwo, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("two", Charset.forName("UTF-8")).asBytes());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
buildArtifact(action.getSoleOutput());
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class ParallelBuilderTest method testUpdateCacheError.
@Test
public void testUpdateCacheError() throws Exception {
FileSystem fs = new InMemoryFileSystem() {
@Override
public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
final FileStatus stat = super.stat(path, followSymlinks);
if (path.toString().endsWith("/out/foo")) {
return new FileStatus() {
private final FileStatus original = stat;
@Override
public boolean isSymbolicLink() {
return original.isSymbolicLink();
}
@Override
public boolean isFile() {
return original.isFile();
}
@Override
public boolean isDirectory() {
return original.isDirectory();
}
@Override
public boolean isSpecialFile() {
return original.isSpecialFile();
}
@Override
public long getSize() throws IOException {
return original.getSize();
}
@Override
public long getNodeId() throws IOException {
return original.getNodeId();
}
@Override
public long getLastModifiedTime() throws IOException {
throw new IOException();
}
@Override
public long getLastChangeTime() throws IOException {
return original.getLastChangeTime();
}
};
}
return stat;
}
};
Artifact foo = createDerivedArtifact(fs, "foo");
registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(foo)));
reporter.removeHandler(failFastHandler);
try {
buildArtifacts(foo);
fail("Expected to fail");
} catch (BuildFailedException e) {
assertContainsEvent("not all outputs were created or valid");
}
}
Aggregations