use of com.google.devtools.build.lib.actions.ArtifactResolver in project bazel by bazelbuild.
the class CppCompileAction method discoverInputs.
@Nullable
@Override
public Iterable<Artifact> discoverInputs(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
Iterable<Artifact> initialResult;
actionExecutionContext.getExecutor().getEventBus().post(ActionStatusMessage.analysisStrategy(this));
try {
initialResult = executor.getContext(actionContext).findAdditionalInputs(this, actionExecutionContext, cppSemantics.getIncludeProcessing());
} catch (ExecException e) {
throw e.toActionExecutionException("Include scanning of rule '" + getOwner().getLabel() + "'", executor.getVerboseFailures(), this);
}
if (initialResult == null) {
NestedSetBuilder<Artifact> result = NestedSetBuilder.stableOrder();
if (useHeaderModules) {
// Here, we cannot really know what the top-level modules are, so we just mark all
// transitive modules as "top level".
topLevelModules = Sets.newLinkedHashSet(context.getTransitiveModules(usePic).toCollection());
result.addTransitive(context.getTransitiveModules(usePic));
}
result.addTransitive(prunableInputs);
additionalInputs = result.build();
return result.build();
}
Set<Artifact> initialResultSet = Sets.newLinkedHashSet(initialResult);
if (shouldPruneModules) {
if (CppFileTypes.CPP_MODULE.matches(sourceFile.getFilename())) {
usedModules = ImmutableSet.of(sourceFile);
initialResultSet.add(sourceFile);
} else {
usedModules = Sets.newLinkedHashSet();
topLevelModules = null;
for (CppCompilationContext.TransitiveModuleHeaders usedModule : context.getUsedModules(usePic, initialResultSet)) {
usedModules.add(usedModule.getModule());
}
initialResultSet.addAll(usedModules);
}
}
initialResult = initialResultSet;
this.additionalInputs = initialResult;
// In some cases, execution backends need extra files for each included file. Add them
// to the set of inputs the caller may need to be aware of.
Collection<Artifact> result = new HashSet<>();
ArtifactResolver artifactResolver = executor.getContext(IncludeScanningContext.class).getArtifactResolver();
for (Artifact artifact : initialResult) {
result.addAll(specialInputsHandler.getInputsForIncludedFile(artifact, artifactResolver));
}
for (Artifact artifact : getInputs()) {
result.addAll(specialInputsHandler.getInputsForIncludedFile(artifact, artifactResolver));
}
// TODO(ulfjack): This only works if include scanning is enabled; the cleanup is in progress,
// and this needs to be fixed before we can even consider disabling it.
resolvedInputs = ImmutableList.copyOf(result);
Iterables.addAll(result, initialResult);
return Preconditions.checkNotNull(result);
}
Aggregations