use of com.google.devtools.build.lib.skyframe.InconsistentFilesystemException in project bazel by bazelbuild.
the class AndroidNdkRepositoryFunction method getNdkRelease.
private static NdkRelease getNdkRelease(Path directory, Environment env) throws RepositoryFunctionException, InterruptedException {
// For NDK r11+
Path releaseFilePath = directory.getRelative("source.properties");
if (!releaseFilePath.exists()) {
// For NDK r10e
releaseFilePath = directory.getRelative("RELEASE.TXT");
}
SkyKey releaseFileKey = FileValue.key(RootedPath.toRootedPath(directory, releaseFilePath));
String releaseFileContent;
try {
env.getValueOrThrow(releaseFileKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
releaseFileContent = new String(FileSystemUtils.readContent(releaseFilePath));
} catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
throw new RepositoryFunctionException(new IOException("Could not read " + releaseFilePath.getBaseName() + " in Android NDK: " + e.getMessage()), Transience.PERSISTENT);
}
return NdkRelease.create(releaseFileContent.trim());
}
use of com.google.devtools.build.lib.skyframe.InconsistentFilesystemException 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);
}
use of com.google.devtools.build.lib.skyframe.InconsistentFilesystemException in project bazel by bazelbuild.
the class NewRepositoryBuildFileHandler method getBuildFileValue.
private FileValue getBuildFileValue(Rule rule, Environment env) throws RepositoryFunctionException, InterruptedException {
WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
String buildFileAttribute;
try {
buildFileAttribute = mapper.get("build_file", Type.STRING);
} catch (EvalException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
}
RootedPath rootedBuild;
if (LabelValidator.isAbsolute(buildFileAttribute)) {
try {
// Parse a label
Label label = Label.parseAbsolute(buildFileAttribute);
SkyKey pkgSkyKey = PackageLookupValue.key(label.getPackageIdentifier());
PackageLookupValue pkgLookupValue = (PackageLookupValue) env.getValue(pkgSkyKey);
if (pkgLookupValue == null) {
return null;
}
if (!pkgLookupValue.packageExists()) {
throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "Unable to load package for " + buildFileAttribute + ": not found."), Transience.PERSISTENT);
}
// And now for the file
Path packageRoot = pkgLookupValue.getRoot();
rootedBuild = RootedPath.toRootedPath(packageRoot, label.toPathFragment());
} catch (LabelSyntaxException ex) {
throw new RepositoryFunctionException(new EvalException(rule.getLocation(), String.format("In %s the 'build_file' attribute does not specify a valid label: %s", rule, ex.getMessage())), Transience.PERSISTENT);
}
} else {
// TODO(dmarting): deprecate using a path for the build_file attribute.
PathFragment buildFile = new PathFragment(buildFileAttribute);
Path buildFileTarget = workspacePath.getRelative(buildFile);
if (!buildFileTarget.exists()) {
throw new RepositoryFunctionException(new EvalException(rule.getLocation(), String.format("In %s the 'build_file' attribute does not specify an existing file " + "(%s does not exist)", rule, buildFileTarget)), Transience.PERSISTENT);
}
if (buildFile.isAbsolute()) {
rootedBuild = RootedPath.toRootedPath(buildFileTarget.getParentDirectory(), new PathFragment(buildFileTarget.getBaseName()));
} else {
rootedBuild = RootedPath.toRootedPath(workspacePath, buildFile);
}
}
SkyKey buildFileKey = FileValue.key(rootedBuild);
FileValue buildFileValue;
try {
// Note that this dependency is, strictly speaking, not necessary: the symlink could simply
// point to this FileValue and the symlink chasing could be done while loading the package
// but this results in a nicer error message and it's correct as long as RepositoryFunctions
// don't write to things in the file system this FileValue depends on. In theory, the latter
// is possible if the file referenced by build_file is a symlink to somewhere under the
// external/ directory, but if you do that, you are really asking for trouble.
buildFileValue = (FileValue) env.getValueOrThrow(buildFileKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
if (buildFileValue == null) {
return null;
}
} catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
throw new RepositoryFunctionException(new IOException("Cannot lookup " + buildFileAttribute + ": " + e.getMessage()), Transience.TRANSIENT);
}
return buildFileValue;
}
use of com.google.devtools.build.lib.skyframe.InconsistentFilesystemException in project bazel by bazelbuild.
the class SkylarkRepositoryContext method getPathFromLabel.
// Resolve the label given by value into a file path.
private SkylarkPath getPathFromLabel(Label label) throws EvalException, InterruptedException {
RootedPath rootedPath = getRootedPathFromLabel(label, env);
SkyKey fileSkyKey = FileValue.key(rootedPath);
FileValue fileValue = null;
try {
fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
} catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
throw new EvalException(Location.BUILTIN, e);
}
if (fileValue == null) {
throw SkylarkRepositoryFunction.restart();
}
if (!fileValue.isFile()) {
throw new EvalException(Location.BUILTIN, "Not a file: " + rootedPath.asPath().getPathString());
}
// A label do not contains space so it safe to use as a key.
markerData.put("FILE:" + label, Integer.toString(fileValue.realFileStateValue().hashCode()));
return new SkylarkPath(rootedPath.asPath());
}
use of com.google.devtools.build.lib.skyframe.InconsistentFilesystemException in project bazel by bazelbuild.
the class AndroidSdkRepositoryFunction method getBuildToolsSourceProperties.
private static Properties getBuildToolsSourceProperties(Path directory, String buildToolsDirectory, Environment env) throws RepositoryFunctionException, InterruptedException {
Path sourcePropertiesFilePath = directory.getRelative("build-tools/" + buildToolsDirectory + "/source.properties");
SkyKey releaseFileKey = FileValue.key(RootedPath.toRootedPath(directory, sourcePropertiesFilePath));
try {
env.getValueOrThrow(releaseFileKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
Properties properties = new Properties();
properties.load(sourcePropertiesFilePath.getInputStream());
return properties;
} catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
String error = String.format("Could not read %s in Android SDK: %s", sourcePropertiesFilePath, e.getMessage());
throw new RepositoryFunctionException(new IOException(error), Transience.PERSISTENT);
}
}
Aggregations