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();
}
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;
}
}
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);
}
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;
}
Aggregations