Search in sources :

Example 16 with ActionAnalysisMetadata

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

the class PostConfiguredTargetFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
    ImmutableMap<ActionAnalysisMetadata, ConflictException> badActions = PrecomputedValue.BAD_ACTIONS.get(env);
    ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key((ConfiguredTargetKey) skyKey.argument()));
    if (env.valuesMissing()) {
        return null;
    }
    for (ActionAnalysisMetadata action : ctValue.getActions()) {
        if (badActions.containsKey(action)) {
            throw new ActionConflictFunctionException(badActions.get(action));
        }
    }
    ConfiguredTarget ct = ctValue.getConfiguredTarget();
    TargetAndConfiguration ctgValue = new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
    ImmutableMap<Label, ConfigMatchingProvider> configConditions = getConfigurableAttributeConditions(ctgValue, env);
    if (configConditions == null) {
        return null;
    }
    OrderedSetMultimap<Attribute, Dependency> deps;
    try {
        BuildConfiguration hostConfiguration = buildViewProvider.getSkyframeBuildView().getHostConfiguration(ct.getConfiguration());
        SkyframeDependencyResolver resolver = buildViewProvider.getSkyframeBuildView().createDependencyResolver(env);
        // We don't track root causes here - this function is only invoked for successfully analyzed
        // targets - as long as we redo the exact same steps here as in ConfiguredTargetFunction, this
        // can never fail.
        deps = resolver.dependentNodeMap(ctgValue, hostConfiguration, /*aspect=*/
        null, configConditions);
        if (ct.getConfiguration() != null && ct.getConfiguration().useDynamicConfigurations()) {
            deps = ConfiguredTargetFunction.getDynamicConfigurations(env, ctgValue, deps, hostConfiguration, ruleClassProvider);
        }
    } catch (EvalException | ConfiguredTargetFunction.DependencyEvaluationException | InvalidConfigurationException | InconsistentAspectOrderException e) {
        throw new PostConfiguredTargetFunctionException(e);
    }
    env.getValues(Iterables.transform(deps.values(), TO_KEYS));
    if (env.valuesMissing()) {
        return null;
    }
    return new PostConfiguredTargetValue(ct);
}
Also used : ConflictException(com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Dependency(com.google.devtools.build.lib.analysis.Dependency) EvalException(com.google.devtools.build.lib.syntax.EvalException) InconsistentAspectOrderException(com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) TargetAndConfiguration(com.google.devtools.build.lib.analysis.TargetAndConfiguration) ConfigMatchingProvider(com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider) Nullable(javax.annotation.Nullable)

Example 17 with ActionAnalysisMetadata

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

the class CoverageReportFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    Preconditions.checkState(CoverageReportValue.SKY_KEY.equals(skyKey), String.format("Expected %s for SkyKey but got %s instead", CoverageReportValue.SKY_KEY, skyKey));
    ImmutableList<ActionAnalysisMetadata> actions = PrecomputedValue.COVERAGE_REPORT_KEY.get(env);
    if (actions == null) {
        return null;
    }
    ImmutableSet.Builder<Artifact> outputs = new ImmutableSet.Builder<>();
    for (ActionAnalysisMetadata action : actions) {
        outputs.addAll(action.getOutputs());
    }
    return new CoverageReportValue(outputs.build(), actions);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 18 with ActionAnalysisMetadata

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

the class CachingAnalysisEnvironment method getOrphanArtifactMap.

private Map<Artifact, String> getOrphanArtifactMap() {
    // Construct this set to avoid poor performance under large --runs_per_test.
    Set<Artifact> artifactsWithActions = new HashSet<>();
    for (ActionAnalysisMetadata action : actions) {
        // Don't bother checking that every Artifact only appears once; that test is performed
        // elsewhere (see #testNonUniqueOutputs in ActionListenerIntegrationTest).
        artifactsWithActions.addAll(action.getOutputs());
    }
    // The order of the artifacts.entrySet iteration is unspecified - we use a TreeMap here to
    // guarantee that the return value of this method is deterministic.
    Map<Artifact, String> orphanArtifacts = new TreeMap<>(Artifact.EXEC_PATH_COMPARATOR);
    for (Map.Entry<Artifact, String> entry : artifacts.entrySet()) {
        Artifact a = entry.getKey();
        if (!a.isSourceArtifact() && !artifactsWithActions.contains(a)) {
            orphanArtifacts.put(a, String.format("%s\n%s", // uncovered artifact
            a.getExecPathString(), // origin of creation
            entry.getValue()));
        }
    }
    return orphanArtifacts;
}
Also used : ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Artifact(com.google.devtools.build.lib.actions.Artifact) HashSet(java.util.HashSet)

Example 19 with ActionAnalysisMetadata

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

the class CachingAnalysisEnvironment method verifyGeneratedArtifactHaveActions.

/**
   * Sanity checks that all generated artifacts have a generating action.
   * @param target for error reporting
   */
public void verifyGeneratedArtifactHaveActions(Target target) {
    Collection<String> orphanArtifacts = getOrphanArtifactMap().values();
    List<String> checkedActions = null;
    if (!orphanArtifacts.isEmpty()) {
        checkedActions = Lists.newArrayListWithCapacity(actions.size());
        for (ActionAnalysisMetadata action : actions) {
            StringBuilder sb = shortDescription(action);
            for (Artifact o : action.getOutputs()) {
                sb.append("\n    ");
                sb.append(o.getExecPathString());
            }
            checkedActions.add(sb.toString());
        }
        throw new IllegalStateException(String.format("%s %s : These artifacts do not have a generating action:\n%s\n" + "These actions were checked:\n%s\n", target.getTargetKind(), target.getLabel(), Joiner.on('\n').join(orphanArtifacts), Joiner.on('\n').join(checkedActions)));
    }
}
Also used : ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 20 with ActionAnalysisMetadata

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

the class ExtraActionUtils method createExtraActionProvider.

/**
   * Scans {@code action_listeners} associated with this build to see if any
   * {@code extra_actions} should be added to this configured target. If any
   * action_listeners are present, a partial visit of the artifact/action graph
   * is performed (for as long as actions found are owned by this {@link
   * ConfiguredTarget}). Any actions that match the {@code action_listener}
   * get an {@code extra_action} associated. The output artifacts of the
   * extra_action are reported to the {@link AnalysisEnvironment} for
   * bookkeeping.
   */
static ExtraActionArtifactsProvider createExtraActionProvider(Set<ActionAnalysisMetadata> actionsWithoutExtraAction, RuleContext ruleContext) {
    BuildConfiguration configuration = ruleContext.getConfiguration();
    if (configuration.isHostConfiguration()) {
        return ExtraActionArtifactsProvider.EMPTY;
    }
    ImmutableList<Artifact> extraActionArtifacts = ImmutableList.of();
    NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder();
    List<Label> actionListenerLabels = configuration.getActionListeners();
    if (!actionListenerLabels.isEmpty() && ruleContext.attributes().getAttributeDefinition(":action_listener") != null) {
        ExtraActionsVisitor visitor = new ExtraActionsVisitor(ruleContext, computeMnemonicsToExtraActionMap(ruleContext));
        // thus the copy
        for (ActionAnalysisMetadata action : ImmutableList.copyOf(ruleContext.getAnalysisEnvironment().getRegisteredActions())) {
            if (!actionsWithoutExtraAction.contains(action)) {
                visitor.maybeAddExtraAction(action);
            }
        }
        extraActionArtifacts = visitor.getAndResetExtraArtifacts();
        if (!extraActionArtifacts.isEmpty()) {
            builder.addAll(extraActionArtifacts);
        }
    }
    // Add extra action artifacts from dependencies
    for (ExtraActionArtifactsProvider provider : AnalysisUtils.getProviders(ruleContext.getConfiguredTargetMap().values(), ExtraActionArtifactsProvider.class)) {
        builder.addTransitive(provider.getTransitiveExtraActionArtifacts());
    }
    return ExtraActionArtifactsProvider.create(NestedSetBuilder.<Artifact>stableOrder().addAll(extraActionArtifacts).build(), builder.build());
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Label(com.google.devtools.build.lib.cmdline.Label) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact)

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