Fix Objc pre-execution header thinning

It was accidentally disabled by https://github.com/bazelbuild/bazel/commit/51a9596f592c183beffdeeffc43c86295c88a4a5 due to the refactoring in
CppCompileAction that made it no longer call the include processing if
shouldScanIncludes() returned false.

Note that ObjC header thinning relies on needsDotdInputPruning being
true as controlled by the --objc_use_dotd_pruning flag. Note that bazel
emits an error if header thinning is enabled, but dotd pruning is
disabled.

This was not caught by our existing tests because none of them actually
check if the list of inputs to the action was reduced before it is
executed. The tests only check that the include scanning action returns
a reduced list, but not that the reduced list is actually used in the
CppCompileAction.

PiperOrigin-RevId: 249835036
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index b199335..d317dfd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -401,17 +401,18 @@
   private Iterable<Artifact> findUsedHeaders(
       ActionExecutionContext actionExecutionContext, IncludeScanningHeaderData headerData)
       throws ActionExecutionException, InterruptedException {
-    if (!shouldScanIncludes()) {
-      return NestedSetBuilder.fromNestedSet(ccCompilationContext.getDeclaredIncludeSrcs())
-          .addTransitive(additionalPrunableHeaders)
-          .build();
-    }
     try {
       try {
-        return actionExecutionContext
-            .getContext(CppIncludeScanningContext.class)
-            .findAdditionalInputs(this, actionExecutionContext, includeProcessing, headerData)
-            .get();
+        ListenableFuture<Iterable<Artifact>> future =
+            actionExecutionContext
+                .getContext(CppIncludeScanningContext.class)
+                .findAdditionalInputs(this, actionExecutionContext, includeProcessing, headerData);
+        if (future == null) {
+          return NestedSetBuilder.fromNestedSet(ccCompilationContext.getDeclaredIncludeSrcs())
+              .addTransitive(additionalPrunableHeaders)
+              .build();
+        }
+        return future.get();
       } catch (ExecutionException e) {
         Throwables.throwIfInstanceOf(e.getCause(), ExecException.class);
         Throwables.throwIfInstanceOf(e.getCause(), InterruptedException.class);