Search in sources :

Example 1 with ArtifactResolver

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);
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ExecException(com.google.devtools.build.lib.actions.ExecException) Artifact(com.google.devtools.build.lib.actions.Artifact) ArtifactResolver(com.google.devtools.build.lib.actions.ArtifactResolver) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)1 ArtifactResolver (com.google.devtools.build.lib.actions.ArtifactResolver)1 ExecException (com.google.devtools.build.lib.actions.ExecException)1 Executor (com.google.devtools.build.lib.actions.Executor)1 HashSet (java.util.HashSet)1 Nullable (javax.annotation.Nullable)1