Search in sources :

Example 1 with SkyValue

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);
}
Also used : SkyValue(com.google.devtools.build.skyframe.SkyValue) RecursivePackageProviderBackedTargetPatternResolver(com.google.devtools.build.lib.skyframe.RecursivePackageProviderBackedTargetPatternResolver) GraphBackedRecursivePackageProvider(com.google.devtools.build.lib.skyframe.GraphBackedRecursivePackageProvider) AutoProfiler(com.google.devtools.build.lib.profiler.AutoProfiler) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with SkyValue

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);
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ImmutableList(com.google.common.collect.ImmutableList) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) IOException(java.io.IOException) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) BuildFileContainsErrorsException(com.google.devtools.build.lib.packages.BuildFileContainsErrorsException) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) QueryException(com.google.devtools.build.lib.query2.engine.QueryException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SkyValue(com.google.devtools.build.skyframe.SkyValue) Entry(java.util.Map.Entry) TransitiveTraversalValue(com.google.devtools.build.lib.skyframe.TransitiveTraversalValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 3 with SkyValue

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();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) Package(com.google.devtools.build.lib.packages.Package) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 4 with SkyValue

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) SkyValue(com.google.devtools.build.skyframe.SkyValue) ImmutableSet(com.google.common.collect.ImmutableSet) ActionLookupValue(com.google.devtools.build.lib.skyframe.ActionLookupValue) ActionLookupKey(com.google.devtools.build.lib.skyframe.ActionLookupValue.ActionLookupKey)

Example 5 with SkyValue

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);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) AbstractAction(com.google.devtools.build.lib.actions.AbstractAction) Action(com.google.devtools.build.lib.actions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

SkyValue (com.google.devtools.build.skyframe.SkyValue)66 SkyKey (com.google.devtools.build.skyframe.SkyKey)63 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)18 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)17 Test (org.junit.Test)16 Artifact (com.google.devtools.build.lib.actions.Artifact)15 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)15 HashMap (java.util.HashMap)14 ImmutableList (com.google.common.collect.ImmutableList)10 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)10 Path (com.google.devtools.build.lib.vfs.Path)9 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)8 LinkedHashMap (java.util.LinkedHashMap)8 Label (com.google.devtools.build.lib.cmdline.Label)7 HashSet (java.util.HashSet)7 Target (com.google.devtools.build.lib.packages.Target)6 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 IOException (java.io.IOException)5 ImmutableSet (com.google.common.collect.ImmutableSet)4