Search in sources :

Example 1 with OwnedArtifact

use of com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact 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

Action (com.google.devtools.build.lib.actions.Action)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 MissingInputFileException (com.google.devtools.build.lib.actions.MissingInputFileException)1 ActionTemplate (com.google.devtools.build.lib.analysis.actions.ActionTemplate)1 OwnedArtifact (com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact)1 IOException (java.io.IOException)1