Search in sources :

Example 1 with ActionLookupValue

use of com.google.devtools.build.lib.skyframe.ActionLookupValue 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 2 with ActionLookupValue

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

the class BuildView method createResult.

private AnalysisResult createResult(ExtendedEventHandler eventHandler, LoadingResult loadingResult, TopLevelArtifactContext topLevelOptions, BuildView.Options viewOptions, SkyframeAnalysisResult skyframeAnalysisResult) throws InterruptedException {
    Collection<Target> testsToRun = loadingResult.getTestsToRun();
    Collection<ConfiguredTarget> configuredTargets = skyframeAnalysisResult.getConfiguredTargets();
    Collection<AspectValue> aspects = skyframeAnalysisResult.getAspects();
    Collection<ConfiguredTarget> allTargetsToTest = null;
    if (testsToRun != null) {
        // Determine the subset of configured targets that are meant to be run as tests.
        // Do not remove <ConfiguredTarget>: workaround for Java 7 type inference.
        allTargetsToTest = Lists.<ConfiguredTarget>newArrayList(filterTestsByTargets(configuredTargets, Sets.newHashSet(testsToRun)));
    }
    Set<Artifact> artifactsToBuild = new HashSet<>();
    Set<ConfiguredTarget> parallelTests = new HashSet<>();
    Set<ConfiguredTarget> exclusiveTests = new HashSet<>();
    // build-info and build-changelist.
    Collection<Artifact> buildInfoArtifacts = skyframeExecutor.getWorkspaceStatusArtifacts(eventHandler);
    Preconditions.checkState(buildInfoArtifacts.size() == 2, buildInfoArtifacts);
    artifactsToBuild.addAll(buildInfoArtifacts);
    // Extra actions
    addExtraActionsIfRequested(viewOptions, configuredTargets, aspects, artifactsToBuild);
    // Coverage
    NestedSet<Artifact> baselineCoverageArtifacts = getBaselineCoverageArtifacts(configuredTargets);
    Iterables.addAll(artifactsToBuild, baselineCoverageArtifacts);
    if (coverageReportActionFactory != null) {
        CoverageReportActionsWrapper actionsWrapper;
        actionsWrapper = coverageReportActionFactory.createCoverageReportActionsWrapper(eventHandler, directories, allTargetsToTest, baselineCoverageArtifacts, getArtifactFactory(), CoverageReportValue.ARTIFACT_OWNER);
        if (actionsWrapper != null) {
            ImmutableList<ActionAnalysisMetadata> actions = actionsWrapper.getActions();
            skyframeExecutor.injectCoverageReportData(actions);
            artifactsToBuild.addAll(actionsWrapper.getCoverageOutputs());
        }
    }
    // Tests. This must come last, so that the exclusive tests are scheduled after everything else.
    scheduleTestsIfRequested(parallelTests, exclusiveTests, topLevelOptions, allTargetsToTest);
    String error = createErrorMessage(loadingResult, skyframeAnalysisResult);
    final WalkableGraph graph = skyframeAnalysisResult.getWalkableGraph();
    final ActionGraph actionGraph = new ActionGraph() {

        @Nullable
        @Override
        public ActionAnalysisMetadata getGeneratingAction(Artifact artifact) {
            ArtifactOwner artifactOwner = artifact.getArtifactOwner();
            if (artifactOwner instanceof ActionLookupValue.ActionLookupKey) {
                SkyKey key = ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner);
                ActionLookupValue val;
                try {
                    val = (ActionLookupValue) graph.getValue(key);
                } catch (InterruptedException e) {
                    throw new IllegalStateException("Interruption not expected from this graph: " + key, e);
                }
                return val == null ? null : val.getGeneratingAction(artifact);
            }
            return null;
        }
    };
    return new AnalysisResult(configuredTargets, aspects, allTargetsToTest, error, actionGraph, artifactsToBuild, parallelTests, exclusiveTests, topLevelOptions, skyframeAnalysisResult.getPackageRoots(), loadingResult.getWorkspaceName());
}
Also used : Target(com.google.devtools.build.lib.packages.Target) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SkyKey(com.google.devtools.build.skyframe.SkyKey) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) ActionGraph(com.google.devtools.build.lib.actions.ActionGraph) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact) SkyframeAnalysisResult(com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) CoverageReportActionsWrapper(com.google.devtools.build.lib.rules.test.CoverageReportActionFactory.CoverageReportActionsWrapper) ActionLookupValue(com.google.devtools.build.lib.skyframe.ActionLookupValue)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)2 ActionLookupValue (com.google.devtools.build.lib.skyframe.ActionLookupValue)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 Target (com.google.devtools.build.lib.packages.Target)1 CoverageReportActionsWrapper (com.google.devtools.build.lib.rules.test.CoverageReportActionFactory.CoverageReportActionsWrapper)1 ActionLookupKey (com.google.devtools.build.lib.skyframe.ActionLookupValue.ActionLookupKey)1 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)1 SkyframeAnalysisResult (com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult)1 SkyValue (com.google.devtools.build.skyframe.SkyValue)1 WalkableGraph (com.google.devtools.build.skyframe.WalkableGraph)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1