Search in sources :

Example 1 with InconsistentFilesystemException

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());
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) ToolPath(com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.ToolPath) Path(com.google.devtools.build.lib.vfs.Path) SkyKey(com.google.devtools.build.skyframe.SkyKey) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) IOException(java.io.IOException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException)

Example 2 with InconsistentFilesystemException

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);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) FileValue(com.google.devtools.build.lib.skyframe.FileValue) SkyKey(com.google.devtools.build.skyframe.SkyKey) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) DirectoryListingValue(com.google.devtools.build.lib.skyframe.DirectoryListingValue) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 3 with InconsistentFilesystemException

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PackageLookupValue(com.google.devtools.build.lib.skyframe.PackageLookupValue) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) FileValue(com.google.devtools.build.lib.skyframe.FileValue) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) Label(com.google.devtools.build.lib.cmdline.Label) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) EvalException(com.google.devtools.build.lib.syntax.EvalException) IOException(java.io.IOException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) RepositoryFunctionException(com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)

Example 4 with InconsistentFilesystemException

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());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) FileValue(com.google.devtools.build.lib.skyframe.FileValue) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 5 with InconsistentFilesystemException

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);
    }
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) SkyKey(com.google.devtools.build.skyframe.SkyKey) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) IOException(java.io.IOException) Properties(java.util.Properties) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException)

Aggregations

InconsistentFilesystemException (com.google.devtools.build.lib.skyframe.InconsistentFilesystemException)8 SkyKey (com.google.devtools.build.skyframe.SkyKey)8 IOException (java.io.IOException)8 FileSymlinkException (com.google.devtools.build.lib.skyframe.FileSymlinkException)7 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)6 FileValue (com.google.devtools.build.lib.skyframe.FileValue)5 Path (com.google.devtools.build.lib.vfs.Path)4 EvalException (com.google.devtools.build.lib.syntax.EvalException)3 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)3 Label (com.google.devtools.build.lib.cmdline.Label)2 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)2 DirectoryListingValue (com.google.devtools.build.lib.skyframe.DirectoryListingValue)2 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 RepositoryFunction (com.google.devtools.build.lib.rules.repository.RepositoryFunction)1 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)1 PackageLookupValue (com.google.devtools.build.lib.skyframe.PackageLookupValue)1 WorkspaceFileValue (com.google.devtools.build.lib.skyframe.WorkspaceFileValue)1 Dirent (com.google.devtools.build.lib.vfs.Dirent)1 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)1