diff options
3 files changed, 37 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java index 754adc96fd..5c46270b1f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.rules.objc; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.syntax.Label; import com.google.devtools.build.lib.vfs.FileSystemUtils; @@ -74,6 +75,15 @@ final class IntermediateArtifacts { } /** + * A dummy .c file to be included in xcode projects. This is needed if the target does not have + * any source files but Xcode requires one. + */ + public Artifact dummySource() { + return scopedArtifact( + ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET).getRootRelativePath()); + } + + /** * The output of using {@code actoolzip} to run {@code actool} for a given bundle which is * merged under the {@code .app} or {@code .bundle} directory root. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java index 3e77023af2..a7860d6bab 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java @@ -331,11 +331,14 @@ public final class XcodeProvider implements TransitiveInfoProvider { */ public static final class Project { private final NestedSet<Artifact> inputsToXcodegen; + private final NestedSet<Artifact> additionalSources; private final ImmutableList<XcodeProvider> topLevelTargets; private Project( - NestedSet<Artifact> inputsToXcodegen, ImmutableList<XcodeProvider> topLevelTargets) { + NestedSet<Artifact> inputsToXcodegen, NestedSet<Artifact> additionalSources, + ImmutableList<XcodeProvider> topLevelTargets) { this.inputsToXcodegen = inputsToXcodegen; + this.additionalSources = additionalSources; this.topLevelTargets = topLevelTargets; } @@ -345,10 +348,13 @@ public final class XcodeProvider implements TransitiveInfoProvider { public static Project fromTopLevelTargets(Iterable<XcodeProvider> topLevelTargets) { NestedSetBuilder<Artifact> inputsToXcodegen = NestedSetBuilder.stableOrder(); + NestedSetBuilder<Artifact> additionalSources = NestedSetBuilder.stableOrder(); for (XcodeProvider target : topLevelTargets) { inputsToXcodegen.addTransitive(target.inputsToXcodegen); + additionalSources.addTransitive(target.additionalSources); } - return new Project(inputsToXcodegen.build(), ImmutableList.copyOf(topLevelTargets)); + return new Project(inputsToXcodegen.build(), additionalSources.build(), + ImmutableList.copyOf(topLevelTargets)); } /** @@ -358,6 +364,13 @@ public final class XcodeProvider implements TransitiveInfoProvider { public NestedSet<Artifact> getInputsToXcodegen() { return inputsToXcodegen; } + + /** + * Returns artifacts that are additional sources for the Xcodegen action. + */ + public NestedSet<Artifact> getAdditionalSources() { + return additionalSources; + } /** * Returns all the target controls that must be added to the xcodegen control. No other target diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java index 0f390ad421..45f9726009 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeSupport.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.actions.BinaryFileWriteAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; +import com.google.devtools.build.lib.analysis.actions.SymlinkAction; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.SplitArchTransition.ConfigurationDistinguisher; @@ -75,8 +76,16 @@ public final class XcodeSupport { * @return this xcode support */ XcodeSupport addDummySource(XcodeProvider.Builder xcodeProviderBuilder) { - xcodeProviderBuilder.addAdditionalSources( - ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET)); + IntermediateArtifacts intermediateArtifacts = + ObjcRuleClasses.intermediateArtifacts(ruleContext); + + ruleContext.registerAction(new SymlinkAction( + ruleContext.getActionOwner(), + ruleContext.getPrerequisiteArtifact("$dummy_source", Mode.TARGET), + intermediateArtifacts.dummySource(), + "Symlinking dummy artifact")); + + xcodeProviderBuilder.addAdditionalSources(intermediateArtifacts.dummySource()); return this; } @@ -207,6 +216,7 @@ public final class XcodeSupport { .addInputArgument(controlFile) .addOutput(ruleContext.getImplicitOutputArtifact(XcodeSupport.PBXPROJ)) .addTransitiveInputs(project.getInputsToXcodegen()) + .addTransitiveInputs(project.getAdditionalSources()) .build(ruleContext)); } |