use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class FilesystemValueChecker method getDirtyValues.
private BatchDirtyResult getDirtyValues(ValueFetcher fetcher, Iterable<SkyKey> keys, final SkyValueDirtinessChecker checker, final boolean checkMissingValues) throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(DIRTINESS_CHECK_THREADS, new ThreadFactoryBuilder().setNameFormat("FileSystem Value Invalidator %d").build());
final BatchDirtyResult batchResult = new BatchDirtyResult();
ThrowableRecordingRunnableWrapper wrapper = new ThrowableRecordingRunnableWrapper("FilesystemValueChecker#getDirtyValues");
final AtomicInteger numKeysScanned = new AtomicInteger(0);
final AtomicInteger numKeysChecked = new AtomicInteger(0);
ElapsedTimeReceiver elapsedTimeReceiver = new ElapsedTimeReceiver() {
@Override
public void accept(long elapsedTimeNanos) {
if (elapsedTimeNanos > 0) {
LOG.info(String.format("Spent %d ms checking %d filesystem nodes (%d scanned)", TimeUnit.MILLISECONDS.convert(elapsedTimeNanos, TimeUnit.NANOSECONDS), numKeysChecked.get(), numKeysScanned.get()));
}
}
};
try (AutoProfiler prof = AutoProfiler.create(elapsedTimeReceiver)) {
for (final SkyKey key : keys) {
numKeysScanned.incrementAndGet();
if (!checker.applies(key)) {
continue;
}
final SkyValue value = fetcher.get(key);
if (!checkMissingValues && value == null) {
continue;
}
executor.execute(wrapper.wrap(new Runnable() {
@Override
public void run() {
numKeysChecked.incrementAndGet();
DirtyResult result = checker.check(key, value, tsgm);
if (result.isDirty()) {
batchResult.add(key, value, result.getNewValue());
}
}
}));
}
boolean interrupted = ExecutorUtil.interruptibleShutdown(executor);
Throwables.propagateIfPossible(wrapper.getFirstThrownError());
if (interrupted) {
throw new InterruptedException();
}
}
return batchResult;
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class ArtifactFunction method createTreeArtifactValueFromActionTemplate.
private static TreeArtifactValue createTreeArtifactValueFromActionTemplate(ActionTemplate actionTemplate, Artifact treeArtifact, Environment env) throws ArtifactFunctionException, InterruptedException {
// Request the list of expanded actions from the ActionTemplate.
ActionTemplateExpansionValue expansionValue = (ActionTemplateExpansionValue) env.getValue(ActionTemplateExpansionValue.key(actionTemplate));
// The expanded actions are not yet available.
if (env.valuesMissing()) {
return null;
}
// Execute the expanded actions in parallel.
Iterable<SkyKey> expandedActionExecutionKeys = ActionExecutionValue.keys(expansionValue.getExpandedActions());
Map<SkyKey, SkyValue> expandedActionValueMap = env.getValues(expandedActionExecutionKeys);
// The execution values of the expanded actions are not yet all available.
if (env.valuesMissing()) {
return null;
}
// Aggregate the ArtifactValues for individual TreeFileArtifacts into a TreeArtifactValue for
// the parent TreeArtifact.
ImmutableMap.Builder<TreeFileArtifact, FileArtifactValue> map = ImmutableMap.builder();
for (Map.Entry<SkyKey, SkyValue> entry : expandedActionValueMap.entrySet()) {
SkyKey expandedActionExecutionKey = entry.getKey();
ActionExecutionValue actionExecutionValue = (ActionExecutionValue) entry.getValue();
Action expandedAction = (Action) expandedActionExecutionKey.argument();
Iterable<TreeFileArtifact> treeFileArtifacts = findActionOutputsWithMatchingParent(expandedAction, treeArtifact);
Preconditions.checkState(!Iterables.isEmpty(treeFileArtifacts), "Action %s does not output TreeFileArtifact under %s", expandedAction, treeArtifact);
for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
FileArtifactValue value = createSimpleFileArtifactValue(treeFileArtifact, expandedAction, actionExecutionValue, env);
map.put(treeFileArtifact, value);
}
}
// Return the aggregated TreeArtifactValue.
return TreeArtifactValue.create(map.build());
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class ArtifactFunctionTest method evaluateArtifactValue.
private SkyValue evaluateArtifactValue(Artifact artifact, boolean mandatory) throws Throwable {
SkyKey key = ArtifactSkyKey.key(artifact, mandatory);
EvaluationResult<SkyValue> result = evaluate(ImmutableList.of(key).toArray(new SkyKey[0]));
if (result.hasError()) {
throw result.getError().getException();
}
return result.get(key);
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class FileFunctionTest method testAbsoluteSymlinksToFilesOutsideRootWhenExternalAssumedNonExistentAndImmutable.
@Test
public void testAbsoluteSymlinksToFilesOutsideRootWhenExternalAssumedNonExistentAndImmutable() throws Exception {
file("/outsideroot");
symlink("a", "/outsideroot");
SequentialBuildDriver driver = makeDriver(ExternalFileAction.ASSUME_NON_EXISTENT_AND_IMMUTABLE_FOR_EXTERNAL_PATHS);
SkyKey key = skyKey("a");
EvaluationResult<SkyValue> result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
assertThatEvaluationResult(result).hasNoError();
FileValue value = (FileValue) result.get(key);
assertThat(value).isNotNull();
assertFalse(value.exists());
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class FileFunctionTest method assertChangesIfChanges.
/**
* Asserts that if the contents of {@code changedPathString} changes, then the FileValue
* corresponding to {@code pathString} will change. Returns the paths of all files seen. Not meant
* to be called directly by tests.
*/
private Set<RootedPath> assertChangesIfChanges(String changedPathString, boolean isFile, boolean changes, String pathString) throws Exception {
SequentialBuildDriver driver = makeDriver();
SkyKey key = skyKey(pathString);
EvaluationResult<SkyValue> result;
result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
if (result.hasError()) {
fail(String.format("Evaluation error for %s: %s", key, result.getError()));
}
SkyValue oldValue = result.get(key);
Pair<ImmutableList<String>, Runnable> changeResult = change(changedPathString, isFile);
ImmutableList<String> changedPathStrings = changeResult.first;
Runnable undoCallback = changeResult.second;
differencer.invalidate(Iterables.transform(changedPathStrings, new Function<String, SkyKey>() {
@Override
public SkyKey apply(String input) {
return fileStateSkyKey(input);
}
}));
result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
if (result.hasError()) {
fail(String.format("Evaluation error for %s: %s", key, result.getError()));
}
SkyValue newValue = result.get(key);
assertTrue(String.format("Changing the contents of %s %s should%s change the value for file %s.", isFile ? "file" : "directory", changedPathString, changes ? "" : " not", pathString), changes != newValue.equals(oldValue));
// Restore the original file.
undoCallback.run();
return filesSeen(driver.getGraphForTesting());
}
Aggregations