Search in sources :

Example 81 with Artifact

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

the class AspectCompleteEvent method asStreamProto.

@Override
public BuildEventStreamProtos.BuildEvent asStreamProto(PathConverter pathConverter) {
    BuildEventStreamProtos.TargetComplete.Builder builder = BuildEventStreamProtos.TargetComplete.newBuilder();
    builder.setSuccess(!failed());
    if (artifacts != null) {
        for (ArtifactsInOutputGroup artifactsInGroup : artifacts.getAllArtifactsByOutputGroup()) {
            OutputGroup.Builder groupBuilder = OutputGroup.newBuilder();
            groupBuilder.setName(artifactsInGroup.getOutputGroup());
            File.Builder fileBuilder = File.newBuilder();
            for (Artifact artifact : artifactsInGroup.getArtifacts()) {
                String name = artifact.getFilename();
                String uri = pathConverter.apply(artifact.getPath());
                groupBuilder.addOutputFile(fileBuilder.setName(name).setUri(uri).build());
            }
            builder.addOutputGroup(groupBuilder.build());
        }
    }
    return GenericBuildEvent.protoChaining(this).setCompleted(builder.build()).build();
}
Also used : ArtifactsInOutputGroup(com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup) OutputGroup(com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.OutputGroup) ArtifactsInOutputGroup(com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup) File(com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.File) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 82 with Artifact

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

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

the class CommandHelper method buildCommandLineMaybeWithScriptFile.

private static Pair<List<String>, Artifact> buildCommandLineMaybeWithScriptFile(RuleContext ruleContext, String command, String scriptPostFix, PathFragment shellPath) {
    List<String> argv;
    Artifact scriptFileArtifact = null;
    if (command.length() <= maxCommandLength) {
        argv = buildCommandLineSimpleArgv(command, shellPath);
    } else {
        // Use script file.
        scriptFileArtifact = buildCommandLineArtifact(ruleContext, command, scriptPostFix);
        argv = buildCommandLineArgvWithArtifact(scriptFileArtifact, shellPath);
    }
    return Pair.of(argv, scriptFileArtifact);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 84 with Artifact

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

the class CompilationHelper method getMiddlemanInternal.

/**
   * Internal implementation for getAggregatingMiddleman / getAggregatingMiddlemanWithSolibSymlinks.
   */
private static List<Artifact> getMiddlemanInternal(AnalysisEnvironment env, RuleContext ruleContext, ActionOwner actionOwner, String purpose, TransitiveInfoCollection dep) {
    if (dep == null) {
        return ImmutableList.of();
    }
    MiddlemanFactory factory = env.getMiddlemanFactory();
    Iterable<Artifact> artifacts = dep.getProvider(FileProvider.class).getFilesToBuild();
    return ImmutableList.of(factory.createMiddlemanAllowMultiple(env, actionOwner, ruleContext.getPackageDirectory(), purpose, artifacts, ruleContext.getConfiguration().getMiddlemanDirectory(ruleContext.getRule().getRepository())));
}
Also used : MiddlemanFactory(com.google.devtools.build.lib.actions.MiddlemanFactory) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 85 with Artifact

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

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28