Search in sources :

Example 6 with ActionAnalysisMetadata

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

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

the class ConfiguredTargetFunction method createConfiguredTarget.

@Nullable
private ConfiguredTargetValue createConfiguredTarget(SkyframeBuildView view, Environment env, Target target, BuildConfiguration configuration, OrderedSetMultimap<Attribute, ConfiguredTarget> depValueMap, ImmutableMap<Label, ConfigMatchingProvider> configConditions, NestedSetBuilder<Package> transitivePackages) throws ConfiguredTargetFunctionException, InterruptedException {
    StoredEventHandler events = new StoredEventHandler();
    BuildConfiguration ownerConfig = (configuration == null) ? null : configuration.getArtifactOwnerConfiguration();
    CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(new ConfiguredTargetKey(target.getLabel(), ownerConfig), false, events, env, configuration);
    if (env.valuesMissing()) {
        return null;
    }
    Preconditions.checkNotNull(depValueMap);
    ConfiguredTarget configuredTarget = view.createConfiguredTarget(target, configuration, analysisEnvironment, depValueMap, configConditions);
    events.replayOn(env.getListener());
    if (events.hasErrors()) {
        analysisEnvironment.disable(target);
        throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException("Analysis of target '" + target.getLabel() + "' failed; build aborted", target.getLabel()));
    }
    Preconditions.checkState(!analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported");
    if (env.valuesMissing()) {
        return null;
    }
    analysisEnvironment.disable(target);
    Preconditions.checkNotNull(configuredTarget, target);
    ImmutableMap<Artifact, ActionAnalysisMetadata> generatingActions;
    // rule implementation).
    try {
        generatingActions = Actions.filterSharedActionsAndThrowActionConflict(analysisEnvironment.getRegisteredActions());
    } catch (ActionConflictException e) {
        throw new ConfiguredTargetFunctionException(e);
    }
    return new ConfiguredTargetValue(configuredTarget, generatingActions, transitivePackages.build());
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) CachingAnalysisEnvironment(com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment) Artifact(com.google.devtools.build.lib.actions.Artifact) Nullable(javax.annotation.Nullable)

Example 8 with ActionAnalysisMetadata

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

the class CrosstoolCompilationSupport method registerHeaderScanningActions.

private void registerHeaderScanningActions(Info info, ObjcProvider objcProvider, CompilationArtifacts compilationArtifacts) {
    // PIC is not used for Obj-C builds, if that changes this method will need to change
    if (!isHeaderThinningEnabled() || info.getCcCompilationOutputs().getObjectFiles(false).isEmpty()) {
        return;
    }
    ImmutableList.Builder<ObjcHeaderThinningInfo> headerThinningInfos = ImmutableList.builder();
    AnalysisEnvironment analysisEnvironment = ruleContext.getAnalysisEnvironment();
    for (Artifact objectFile : info.getCcCompilationOutputs().getObjectFiles(false)) {
        ActionAnalysisMetadata generatingAction = analysisEnvironment.getLocalGeneratingAction(objectFile);
        if (generatingAction instanceof CppCompileAction) {
            CppCompileAction action = (CppCompileAction) generatingAction;
            Artifact sourceFile = action.getSourceFile();
            if (!sourceFile.isTreeArtifact() && SOURCES_FOR_HEADER_THINNING.matches(sourceFile.getFilename())) {
                headerThinningInfos.add(new ObjcHeaderThinningInfo(sourceFile, intermediateArtifacts.headersListFile(sourceFile), action.getCompilerOptions()));
            }
        }
    }
    registerHeaderScanningActions(headerThinningInfos.build(), objcProvider, compilationArtifacts);
}
Also used : AnalysisEnvironment(com.google.devtools.build.lib.analysis.AnalysisEnvironment) ImmutableList(com.google.common.collect.ImmutableList) CppCompileAction(com.google.devtools.build.lib.rules.cpp.CppCompileAction) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 9 with ActionAnalysisMetadata

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

the class BuildViewTestCase method getGeneratingAction.

protected final Action getGeneratingAction(Artifact artifact) {
    Preconditions.checkNotNull(artifact);
    ActionAnalysisMetadata action = mutableActionGraph.getGeneratingAction(artifact);
    if (action == null) {
        action = getActionGraph().getGeneratingAction(artifact);
    }
    if (action != null) {
        Preconditions.checkState(action instanceof Action, "%s is not a proper Action object", action.prettyPrint());
        return (Action) action;
    } else {
        return null;
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) SourceManifestAction(com.google.devtools.build.lib.analysis.SourceManifestAction) ExtraAction(com.google.devtools.build.lib.rules.extra.ExtraAction) PseudoAction(com.google.devtools.build.lib.analysis.PseudoAction) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) SymlinkTreeAction(com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction) WorkspaceStatusAction(com.google.devtools.build.lib.analysis.WorkspaceStatusAction) BaselineCoverageAction(com.google.devtools.build.lib.rules.test.BaselineCoverageAction) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata)

Example 10 with ActionAnalysisMetadata

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

the class AnalysisTestCase method getGeneratingAction.

protected Action getGeneratingAction(Artifact artifact) {
    ensureUpdateWasCalled();
    ActionAnalysisMetadata action = analysisResult.getActionGraph().getGeneratingAction(artifact);
    if (action != null) {
        Preconditions.checkState(action instanceof Action, "%s is not a proper Action object", action.prettyPrint());
        return (Action) action;
    } else {
        return null;
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata)

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