Search in sources :

Example 1 with ArtifactOwner

use of com.google.devtools.build.lib.actions.ArtifactOwner 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)

Example 2 with ArtifactOwner

use of com.google.devtools.build.lib.actions.ArtifactOwner in project bazel by bazelbuild.

the class ArtifactFunction method extractActionFromArtifact.

private static ActionAnalysisMetadata extractActionFromArtifact(Artifact artifact, SkyFunction.Environment env) throws InterruptedException {
    ArtifactOwner artifactOwner = artifact.getArtifactOwner();
    Preconditions.checkState(artifactOwner instanceof ActionLookupKey, "", artifact, artifactOwner);
    SkyKey actionLookupKey = ActionLookupValue.key((ActionLookupKey) artifactOwner);
    ActionLookupValue value = (ActionLookupValue) env.getValue(actionLookupKey);
    if (value == null) {
        Preconditions.checkState(artifactOwner == CoverageReportValue.ARTIFACT_OWNER, "Not-yet-present artifact owner: %s", artifactOwner);
        return null;
    }
    // The value should already exist (except for the coverage report action output artifacts):
    // ConfiguredTargetValues were created during the analysis phase, and BuildInfo*Values
    // were created during the first analysis of a configured target.
    Preconditions.checkNotNull(value, "Owner %s of %s not in graph %s", artifactOwner, artifact, actionLookupKey);
    ActionAnalysisMetadata action = value.getGeneratingAction(artifact);
    if (artifact.hasParent()) {
        // generating action for its parent TreeArtifact, which contains this TreeFileArtifact.
        if (action == null) {
            action = value.getGeneratingAction(artifact.getParent());
        }
    }
    return Preconditions.checkNotNull(action, "Value %s does not contain generating action of %s", value, artifact);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) ActionLookupKey(com.google.devtools.build.lib.skyframe.ActionLookupValue.ActionLookupKey)

Example 3 with ArtifactOwner

use of com.google.devtools.build.lib.actions.ArtifactOwner in project bazel by bazelbuild.

the class SkyframeExecutor method getGeneratingAction.

/** Returns the generating action of a given artifact ({@code null} if it's a source artifact). */
private ActionAnalysisMetadata getGeneratingAction(ExtendedEventHandler eventHandler, Artifact artifact) throws InterruptedException {
    if (artifact.isSourceArtifact()) {
        return null;
    }
    ArtifactOwner artifactOwner = artifact.getArtifactOwner();
    Preconditions.checkState(artifactOwner instanceof ActionLookupValue.ActionLookupKey, "%s %s", artifact, artifactOwner);
    SkyKey actionLookupKey = ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner);
    synchronized (valueLookupLock) {
        // Note that this will crash (attempting to run a configured target value builder after
        // analysis) after a failed --nokeep_going analysis in which the configured target that
        // failed was a (transitive) dependency of the configured target that should generate
        // this action. We don't expect callers to query generating actions in such cases.
        EvaluationResult<ActionLookupValue> result = buildDriver.evaluate(ImmutableList.of(actionLookupKey), false, ResourceUsage.getAvailableProcessors(), eventHandler);
        return result.hasError() ? null : result.get(actionLookupKey).getGeneratingAction(artifact);
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner)

Example 4 with ArtifactOwner

use of com.google.devtools.build.lib.actions.ArtifactOwner in project bazel by bazelbuild.

the class ConfiguredTargetFactory method getOutputArtifact.

private Artifact getOutputArtifact(OutputFile outputFile, BuildConfiguration configuration, boolean isFileset, ArtifactFactory artifactFactory) {
    Rule rule = outputFile.getAssociatedRule();
    Root root = rule.hasBinaryOutput() ? configuration.getBinDirectory(rule.getRepository()) : configuration.getGenfilesDirectory(rule.getRepository());
    ArtifactOwner owner = new ConfiguredTargetKey(rule.getLabel(), configuration.getArtifactOwnerConfiguration());
    PathFragment rootRelativePath = outputFile.getLabel().getPackageIdentifier().getSourceRoot().getRelative(outputFile.getLabel().getName());
    Artifact result = isFileset ? artifactFactory.getFilesetArtifact(rootRelativePath, root, owner) : artifactFactory.getDerivedArtifact(rootRelativePath, root, owner);
    // The associated rule should have created the artifact.
    Preconditions.checkNotNull(result, "no artifact for %s", rootRelativePath);
    return result;
}
Also used : ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) Root(com.google.devtools.build.lib.actions.Root) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 5 with ArtifactOwner

use of com.google.devtools.build.lib.actions.ArtifactOwner in project bazel by bazelbuild.

the class ActionTemplateExpansionFunctionTest method testActionTemplateExpansionFunction.

@Test
public void testActionTemplateExpansionFunction() throws Exception {
    Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
    Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
    SpawnActionTemplate spawnActionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(inputTreeArtifact, outputTreeArtifact);
    List<Action> actions = evaluate(spawnActionTemplate);
    assertThat(actions).hasSize(3);
    ArtifactOwner owner = ActionTemplateExpansionValue.createActionTemplateExpansionKey(spawnActionTemplate);
    int i = 0;
    for (Action action : actions) {
        String childName = "child" + i;
        assertThat(Artifact.toExecPaths(action.getInputs())).contains("out/inputTreeArtifact/" + childName);
        assertThat(Artifact.toExecPaths(action.getOutputs())).containsExactly("out/outputTreeArtifact/" + childName);
        assertThat(Iterables.getOnlyElement(action.getOutputs()).getArtifactOwner()).isEqualTo(owner);
        ++i;
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) OwnedArtifact(com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Aggregations

ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)6 Artifact (com.google.devtools.build.lib.actions.Artifact)3 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)2 Root (com.google.devtools.build.lib.actions.Root)2 Rule (com.google.devtools.build.lib.packages.Rule)2 ConfiguredTargetKey (com.google.devtools.build.lib.skyframe.ConfiguredTargetKey)2 Action (com.google.devtools.build.lib.actions.Action)1 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)1 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 SpawnActionTemplate (com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)1 Target (com.google.devtools.build.lib.packages.Target)1 CoverageReportActionsWrapper (com.google.devtools.build.lib.rules.test.CoverageReportActionFactory.CoverageReportActionsWrapper)1 ActionLookupValue (com.google.devtools.build.lib.skyframe.ActionLookupValue)1 ActionLookupKey (com.google.devtools.build.lib.skyframe.ActionLookupValue.ActionLookupKey)1 OwnedArtifact (com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact)1