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);
}
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);
}
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;
}
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)));
}
}
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());
}
Aggregations