use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class SkyQueryEnvironment method beforeEvaluateQuery.
private void beforeEvaluateQuery() throws InterruptedException {
if (graph == null || !graphFactory.isUpToDate(universeKey)) {
// If this environment is uninitialized or the graph factory needs to evaluate, do so. We
// assume here that this environment cannot be initialized-but-stale if the factory is up
// to date.
EvaluationResult<SkyValue> result;
try (AutoProfiler p = AutoProfiler.logged("evaluation and walkable graph", LOG)) {
result = graphFactory.prepareAndGet(universeKey, loadingPhaseThreads, universeEvalEventHandler);
}
checkEvaluationResult(result);
packageSemaphore = makeFreshPackageMultisetSemaphore();
graph = result.getWalkableGraph();
blacklistPatternsSupplier = InterruptibleSupplier.Memoize.of(new BlacklistSupplier(graph));
graphBackedRecursivePackageProvider = new GraphBackedRecursivePackageProvider(graph, universeTargetPatternKeys, pkgPath);
}
if (executor == null) {
executor = MoreExecutors.listeningDecorator(new ThreadPoolExecutor(/*corePoolSize=*/
queryEvaluationParallelismLevel, /*maximumPoolSize=*/
queryEvaluationParallelismLevel, /*keepAliveTime=*/
1, /*units=*/
TimeUnit.SECONDS, /*workQueue=*/
new BlockingStack<Runnable>(), new ThreadFactoryBuilder().setNameFormat("QueryEnvironment %d").build()));
}
resolver = new RecursivePackageProviderBackedTargetPatternResolver(graphBackedRecursivePackageProvider, eventHandler, TargetPatternEvaluator.DEFAULT_FILTERING_POLICY, packageSemaphore);
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class SkyQueryEnvironment method buildTransitiveClosure.
@Override
public void buildTransitiveClosure(QueryExpression caller, Set<Target> targets, int maxDepth) throws QueryException, InterruptedException {
// Everything has already been loaded, so here we just check for errors so that we can
// pre-emptively throw/report if needed.
Iterable<SkyKey> transitiveTraversalKeys = makeTransitiveTraversalKeys(targets);
ImmutableList.Builder<String> errorMessagesBuilder = ImmutableList.builder();
// First, look for errors in the successfully evaluated TransitiveTraversalValues. They may
// have encountered errors that they were able to recover from.
Set<Entry<SkyKey, SkyValue>> successfulEntries = graph.getSuccessfulValues(transitiveTraversalKeys).entrySet();
Builder<SkyKey> successfulKeysBuilder = ImmutableSet.builder();
for (Entry<SkyKey, SkyValue> successfulEntry : successfulEntries) {
successfulKeysBuilder.add(successfulEntry.getKey());
TransitiveTraversalValue value = (TransitiveTraversalValue) successfulEntry.getValue();
String firstErrorMessage = value.getFirstErrorMessage();
if (firstErrorMessage != null) {
errorMessagesBuilder.add(firstErrorMessage);
}
}
ImmutableSet<SkyKey> successfulKeys = successfulKeysBuilder.build();
// Next, look for errors from the unsuccessfully evaluated TransitiveTraversal skyfunctions.
Iterable<SkyKey> unsuccessfulKeys = Iterables.filter(transitiveTraversalKeys, Predicates.not(Predicates.in(successfulKeys)));
Set<Entry<SkyKey, Exception>> errorEntries = graph.getMissingAndExceptions(unsuccessfulKeys).entrySet();
for (Map.Entry<SkyKey, Exception> entry : errorEntries) {
if (entry.getValue() == null) {
// Targets may be in the graph because they are not in the universe or depend on cycles.
eventHandler.handle(Event.warn(entry.getKey().argument() + " does not exist in graph"));
} else {
errorMessagesBuilder.add(entry.getValue().getMessage());
}
}
// Lastly, report all found errors.
ImmutableList<String> errorMessages = errorMessagesBuilder.build();
for (String errorMessage : errorMessages) {
reportBuildFileError(caller, errorMessage);
}
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class SkyQueryEnvironment method bulkGetPackages.
@ThreadSafe
public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) throws InterruptedException {
Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));
ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
for (Map.Entry<SkyKey, SkyValue> pkgEntry : packages.entrySet()) {
PackageIdentifier pkgId = (PackageIdentifier) pkgEntry.getKey().argument();
PackageValue pkgValue = (PackageValue) pkgEntry.getValue();
pkgResults.put(pkgId, Preconditions.checkNotNull(pkgValue.getPackage(), pkgId));
}
return pkgResults.build();
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class CppCompileAction method discoverInputsStage2.
@Override
public Iterable<Artifact> discoverInputsStage2(SkyFunction.Environment env) throws ActionExecutionException, InterruptedException {
if (this.usedModules == null) {
return null;
}
Map<Artifact, SkyKey> skyKeys = new HashMap<>();
for (Artifact artifact : this.usedModules) {
skyKeys.put(artifact, ActionLookupValue.key((ActionLookupKey) artifact.getArtifactOwner()));
}
Map<SkyKey, SkyValue> skyValues = env.getValues(skyKeys.values());
Set<Artifact> additionalModules = Sets.newLinkedHashSet();
for (Artifact artifact : this.usedModules) {
SkyKey skyKey = skyKeys.get(artifact);
ActionLookupValue value = (ActionLookupValue) skyValues.get(skyKey);
Preconditions.checkNotNull(value, "Owner %s of %s not in graph %s", artifact.getArtifactOwner(), artifact, skyKey);
CppCompileAction action = (CppCompileAction) value.getGeneratingAction(artifact);
for (Artifact input : action.getInputs()) {
if (CppFileTypes.CPP_MODULE.matches(input.getFilename())) {
additionalModules.add(input);
}
}
}
ImmutableSet.Builder<Artifact> topLevelModules = ImmutableSet.builder();
for (Artifact artifact : this.usedModules) {
if (!additionalModules.contains(artifact)) {
topLevelModules.add(artifact);
}
}
this.topLevelModules = topLevelModules.build();
this.additionalInputs = new ImmutableList.Builder<Artifact>().addAll(this.additionalInputs).addAll(additionalModules).build();
this.usedModules = null;
return additionalModules;
}
use of com.google.devtools.build.skyframe.SkyValue in project bazel by bazelbuild.
the class SkyframeAwareActionTest method assertActionExecutions.
private void assertActionExecutions(ExecutionCountingActionFactory actionFactory, ChangeArtifact changeActionInput, Callable<Void> betweenBuilds, ExpectActionIs expectActionIs) throws Exception {
// Set up the action's input, output, owner and most importantly the execution counter.
Artifact actionInput = createSourceArtifact("foo/action-input.txt");
Artifact actionOutput = createDerivedArtifact("foo/action-output.txt");
AtomicInteger executionCounter = new AtomicInteger(0);
scratch.file(actionInput.getPath().getPathString(), "foo");
// Generating actions of artifacts are found by looking them up in the graph. The lookup value
// must be present in the graph before execution.
Action action = actionFactory.create(actionInput, actionOutput, executionCounter);
registerAction(action);
// Build the output for the first time.
builder.buildArtifacts(reporter, ImmutableSet.of(actionOutput), null, null, null, null, executor, null, false, null, null);
// Sanity check that our invalidation receiver is working correctly. We'll rely on it again.
SkyKey actionKey = ActionExecutionValue.key(action);
TrackingEvaluationProgressReceiver.EvaluatedEntry evaluatedAction = progressReceiver.getEvalutedEntry(actionKey);
assertThat(evaluatedAction).isNotNull();
SkyValue actionValue = evaluatedAction.value;
// Mutate the action input if requested.
maybeChangeFile(actionInput, changeActionInput);
// Execute user code before next build.
betweenBuilds.call();
// Rebuild the output.
progressReceiver.reset();
builder.buildArtifacts(reporter, ImmutableSet.of(actionOutput), null, null, null, null, executor, null, false, null, null);
if (expectActionIs.dirtied()) {
assertThat(progressReceiver.wasInvalidated(actionKey)).isTrue();
TrackingEvaluationProgressReceiver.EvaluatedEntry newEntry = progressReceiver.getEvalutedEntry(actionKey);
assertThat(newEntry).isNotNull();
if (expectActionIs.actuallyClean()) {
// Action was dirtied but verified clean.
assertThat(newEntry.state).isEqualTo(EvaluationState.CLEAN);
assertThat(newEntry.value).isEqualTo(actionValue);
} else {
// Action was dirtied and rebuilt. It was either reexecuted or was an action cache hit,
// doesn't matter here.
assertThat(newEntry.state).isEqualTo(EvaluationState.BUILT);
assertThat(newEntry.value).isNotEqualTo(actionValue);
}
} else {
// Action was not dirtied.
assertThat(progressReceiver.wasInvalidated(actionKey)).isFalse();
}
// Assert that the action was executed the right number of times. Whether the action execution
// function was called again is up for the test method to verify.
assertThat(executionCounter.get()).isEqualTo(expectActionIs.reexecuted() ? 2 : 1);
}
Aggregations