diff options
author | 2018-04-05 09:46:55 -0700 | |
---|---|---|
committer | 2018-04-05 09:48:42 -0700 | |
commit | e1ed9e9e567334fdf7c26cd0db6f20c64840f119 (patch) | |
tree | 5ef5b93f36dc499b64bb5d3f3aed9bcec8e822cb /src/test/java/com/google/devtools/build/lib/rules | |
parent | d7829b1cb0cfbafe10a70c0a4868158dba46b27a (diff) |
Fix strict module map propagation for j2objc.
J2Objc needs special consideration to implement strict Swift-ObjC deps. The module maps for the generated Objective-C code are associated with their originating java_library targets (via the J2Objc aspect), which a swift_library cannot directly depend on. So those deeper down module maps need to be propagated transitively *until* a j2objc_library is reached; at that point, the j2objc_library should propagate all of its Java deps module maps, but *not* any of its j2objc_library deps (because that would be non-strict).
PiperOrigin-RevId: 191754811
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java index 902ba916a1..2e96850a9b 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java @@ -46,6 +46,7 @@ import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.cpp.CppCompileActionTemplate; import com.google.devtools.build.lib.rules.cpp.CppModuleMapAction; import com.google.devtools.build.lib.rules.cpp.UmbrellaHeaderAction; +import com.google.devtools.build.lib.syntax.SkylarkSemantics; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; @@ -1070,4 +1071,62 @@ public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { assertThat(commandLine).contains(expectedArg); } } + + @Test + public void testModuleMapsArePropagatedStrictly() throws Exception { + useConfiguration( + "--experimental_objc_enable_module_maps", "--incompatible_strict_objc_module_maps"); + + scratch.file("java/com/google/transpile/dummy.java"); + scratch.file( + "java/com/google/transpile/BUILD", + "package(default_visibility=['//visibility:public'])", + "java_library(name = 'dummy1',", + " srcs = ['dummy.java'])", + "java_library(name = 'dummy2',", + " srcs = ['dummy.java'])", + "java_library(name = 'dummy3',", + " srcs = ['dummy.java'], deps = [':dummy2'])", + "j2objc_library(name = 'lib1',", + " deps = [':dummy1'])", + "j2objc_library(name = 'lib2',", + " deps = [':lib1', ':dummy3'])"); + + // Bazel doesn't give us a way to test the aspect directly on the java_library targets, so we + // can only test propagation through the j2objc_libraries that attach the aspect. + + // lib1 should propagate the module map from its java_library dependency. + assertThat( + getFirstPropagatedModuleMap( + "//java/com/google/transpile:lib1", "dummy1.modulemaps/module.modulemap")) + .isNotNull(); + + // lib2 should propagate the module maps from its transitive java_library dependencies... + assertThat( + getFirstPropagatedModuleMap( + "//java/com/google/transpile:lib2", "dummy2.modulemaps/module.modulemap")) + .isNotNull(); + assertThat( + getFirstPropagatedModuleMap( + "//java/com/google/transpile:lib2", "dummy3.modulemaps/module.modulemap")) + .isNotNull(); + + // ...but it should not propagate the module maps from its j2objc_library dependencies. + assertThat( + getFirstPropagatedModuleMap( + "//java/com/google/transpile:lib2", "dummy1.modulemaps/module.modulemap")) + .isNull(); + } + + private Artifact getFirstPropagatedModuleMap(String label, String nameSuffix) throws Exception { + ObjcProvider provider = providerForTarget(label); + // The ObjC and Swift build rules retrieve the module maps they need to pass to the compiler by + // building a transitive provider from the target-to-build's deps. We duplicate that behavior + // here to make sure we're testing the provider set that the eventual target library would see. + ObjcProvider newProvider = + new ObjcProvider.Builder(SkylarkSemantics.DEFAULT_SEMANTICS) + .addTransitiveAndPropagate(ImmutableList.of(provider)) + .build(); + return getFirstArtifactEndingWith(newProvider.get(ObjcProvider.MODULE_MAP), nameSuffix); + } } |