aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-09-15 00:00:54 +0000
committerGravatar John Field <jfield@google.com>2015-09-15 20:26:21 +0000
commit415aae660a932ead71628072610948afd11d7dc2 (patch)
treec2b038ca199463663974c3d2eee5f13a38a15c70 /src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
parent1c289af299227a73de2eb8903696d906105451ef (diff)
Generate module maps for each objc_* target with compilation support.
This uses CppModuleMap and CppModuleMapAction to generate clang module maps for the target and its transitive dependencies. To enable this feature, you must pass -experimental_objc_enable_module_maps to bazel. For objc_* targets that need to use the "modules" language features (@import, Swift interop, etc), set the "enable_modules" attribute to 1. -- MOS_MIGRATED_REVID=103045673
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java56
1 files changed, 49 insertions, 7 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 59f9b07f67..923ed6c79f 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,8 +17,10 @@ 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.actions.Root;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
import com.google.devtools.build.lib.syntax.Label;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -28,7 +30,7 @@ import com.google.devtools.build.lib.vfs.PathFragment;
*/
// TODO(bazel-team): This should really be named DerivedArtifacts as it contains methods for
// final as well as intermediate artifacts.
-final class IntermediateArtifacts {
+public final class IntermediateArtifacts {
/**
* Extension used on the temporary zipped dsym bundle location. Must contain {@code .dSYM} for
@@ -100,6 +102,16 @@ final class IntermediateArtifacts {
}
/**
+ * Returns a derived artifact in the genfiles directory obtained by appending some extension to
+ * the end of the {@link PathFragment} corresponding to the owner {@link Label}.
+ */
+ private Artifact appendExtensionInGenfiles(String extension) {
+ PathFragment name = new PathFragment(ruleContext.getLabel().getName());
+ return scopedArtifact(
+ name.replaceName(name.getBaseName() + extension), /* inGenfiles = */ true);
+ }
+
+ /**
* 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.
*/
@@ -161,23 +173,34 @@ final class IntermediateArtifacts {
return appendExtension("_lipobin");
}
- private Artifact scopedArtifact(PathFragment scopeRelative) {
+ private Artifact scopedArtifact(PathFragment scopeRelative, boolean inGenfiles) {
+ Root root =
+ inGenfiles
+ ? ruleContext.getConfiguration().getGenfilesDirectory()
+ : ruleContext.getConfiguration().getBinDirectory();
if (scopingLabel.isPresent()) {
// The path of this artifact will be
// RULE_PACKAGE/_intermediate_scoped/RULE_LABEL/SCOPING_PACKAGE/SCOPING_LABEL/SCOPERELATIVE
- return ruleContext.getUniqueDirectoryArtifact("_intermediate_scoped",
- scopingLabel.get().getPackageIdentifier().getPathFragment()
+ return ruleContext.getUniqueDirectoryArtifact(
+ "_intermediate_scoped",
+ scopingLabel
+ .get()
+ .getPackageIdentifier()
+ .getPathFragment()
.getRelative(scopingLabel.get().getName())
.getRelative(scopeRelative),
- ruleContext.getConfiguration().getBinDirectory());
+ root);
} else {
// The path of this artifact will be
// RULE_PACKAGE/SCOPERELATIVE
- return ruleContext.getPackageRelativeArtifact(scopeRelative,
- ruleContext.getConfiguration().getBinDirectory());
+ return ruleContext.getPackageRelativeArtifact(scopeRelative, root);
}
}
+ private Artifact scopedArtifact(PathFragment scopeRelative) {
+ return scopedArtifact(scopeRelative, /* inGenfiles = */ false);
+ }
+
/**
* The {@code .a} file which contains all the compiled sources for a rule.
*/
@@ -339,4 +362,23 @@ final class IntermediateArtifacts {
public Artifact dotdFile(Artifact source) {
return inUniqueObjsDir(source, ".d");
}
+
+ /**
+ * {@link CppModuleMap} that provides the clang module map for this target.
+ */
+ public CppModuleMap moduleMap() {
+ if (!ObjcRuleClasses.objcConfiguration(ruleContext).moduleMapsEnabled()) {
+ throw new IllegalStateException();
+ }
+ String moduleName =
+ ruleContext
+ .getLabel()
+ .toString()
+ .replace("//", "")
+ .replace("/", "_")
+ .replace(":", "_");
+ // To get Swift to pick up module maps, we need to name them "module.modulemap" and have their
+ // parent directory in the module map search paths.
+ return new CppModuleMap(appendExtensionInGenfiles(".modulemaps/module.modulemap"), moduleName);
+ }
}