Search in sources :

Example 6 with FileValue

use of com.google.devtools.build.lib.skyframe.FileValue in project bazel by bazelbuild.

the class MavenServerFunction method getDefaultSettingsFile.

private Map<String, FileValue> getDefaultSettingsFile(BlazeDirectories directories, Environment env) throws InterruptedException {
    // The system settings file is at $M2_HOME/conf/settings.xml.
    String m2Home = System.getenv("M2_HOME");
    ImmutableList.Builder<SkyKey> settingsFilesBuilder = ImmutableList.builder();
    SkyKey systemKey = null;
    if (m2Home != null) {
        PathFragment mavenInstallSettings = new PathFragment(m2Home).getRelative("conf/settings.xml");
        systemKey = FileValue.key(RootedPath.toRootedPath(directories.getWorkspace().getRelative(mavenInstallSettings), PathFragment.EMPTY_FRAGMENT));
        settingsFilesBuilder.add(systemKey);
    }
    // The user settings file is at $HOME/.m2/settings.xml.
    String userHome = System.getenv("HOME");
    SkyKey userKey = null;
    if (userHome != null) {
        PathFragment userSettings = new PathFragment(userHome).getRelative(".m2/settings.xml");
        userKey = FileValue.key(RootedPath.toRootedPath(directories.getWorkspace().getRelative(userSettings), PathFragment.EMPTY_FRAGMENT));
        settingsFilesBuilder.add(userKey);
    }
    ImmutableList<SkyKey> settingsFiles = settingsFilesBuilder.build();
    if (settingsFiles.isEmpty()) {
        return ImmutableMap.of();
    }
    Map<SkyKey, SkyValue> values = env.getValues(settingsFiles);
    ImmutableMap.Builder<String, FileValue> settingsBuilder = ImmutableMap.builder();
    for (Map.Entry<SkyKey, SkyValue> entry : values.entrySet()) {
        if (entry.getValue() == null) {
            return null;
        }
        if (systemKey != null && systemKey.equals(entry.getKey())) {
            settingsBuilder.put(SYSTEM_KEY, (FileValue) entry.getValue());
        } else if (userKey != null && userKey.equals(entry.getKey())) {
            settingsBuilder.put(USER_KEY, (FileValue) entry.getValue());
        }
    }
    return settingsBuilder.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) FileValue(com.google.devtools.build.lib.skyframe.FileValue) ImmutableList(com.google.common.collect.ImmutableList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ImmutableMap(com.google.common.collect.ImmutableMap) SkyValue(com.google.devtools.build.skyframe.SkyValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with FileValue

use of com.google.devtools.build.lib.skyframe.FileValue in project bazel by bazelbuild.

the class SkylarkRepositoryContext method verifyLabelMarkerData.

private static boolean verifyLabelMarkerData(String key, String value, Environment env) throws InterruptedException {
    Preconditions.checkArgument(key.startsWith("FILE:"));
    try {
        Label label = Label.parseAbsolute(key.substring(5));
        RootedPath rootedPath = getRootedPathFromLabel(label, env);
        SkyKey fileSkyKey = FileValue.key(rootedPath);
        FileValue fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
        if (fileValue == null || !fileValue.isFile()) {
            return false;
        }
        return Objects.equals(value, Integer.toString(fileValue.realFileStateValue().hashCode()));
    } catch (LabelSyntaxException e) {
        throw new IllegalStateException("Key " + key + " is not a correct file key (should be in form FILE:label)", e);
    } catch (IOException | FileSymlinkException | InconsistentFilesystemException | EvalException e) {
        // Consider those exception to be a cause for invalidation
        return false;
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) FileValue(com.google.devtools.build.lib.skyframe.FileValue) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) Label(com.google.devtools.build.lib.cmdline.Label) 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 8 with FileValue

use of com.google.devtools.build.lib.skyframe.FileValue in project bazel by bazelbuild.

the class LocalRepositoryFunction method fetch.

@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws InterruptedException, RepositoryFunctionException {
    PathFragment pathFragment = RepositoryFunction.getTargetPath(rule, directories.getWorkspace());
    try {
        outputDirectory.createSymbolicLink(pathFragment);
    } catch (IOException e) {
        throw new RepositoryFunctionException(new IOException("Could not create symlink to repository " + pathFragment + ": " + e.getMessage(), e), Transience.TRANSIENT);
    }
    FileValue repositoryValue = getRepositoryDirectory(outputDirectory, env);
    if (repositoryValue == null) {
        // second execution.
        return null;
    }
    if (!repositoryValue.isDirectory()) {
        throw new RepositoryFunctionException(new IOException(rule + " must specify an existing directory"), Transience.TRANSIENT);
    }
    return RepositoryDirectoryValue.builder().setPath(outputDirectory);
}
Also used : FileValue(com.google.devtools.build.lib.skyframe.FileValue) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException)

Example 9 with FileValue

use of com.google.devtools.build.lib.skyframe.FileValue in project bazel by bazelbuild.

the class RepositoryFunction method getRepositoryDirectory.

/**
   * Adds the repository's directory to the graph and, if it's a symlink, resolves it to an actual
   * directory.
   */
@Nullable
protected static FileValue getRepositoryDirectory(Path repositoryDirectory, Environment env) throws RepositoryFunctionException, InterruptedException {
    SkyKey outputDirectoryKey = FileValue.key(RootedPath.toRootedPath(repositoryDirectory, PathFragment.EMPTY_FRAGMENT));
    FileValue value;
    try {
        value = (FileValue) env.getValueOrThrow(outputDirectoryKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
    } catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
        throw new RepositoryFunctionException(new IOException("Could not access " + repositoryDirectory + ": " + e.getMessage()), Transience.PERSISTENT);
    }
    return value;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) FileValue(com.google.devtools.build.lib.skyframe.FileValue) WorkspaceFileValue(com.google.devtools.build.lib.skyframe.WorkspaceFileValue) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) IOException(java.io.IOException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException) Nullable(javax.annotation.Nullable)

Aggregations

FileValue (com.google.devtools.build.lib.skyframe.FileValue)9 IOException (java.io.IOException)8 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 FileSymlinkException (com.google.devtools.build.lib.skyframe.FileSymlinkException)5 InconsistentFilesystemException (com.google.devtools.build.lib.skyframe.InconsistentFilesystemException)5 EvalException (com.google.devtools.build.lib.syntax.EvalException)5 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)5 Path (com.google.devtools.build.lib.vfs.Path)4 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)2 Label (com.google.devtools.build.lib.cmdline.Label)2 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)2 Rule (com.google.devtools.build.lib.packages.Rule)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 ImmutableList (com.google.common.collect.ImmutableList)1 MavenServerRule (com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1