ObjcCompileAction provides all headers to sandboxed execution.  This allows
headers pruned by .d pruning to be re-added if they are changed.

--
MOS_MIGRATED_REVID=137697323
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
index 8ee9858..3222dd1 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
@@ -426,14 +426,20 @@
   }
 
   /**
-   * The Spawn which this SpawnAction will execute.
+   * A spawn instance that is tied to a specific SpawnAction.  
    */
-  private class ActionSpawn extends BaseSpawn {
+  public class ActionSpawn extends BaseSpawn {
 
     private final List<Artifact> filesets = new ArrayList<>();
 
     private final ImmutableMap<String, String> effectiveEnvironment;
 
+    /**
+     * Creates an ActionSpawn with the given environment variables.
+     * 
+     * <p>Subclasses of SpawnAction may subclass in order to provide action-specific values for
+     * environment variables or action inputs.
+     */
     public ActionSpawn(Map<String, String> clientEnv) {
       super(ImmutableList.copyOf(argv.arguments()),
           ImmutableMap.<String, String>of(),
@@ -460,6 +466,9 @@
       effectiveEnvironment = ImmutableMap.copyOf(env);
     }
 
+    /**
+     * Creates an ActionSpawn with no environment variables.
+     */
     public ActionSpawn() {
       this(null);
     }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 8cad89d..26e9986 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -694,6 +694,7 @@
     ruleContext.registerAction(
         ObjcCompileAction.Builder.createObjcCompileActionBuilderWithAppleEnv(
                 appleConfiguration, appleConfiguration.getSingleArchPlatform())
+            .setHeaders(objcProvider.get(HEADER))
             .setDotdPruningPlan(objcConfiguration.getDotdPruningPlan())
             .setSourceFile(sourceFile)
             .addMandatoryInputs(swiftHeader.asSet())
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCompileAction.java
index 47c4ff1..9179e74 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCompileAction.java
@@ -21,13 +21,16 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.actions.ActionExecutionContext;
 import com.google.devtools.build.lib.actions.ActionExecutionException;
+import com.google.devtools.build.lib.actions.ActionInput;
 import com.google.devtools.build.lib.actions.ActionOwner;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.ArtifactResolver;
 import com.google.devtools.build.lib.actions.Executor;
 import com.google.devtools.build.lib.actions.ResourceSet;
+import com.google.devtools.build.lib.actions.Spawn;
 import com.google.devtools.build.lib.analysis.actions.CommandLine;
 import com.google.devtools.build.lib.analysis.actions.SpawnAction;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
@@ -59,10 +62,27 @@
  */
 public class ObjcCompileAction extends SpawnAction {
 
+  /**
+   * A spawn that provides all headers to sandboxed execution to allow pruned headers to be
+   * re-introduced into action inputs.
+   */
+  public class ObjcCompileActionSpawn extends ActionSpawn {
+    
+    public ObjcCompileActionSpawn(Map<String, String> clientEnv) {
+      super(clientEnv);
+    }
+
+    @Override
+    public Iterable<? extends ActionInput> getInputFiles() {
+      return Iterables.concat(super.getInputFiles(), headers);
+    }
+  }
+
   private final DotdFile dotdFile;
   private final Artifact sourceFile;
   private final NestedSet<Artifact> mandatoryInputs;
   private final HeaderDiscovery.DotdPruningMode dotdPruningPlan;
+  private final NestedSet<Artifact> headers;
 
   private static final String GUID = "a00d5bac-a72c-4f0f-99a7-d5fdc6072137";
 
@@ -83,7 +103,8 @@
       DotdFile dotdFile,
       Artifact sourceFile,
       NestedSet<Artifact> mandatoryInputs,
-      HeaderDiscovery.DotdPruningMode dotdPruningPlan) {
+      HeaderDiscovery.DotdPruningMode dotdPruningPlan,
+      NestedSet<Artifact> headers) {
     super(
         owner,
         tools,
@@ -104,6 +125,7 @@
     this.sourceFile = sourceFile;
     this.mandatoryInputs = mandatoryInputs;
     this.dotdPruningPlan = dotdPruningPlan;
+    this.headers = headers;
   }
 
   /** Returns the DotdPruningPlan for this compile */
@@ -113,14 +135,18 @@
   }
 
   @Override
+  public final Spawn getSpawn(Map<String, String> clientEnv) {
+    return new ObjcCompileActionSpawn(clientEnv);
+  }
+  
+  @Override
   public boolean discoversInputs() {
     return true;
   }
 
   @Override
   public Iterable<Artifact> discoverInputs(ActionExecutionContext actionExecutionContext) {
-    // We do not use include scanning for objc
-    return null;
+    return headers;
   }
 
   @Override
@@ -225,6 +251,7 @@
     private Artifact sourceFile;
     private final NestedSetBuilder<Artifact> mandatoryInputs = new NestedSetBuilder<>(STABLE_ORDER);
     private HeaderDiscovery.DotdPruningMode dotdPruningPlan;
+    private NestedSet<Artifact> headers;
 
     /**
      * Creates a new compile action builder with apple environment variables set that are typically
@@ -293,6 +320,12 @@
       return this;
     }
 
+    /** Sets the set of all possible headers that could be required by this compile action. */
+    public Builder setHeaders(NestedSet<Artifact> headers) {
+      this.headers = Preconditions.checkNotNull(headers);
+      return this;
+    }
+    
     @Override
     protected SpawnAction createSpawnAction(
         ActionOwner owner,
@@ -324,7 +357,8 @@
           dotdFile,
           sourceFile,
           mandatoryInputs.build(),
-          dotdPruningPlan);
+          dotdPruningPlan,
+          headers);
     }
   }
 }