Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Rollforward #2 of "AppleBinary and AppleStaticLibrary no longer propa…
Browse files Browse the repository at this point in the history
…gate unwrapped ObjcProvider", after changes made to apple bazel rules to be compatible.

RELNOTES: None.
PiperOrigin-RevId: 167061765
  • Loading branch information
c-parsons authored and vladmos committed Aug 31, 2017
1 parent 58e3891 commit 618a2bf
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ public final ConfiguredTarget create(RuleContext ruleContext)
objcProviderBuilder.add(MULTI_ARCH_LINKED_BINARIES, outputArtifact);

ObjcProvider objcProvider = objcProviderBuilder.build();
// TODO(cparsons): Stop propagating ObjcProvider directly from this rule.
targetBuilder.addNativeDeclaredProvider(objcProvider);

switch (getBinaryType(ruleContext)) {
case EXECUTABLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ public final ConfiguredTarget create(RuleContext ruleContext)
ObjcProvider objcProvider = objcProviderBuilder.build();

targetBuilder
// TODO(cparsons): Remove ObjcProvider as a direct provider.
.addNativeDeclaredProvider(objcProvider)
.addNativeDeclaredProvider(
new AppleStaticLibraryProvider(
ruleIntermediateArtifacts.combinedArchitectureArchive(), objcProvider))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ public void testLoadableBundleBinaryAddsRpathLinkOptWithBundleLoader() throws Ex

@Test
public void testCustomModuleMap() throws Exception {
checkCustomModuleMap(RULE_TYPE);
checkCustomModuleMap(RULE_TYPE, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public void testAvoidDepsProviders() throws Exception {
" resources = [':avoid.png']",
")");

ObjcProvider provider = providerForTarget("//package:test");
ObjcProvider provider = getConfiguredTarget("//package:test")
.get(AppleStaticLibraryProvider.SKYLARK_CONSTRUCTOR)
.getDepsObjcProvider();
// Do not remove SDK_FRAMEWORK values in avoid_deps.
assertThat(provider.get(ObjcProvider.SDK_FRAMEWORK))
.containsAllOf(new SdkFramework("AvoidSDK"), new SdkFramework("BaseSDK"));
Expand Down Expand Up @@ -623,4 +625,4 @@ public void testAvoidDepsObjects_avoidCcLibrary() throws Exception {
assertThat(Artifact.toRootRelativePaths(action.getInputs())).doesNotContain(
"package/libavoidCcLib.a");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,22 @@ public void testMultiArchUserHeaderSearchPathsUsed() throws Exception {
// Usually, an ios_test would depend on apple_binary through a skylark_ios_application in its
// 'binary' attribute. Since we don't have skylark_ios_application here, we use the 'deps'
// attribute instead.
scratch.file("skylarkstub/BUILD");
scratch.file("skylarkstub/skylark_stub.bzl",
"def skylark_ios_application_stub_impl(ctx):",
" bin_provider = ctx.attr.binary[apple_common.AppleExecutableBinary]",
" return struct(objc=bin_provider.objc)",
"skylark_ios_application_stub = rule(",
" skylark_ios_application_stub_impl,",
// Both 'binary' and 'deps' are needed because ObjcProtoAspect is applied transitively
// along attribute 'deps' only.
" attrs = {'binary': attr.label(mandatory=True,",
" providers=[apple_common.AppleExecutableBinary])},",
" fragments = ['apple', 'objc'],",
")");

scratch.file("x/BUILD",
"load('//skylarkstub:skylark_stub.bzl', 'skylark_ios_application_stub')",
"genrule(",
" name = 'gen_hdrs',",
" outs = ['generated.h'],",
Expand All @@ -1179,6 +1194,10 @@ public void testMultiArchUserHeaderSearchPathsUsed() throws Exception {
" platform_type = 'ios',",
" hdrs = ['generated.h'],",
")",
"skylark_ios_application_stub(",
" name = 'stub_application',",
" binary = ':apple_bin',",
")",
"objc_binary(",
" name = 'bin',",
" srcs = ['bin.m'],",
Expand All @@ -1192,7 +1211,7 @@ public void testMultiArchUserHeaderSearchPathsUsed() throws Exception {
" srcs = ['test.m'],",
" xctest = 1,",
" xctest_app = ':testApp',",
" deps = [':apple_bin']",
" deps = [':stub_application']",
")");
CommandAction compileAction = compileAction("//x:test", "test.o");
// The genfiles root for child configurations must be present in the compile action so that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ public void testFilesToCompileOutputGroup() throws Exception {

@Test
public void testCustomModuleMap() throws Exception {
checkCustomModuleMap(RULE_TYPE);
checkCustomModuleMap(RULE_TYPE, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,6 @@ public void testDefaultEnabledFeatureIsUsed() throws Exception {

@Test
public void testCustomModuleMap() throws Exception {
checkCustomModuleMap(RULE_TYPE);
checkCustomModuleMap(RULE_TYPE, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ public void testErrorForUsesProtobufWithOptionsFile() throws Exception {

@Test
public void testModulemapCreatedForNonLinkingTargets() throws Exception {
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_protobuf");
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_protobuf", false);
}

@Test
public void testModulemapNotCreatedForLinkingTargets() throws Exception {
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_binary");
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_binary", true);
}

@Test
Expand Down Expand Up @@ -760,7 +760,8 @@ private static String sortedJoin(Iterable<String> elements) {
return Joiner.on('\n').join(Ordering.natural().immutableSortedCopy(elements));
}

private void checkOnlyLibModuleMapsArePresentForTarget(String target) throws Exception {
private void checkOnlyLibModuleMapsArePresentForTarget(String target,
boolean fromBinary) throws Exception {
Artifact libModuleMap =
getGenfilesArtifact(
"opl_protobuf.modulemaps/module.modulemap",
Expand All @@ -770,7 +771,11 @@ private void checkOnlyLibModuleMapsArePresentForTarget(String target) throws Exc
"protobuf_lib.modulemaps/module.modulemap",
getConfiguredTarget("//objcproto:protobuf_lib"));

ObjcProvider provider = providerForTarget(target);
ObjcProvider provider = fromBinary
? getConfiguredTarget(target)
.get(AppleExecutableBinaryProvider.SKYLARK_CONSTRUCTOR)
.getDepsObjcProvider()
: providerForTarget(target);
assertThat(Artifact.toRootRelativePaths(provider.get(ObjcProvider.MODULE_MAP).toSet()))
.containsExactlyElementsIn(
Artifact.toRootRelativePaths(ImmutableSet.of(libModuleMap, protolibModuleMap)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4892,7 +4892,7 @@ public void checkFilesToCompileOutputGroup(RuleType ruleType) throws Exception {
.isEqualTo("a.o");
}

protected void checkCustomModuleMap(RuleType ruleType) throws Exception {
protected void checkCustomModuleMap(RuleType ruleType, boolean fromBinary) throws Exception {
useConfiguration("--experimental_objc_enable_module_maps");
ruleType.scratchTarget(scratch, "srcs", "['a.m']", "deps", "['//z:testModuleMap']");
scratch.file("x/a.m");
Expand Down Expand Up @@ -4920,7 +4920,11 @@ protected void checkCustomModuleMap(RuleType ruleType) throws Exception {
assertThat(Artifact.toExecPaths(provider.get(MODULE_MAP)))
.containsExactly("y/module.modulemap");

provider = providerForTarget("//x:x");
provider = fromBinary
? getConfiguredTarget("//x:x")
.get(AppleExecutableBinaryProvider.SKYLARK_CONSTRUCTOR)
.getDepsObjcProvider()
: providerForTarget("//x:x");
assertThat(Artifact.toExecPaths(provider.get(MODULE_MAP))).contains("y/module.modulemap");
}

Expand Down

0 comments on commit 618a2bf

Please sign in to comment.