diff options
Diffstat (limited to 'src/main')
4 files changed, 70 insertions, 8 deletions
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 b452b470ba..16c8ba95fb 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 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie } /** - * 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 ActionSpawn 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 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie 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/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index 394a925190..a20ed3d09a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -33,6 +33,9 @@ public final class CppFileTypes { FileTypeSet.of(CppFileTypes.CPP_SOURCE, CppFileTypes.C_SOURCE); public static final FileType CPP_HEADER = FileType.of(".h", ".hh", ".hpp", ".hxx", ".inc"); + public static final FileType PCH = FileType.of(".pch"); + public static final FileTypeSet OBJC_HEADER = FileTypeSet.of(CPP_HEADER, PCH); + public static final FileType CPP_TEXTUAL_INCLUDE = FileType.of(".inc"); public static final FileType PIC_PREPROCESSED_C = FileType.of(".pic.i"); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java index f7fdcdfb62..2d564e7dd9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java @@ -489,12 +489,13 @@ public class LegacyCompilationSupport extends CompilationSupport { appleConfiguration, appleConfiguration.getSingleArchPlatform()) .setDotdPruningPlan(objcConfiguration.getDotdPruningPlan()) .setSourceFile(sourceFile) + .addTransitiveHeaders(objcProvider.get(HEADER)) + .addHeaders(compilationArtifacts.getPrivateHdrs()) .addMandatoryInputs(swiftHeader.asSet()) .addTransitiveMandatoryInputs(moduleMapInputs) .addTransitiveMandatoryInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)) .addTransitiveMandatoryInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)) .setDotdFile(dotdFile) - .addInputs(compilationArtifacts.getPrivateHdrs()) .addInputs(compilationArtifacts.getPchFile().asSet()) .setMnemonic("ObjcCompile") .setExecutable(xcrunwrapper(ruleContext)) @@ -502,7 +503,6 @@ public class LegacyCompilationSupport extends CompilationSupport { .addOutput(objFile) .addOutputs(gcnoFile.asSet()) .addOutput(dotdFile.artifact()) - .addTransitiveInputs(objcProvider.get(HEADER)) .build(ruleContext)); } 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 47c4ff1c6d..ed09fdbd98 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 @@ -23,11 +23,13 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; 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; @@ -38,6 +40,7 @@ import com.google.devtools.build.lib.profiler.ProfilerTask; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.Platform; import com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile; +import com.google.devtools.build.lib.rules.cpp.CppFileTypes; import com.google.devtools.build.lib.rules.cpp.HeaderDiscovery; import com.google.devtools.build.lib.rules.cpp.IncludeScanningContext; import com.google.devtools.build.lib.util.DependencySet; @@ -59,10 +62,35 @@ import java.util.Map; */ 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() { + ImmutableList.Builder<ActionInput> inputs = ImmutableList.<ActionInput>builder() + .addAll(super.getInputFiles()); + + for (Artifact headerArtifact : headers) { + if (CppFileTypes.OBJC_HEADER.matches(headerArtifact.getFilename())) { + inputs.add(headerArtifact); + } + } + return inputs.build(); + } + } + 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 +111,8 @@ public class ObjcCompileAction extends SpawnAction { DotdFile dotdFile, Artifact sourceFile, NestedSet<Artifact> mandatoryInputs, - HeaderDiscovery.DotdPruningMode dotdPruningPlan) { + HeaderDiscovery.DotdPruningMode dotdPruningPlan, + NestedSet<Artifact> headers) { super( owner, tools, @@ -104,6 +133,7 @@ public class ObjcCompileAction extends SpawnAction { this.sourceFile = sourceFile; this.mandatoryInputs = mandatoryInputs; this.dotdPruningPlan = dotdPruningPlan; + this.headers = headers; } /** Returns the DotdPruningPlan for this compile */ @@ -113,14 +143,18 @@ public class ObjcCompileAction extends SpawnAction { } @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 +259,7 @@ public class ObjcCompileAction extends SpawnAction { private Artifact sourceFile; private final NestedSetBuilder<Artifact> mandatoryInputs = new NestedSetBuilder<>(STABLE_ORDER); private HeaderDiscovery.DotdPruningMode dotdPruningPlan; + private NestedSetBuilder<Artifact> headers = NestedSetBuilder.stableOrder(); /** * Creates a new compile action builder with apple environment variables set that are typically @@ -292,6 +327,20 @@ public class ObjcCompileAction extends SpawnAction { this.dotdPruningPlan = dotdPruningPlan; return this; } + + /** Adds to the set of all possible headers that could be required by this compile action. */ + public Builder addTransitiveHeaders(NestedSet<Artifact> headers) { + this.headers.addTransitive(Preconditions.checkNotNull(headers)); + this.addTransitiveInputs(headers); + return this; + } + + /** Adds to the set of all possible headers that could be required by this compile action. */ + public Builder addHeaders(Iterable<Artifact> headers) { + this.headers.addAll(Preconditions.checkNotNull(headers)); + this.addInputs(headers); + return this; + } @Override protected SpawnAction createSpawnAction( @@ -324,7 +373,8 @@ public class ObjcCompileAction extends SpawnAction { dotdFile, sourceFile, mandatoryInputs.build(), - dotdPruningPlan); + dotdPruningPlan, + headers.build()); } } } |