diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java index d4a26a234d..13a915f22a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java @@ -157,6 +157,7 @@ public final class ObjcCommon { private Iterable<ObjcProvider> depObjcProviders = ImmutableList.of(); private Iterable<ObjcProvider> directDepObjcProviders = ImmutableList.of(); private Iterable<ObjcProvider> runtimeDepObjcProviders = ImmutableList.of(); + private Iterable<ObjcProvider> repropagatedModuleMapObjcProviders = ImmutableList.of(); private Iterable<String> defines = ImmutableList.of(); private Iterable<PathFragment> includes = ImmutableList.of(); private Iterable<PathFragment> directDependencyIncludes = ImmutableList.of(); @@ -363,6 +364,22 @@ public final class ObjcCommon { } /** + * Adds Objc providers whose module maps should be repropagated as if they are directly + * associated with the target propagating the provider being built. + * + * <p>This supports a small number of specialized use cases, like J2Objc, where the module maps + * associated with the {@code java_library} (via an aspect) need to be repropagated by the + * {@code j2objc_library} that depends on them so that Swift code can access those module maps + * for the purposes of strict module map propagation (without propagating the module maps + * _fully_ transitively). + */ + Builder addRepropagatedModuleMapObjcProviders(Iterable<ObjcProvider> objcProviders) { + this.repropagatedModuleMapObjcProviders = + Iterables.concat(this.repropagatedModuleMapObjcProviders, objcProviders); + return this; + } + + /** * Adds additional static libraries to be linked into the final ObjC application bundle. */ Builder addExtraImportLibraries(Iterable<Artifact> extraImportLibraries) { @@ -544,13 +561,21 @@ public final class ObjcCommon { } } + if (useStrictObjcModuleMaps(context)) { + for (ObjcProvider provider : repropagatedModuleMapObjcProviders) { + objcProvider.addAllForDirectDependents(MODULE_MAP, provider.get(ObjcProvider.MODULE_MAP)); + objcProvider.addAllForDirectDependents( + TOP_LEVEL_MODULE_MAP, provider.get(ObjcProvider.TOP_LEVEL_MODULE_MAP)); + } + } + if (hasModuleMap) { CppModuleMap moduleMap = intermediateArtifacts.moduleMap(); Optional<Artifact> umbrellaHeader = moduleMap.getUmbrellaHeader(); if (umbrellaHeader.isPresent()) { objcProvider.add(UMBRELLA_HEADER, umbrellaHeader.get()); } - if (context.getFragment(ObjcConfiguration.class).useStrictObjcModuleMaps()) { + if (useStrictObjcModuleMaps(context)) { objcProvider.addForDirectDependents(MODULE_MAP, moduleMap.getArtifact()); objcProvider.addForDirectDependents(TOP_LEVEL_MODULE_MAP, moduleMap); } else { @@ -572,6 +597,13 @@ public final class ObjcCommon { return new ObjcCommon(objcProvider.build(), compilationArtifacts); } + private static boolean useStrictObjcModuleMaps(RuleContext context) { + // We need to check isLegalFragment first because some non-compilation rules, like + // objc_bundle_library, don't declare this fragment. + return context.isLegalFragment(ObjcConfiguration.class) + && context.getFragment(ObjcConfiguration.class).useStrictObjcModuleMaps(); + } + private static boolean isCcLibrary(ConfiguredTargetAndData info) { try { String targetName = info.getTarget().getTargetKind(); |