Search in sources :

Example 1 with ActionAnalysisMetadata

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

the class ActionsTestUtil method assertPrimaryInputAndOutputArtifacts.

/**
   * Assert that an artifact is the primary output of its generating action.
   */
public void assertPrimaryInputAndOutputArtifacts(Artifact input, Artifact output) {
    ActionAnalysisMetadata generatingAction = actionGraph.getGeneratingAction(output);
    assertThat(generatingAction).isNotNull();
    assertThat(generatingAction.getPrimaryOutput()).isEqualTo(output);
    assertThat(generatingAction.getPrimaryInput()).isEqualTo(input);
}
Also used : ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata)

Example 2 with ActionAnalysisMetadata

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

the class ActionsTestUtil method findTransitivePrerequisitesOf.

/**
   * Finds all the actions that are instances of <code>actionClass</code>
   * in the transitive closure of prerequisites.
   */
public <A extends Action> List<A> findTransitivePrerequisitesOf(Artifact artifact, Class<A> actionClass, Predicate<Artifact> allowedArtifacts) {
    List<A> actions = new ArrayList<>();
    Set<Artifact> visited = new LinkedHashSet<>();
    List<Artifact> toVisit = new LinkedList<>();
    toVisit.add(artifact);
    while (!toVisit.isEmpty()) {
        Artifact current = toVisit.remove(0);
        if (!visited.add(current)) {
            continue;
        }
        ActionAnalysisMetadata generatingAction = actionGraph.getGeneratingAction(current);
        if (generatingAction != null) {
            Iterables.addAll(toVisit, Iterables.filter(generatingAction.getInputs(), allowedArtifacts));
            if (actionClass.isInstance(generatingAction)) {
                actions.add(actionClass.cast(generatingAction));
            }
        }
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) LinkedList(java.util.LinkedList)

Example 3 with ActionAnalysisMetadata

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

the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionCreatesSpawnAction.

@Test
public void testCreateSpawnActionCreatesSpawnAction() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    createTestSpawnAction(ruleContext);
    ActionAnalysisMetadata action = Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
    assertThat(action).isInstanceOf(SpawnAction.class);
}
Also used : ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 4 with ActionAnalysisMetadata

use of com.google.devtools.build.lib.actions.ActionAnalysisMetadata 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 5 with ActionAnalysisMetadata

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

the class ArtifactFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws ArtifactFunctionException, InterruptedException {
    OwnedArtifact ownedArtifact = (OwnedArtifact) skyKey.argument();
    Artifact artifact = ownedArtifact.getArtifact();
    if (artifact.isSourceArtifact()) {
        try {
            return createSourceValue(artifact, ownedArtifact.isMandatory(), env);
        } catch (MissingInputFileException e) {
            // is potentially used to report root causes.
            throw new ArtifactFunctionException(e, Transience.TRANSIENT);
        }
    }
    ActionAnalysisMetadata actionMetadata = extractActionFromArtifact(artifact, env);
    if (actionMetadata == null) {
        return null;
    }
    // actions, execute those actions in parallel and then aggregate the action execution results.
    if (artifact.isTreeArtifact() && actionMetadata instanceof ActionTemplate) {
        // Create the directory structures for the output TreeArtifact first.
        try {
            FileSystemUtils.createDirectoryAndParents(artifact.getPath());
        } catch (IOException e) {
            env.getListener().handle(Event.error(String.format("Failed to create output directory for TreeArtifact %s: %s", artifact, e.getMessage())));
            throw new ArtifactFunctionException(e, Transience.TRANSIENT);
        }
        return createTreeArtifactValueFromActionTemplate((ActionTemplate) actionMetadata, artifact, env);
    } else {
        Preconditions.checkState(actionMetadata instanceof Action, "%s is not a proper Action object and therefore cannot be executed", actionMetadata);
        Action action = (Action) actionMetadata;
        ActionExecutionValue actionValue = (ActionExecutionValue) env.getValue(ActionExecutionValue.key(action));
        if (actionValue == null) {
            return null;
        }
        if (artifact.isTreeArtifact()) {
            // TreeArtifactValue.
            return Preconditions.checkNotNull(actionValue.getTreeArtifactValue(artifact), artifact);
        } else if (isAggregatingValue(action)) {
            return createAggregatingValue(artifact, action, actionValue.getArtifactValue(artifact), env);
        } else {
            return createSimpleFileArtifactValue(artifact, action, actionValue, env);
        }
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) IOException(java.io.IOException) ActionTemplate(com.google.devtools.build.lib.analysis.actions.ActionTemplate) OwnedArtifact(com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact) 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) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException)

Aggregations

ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)24 Artifact (com.google.devtools.build.lib.actions.Artifact)16 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)6 Action (com.google.devtools.build.lib.actions.Action)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)4 ActionConflictException (com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)4 Map (java.util.Map)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)3 Label (com.google.devtools.build.lib.cmdline.Label)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Test (org.junit.Test)3 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)2 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)2 MutableActionGraph (com.google.devtools.build.lib.actions.MutableActionGraph)2 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)2 ConflictException (com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException)2