aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2015-11-05 02:17:45 +0000
committerGravatar John Field <jfield@google.com>2015-11-05 16:50:52 +0000
commitca2b1bef32fa74c5943dcf040413344e5b38b341 (patch)
treef1b7f42ee7024a81ab8071a200db83fa2d6f1b12 /src
parent6153243bb95f832220d6e5fca8f62af5213a93f2 (diff)
Add missing header sources to Swift compilation steps
* Adds pass-through of dependent headers * Adds pass-through of search paths specified in "includes" attribute -- MOS_MIGRATED_REVID=107098761
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java56
1 files changed, 50 insertions, 6 deletions
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 be937b45b2..17b8f918d2 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
@@ -277,7 +277,7 @@ public final class CompilationSupport {
}
if (compilationArtifacts.hasSwiftSources()) {
- registerSwiftModuleMergeAction(intermediateArtifacts, compilationArtifacts);
+ registerSwiftModuleMergeAction(intermediateArtifacts, compilationArtifacts, objcProvider);
}
for (Artifact archive : compilationArtifacts.getArchive().asSet()) {
@@ -391,6 +391,8 @@ public final class CompilationSupport {
*
* @param sourceFile the artifact to compile
* @param objFile the resulting object artifact
+ * @param intermediateArtifacts intermediary artifacts
+ * @param objcProvider ObjcProvider instance for this invocation
*/
private void registerSwiftCompileAction(
Artifact sourceFile,
@@ -431,8 +433,18 @@ public final class CompilationSupport {
.addExecPath("-primary-file", sourceFile)
.addExecPaths(otherSwiftSources)
.addExecPath("-o", objFile)
- .addExecPath("-emit-module-path", intermediateArtifacts.swiftModuleFile(sourceFile));
-
+ .addExecPath("-emit-module-path", intermediateArtifacts.swiftModuleFile(sourceFile))
+ // The swift compiler will invoke clang itself when compiling module maps. This invocation
+ // does not include the current working directory, causing cwd-relative imports to fail.
+ // Including the current working directory to the header search paths ensures that these
+ // relative imports will work.
+ .add("-Xcc").add("-I.");
+
+ // Using addExecPathBefore here adds unnecessary quotes around '-Xcc -I', which trips the
+ // compiler. Using two add() calls generates a correctly formed command line.
+ for (PathFragment directory : objcProvider.get(INCLUDE).toList()) {
+ commandLine.add("-Xcc").add(String.format("-I%s", directory.toString()));
+ }
ImmutableList.Builder<Artifact> inputHeaders = ImmutableList.<Artifact>builder()
.addAll(attributes.hdrs())
@@ -450,6 +462,7 @@ public final class CompilationSupport {
if (objcConfiguration.moduleMapsEnabled()) {
PathFragment moduleMapPath = intermediateArtifacts.moduleMap().getArtifact().getExecPath();
commandLine.add("-I").add(moduleMapPath.getParentDirectory().toString());
+ commandLine.add("-import-underlying-module");
}
ruleContext.registerAction(
@@ -473,7 +486,8 @@ public final class CompilationSupport {
*/
private void registerSwiftModuleMergeAction(
IntermediateArtifacts intermediateArtifacts,
- CompilationArtifacts compilationArtifacts) {
+ CompilationArtifacts compilationArtifacts,
+ ObjcProvider objcProvider) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
ImmutableList.Builder<Artifact> moduleFiles = new ImmutableList.Builder<>();
@@ -489,21 +503,45 @@ public final class CompilationSupport {
.add("-emit-module")
.add("-sdk").add(IosSdkCommands.sdkDir(objcConfiguration))
.add("-target").add(IosSdkCommands.swiftTarget(objcConfiguration));
+
if (objcConfiguration.generateDebugSymbols()) {
commandLine.add("-g");
}
- commandLine.add("-module-name").add(getModuleName())
+ commandLine
+ .add("-module-name").add(getModuleName())
.add("-parse-as-library")
.addExecPaths(moduleFiles.build())
.addExecPath("-o", intermediateArtifacts.swiftModule())
- .addExecPath("-emit-objc-header-path", intermediateArtifacts.swiftHeader());
+ .addExecPath("-emit-objc-header-path", intermediateArtifacts.swiftHeader())
+ // The swift compiler will invoke clang itself when compiling module maps. This invocation
+ // does not include the current working directory, causing cwd-relative imports to fail.
+ // Including the current working directory to the header search paths ensures that these
+ // relative imports will work.
+ .add("-Xcc").add("-I.");
+
+
+ // Using addExecPathBefore here adds unnecessary quotes around '-Xcc -I', which trips the
+ // compiler. Using two add() calls generates a correctly formed command line.
+ for (PathFragment directory : objcProvider.get(INCLUDE).toList()) {
+ commandLine.add("-Xcc").add(String.format("-I%s", directory.toString()));
+ }
+
+ // Import the Objective-C module map.
+ // TODO(bazel-team): Find a way to import the module map directly, instead of the parent
+ // directory?
+ if (objcConfiguration.moduleMapsEnabled()) {
+ PathFragment moduleMapPath = intermediateArtifacts.moduleMap().getArtifact().getExecPath();
+ commandLine.add("-I").add(moduleMapPath.getParentDirectory().toString());
+ }
ruleContext.registerAction(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext)
.setMnemonic("SwiftModuleMerge")
.setExecutable(XCRUN)
.setCommandLine(commandLine.build())
.addInputs(moduleFiles.build())
+ .addTransitiveInputs(objcProvider.get(HEADER))
+ .addTransitiveInputs(objcProvider.get(MODULE_MAP))
.addOutput(intermediateArtifacts.swiftModule())
.addOutput(intermediateArtifacts.swiftHeader())
.build(ruleContext));
@@ -1170,6 +1208,12 @@ public final class CompilationSupport {
* Returns the name of Swift module for this target.
*/
private String getModuleName() {
+ // If we have module maps support, we need to use the generated module name, this way
+ // clang can properly load objc part of the module via -import-underlying-module command.
+ if (ObjcRuleClasses.objcConfiguration(ruleContext).moduleMapsEnabled()) {
+ return ObjcRuleClasses.intermediateArtifacts(ruleContext).moduleMap().getName();
+ }
+ // Otherwise, just use target name, it doesn't matter.
return ruleContext.getLabel().getName();
}