From 498ef53f9b36230adce79a64f1237ab3971ae54c Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Tue, 25 Aug 2015 14:16:48 +0000 Subject: Link to tools/objc/dummy.c from output directory to allow xcodeproj to resolve the file even while outside a workspace which contains it -- MOS_MIGRATED_REVID=101462428 --- .../build/lib/rules/objc/IntermediateArtifacts.java | 10 ++++++++++ .../devtools/build/lib/rules/objc/XcodeProvider.java | 17 +++++++++++++++-- .../devtools/build/lib/rules/objc/XcodeSupport.java | 14 ++++++++++++-- 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; @@ -73,6 +74,15 @@ final class IntermediateArtifacts { return scopedArtifact(name.replaceName(name.getBaseName() + extension)); } + /** + * 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 inputsToXcodegen; + private final NestedSet additionalSources; private final ImmutableList topLevelTargets; private Project( - NestedSet inputsToXcodegen, ImmutableList topLevelTargets) { + NestedSet inputsToXcodegen, NestedSet additionalSources, + ImmutableList 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 topLevelTargets) { NestedSetBuilder inputsToXcodegen = NestedSetBuilder.stableOrder(); + NestedSetBuilder 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 getInputsToXcodegen() { return inputsToXcodegen; } + + /** + * Returns artifacts that are additional sources for the Xcodegen action. + */ + public NestedSet 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)); } -- cgit v1.2.3