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());
}
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);
}
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())));
}
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);
}
}
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class ArtifactFunction method createAggregatingValue.
private static AggregatingArtifactValue createAggregatingValue(Artifact artifact, ActionAnalysisMetadata action, FileArtifactValue value, SkyFunction.Environment env) throws InterruptedException {
// This artifact aggregates other artifacts. Keep track of them so callers can find them.
ImmutableList.Builder<Pair<Artifact, FileArtifactValue>> inputs = ImmutableList.builder();
for (Map.Entry<SkyKey, SkyValue> entry : env.getValues(ArtifactSkyKey.mandatoryKeys(action.getInputs())).entrySet()) {
Artifact input = ArtifactSkyKey.artifact(entry.getKey());
SkyValue inputValue = entry.getValue();
Preconditions.checkNotNull(inputValue, "%s has null dep %s", artifact, input);
if (!(inputValue instanceof FileArtifactValue)) {
// We do not recurse in aggregating middleman artifacts.
Preconditions.checkState(!(inputValue instanceof AggregatingArtifactValue), "%s %s %s", artifact, action, inputValue);
continue;
}
inputs.add(Pair.of(input, (FileArtifactValue) inputValue));
}
return new AggregatingArtifactValue(inputs.build(), value);
}
Aggregations