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

Commit 618a2bf

Browse files
c-parsonsvladmos
authored andcommitted
Rollforward #2 of "AppleBinary and AppleStaticLibrary no longer propagate unwrapped ObjcProvider", after changes made to apple bazel rules to be compatible.
RELNOTES: None. PiperOrigin-RevId: 167061765
1 parent 58e3891 commit 618a2bf

File tree

9 files changed

+42
-16
lines changed

9 files changed

+42
-16
lines changed

src/main/java/com/google/devtools/build/lib/rules/objc/AppleBinary.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ public final ConfiguredTarget create(RuleContext ruleContext)
167167
objcProviderBuilder.add(MULTI_ARCH_LINKED_BINARIES, outputArtifact);
168168

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

173171
switch (getBinaryType(ruleContext)) {
174172
case EXECUTABLE:

src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ public final ConfiguredTarget create(RuleContext ruleContext)
181181
ObjcProvider objcProvider = objcProviderBuilder.build();
182182

183183
targetBuilder
184-
// TODO(cparsons): Remove ObjcProvider as a direct provider.
185-
.addNativeDeclaredProvider(objcProvider)
186184
.addNativeDeclaredProvider(
187185
new AppleStaticLibraryProvider(
188186
ruleIntermediateArtifacts.combinedArchitectureArchive(), objcProvider))

src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinaryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ public void testLoadableBundleBinaryAddsRpathLinkOptWithBundleLoader() throws Ex
14401440

14411441
@Test
14421442
public void testCustomModuleMap() throws Exception {
1443-
checkCustomModuleMap(RULE_TYPE);
1443+
checkCustomModuleMap(RULE_TYPE, true);
14441444
}
14451445

14461446
@Test

src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ public void testAvoidDepsProviders() throws Exception {
149149
" resources = [':avoid.png']",
150150
")");
151151

152-
ObjcProvider provider = providerForTarget("//package:test");
152+
ObjcProvider provider = getConfiguredTarget("//package:test")
153+
.get(AppleStaticLibraryProvider.SKYLARK_CONSTRUCTOR)
154+
.getDepsObjcProvider();
153155
// Do not remove SDK_FRAMEWORK values in avoid_deps.
154156
assertThat(provider.get(ObjcProvider.SDK_FRAMEWORK))
155157
.containsAllOf(new SdkFramework("AvoidSDK"), new SdkFramework("BaseSDK"));
@@ -623,4 +625,4 @@ public void testAvoidDepsObjects_avoidCcLibrary() throws Exception {
623625
assertThat(Artifact.toRootRelativePaths(action.getInputs())).doesNotContain(
624626
"package/libavoidCcLib.a");
625627
}
626-
}
628+
}

src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,22 @@ public void testMultiArchUserHeaderSearchPathsUsed() throws Exception {
11671167
// Usually, an ios_test would depend on apple_binary through a skylark_ios_application in its
11681168
// 'binary' attribute. Since we don't have skylark_ios_application here, we use the 'deps'
11691169
// attribute instead.
1170+
scratch.file("skylarkstub/BUILD");
1171+
scratch.file("skylarkstub/skylark_stub.bzl",
1172+
"def skylark_ios_application_stub_impl(ctx):",
1173+
" bin_provider = ctx.attr.binary[apple_common.AppleExecutableBinary]",
1174+
" return struct(objc=bin_provider.objc)",
1175+
"skylark_ios_application_stub = rule(",
1176+
" skylark_ios_application_stub_impl,",
1177+
// Both 'binary' and 'deps' are needed because ObjcProtoAspect is applied transitively
1178+
// along attribute 'deps' only.
1179+
" attrs = {'binary': attr.label(mandatory=True,",
1180+
" providers=[apple_common.AppleExecutableBinary])},",
1181+
" fragments = ['apple', 'objc'],",
1182+
")");
1183+
11701184
scratch.file("x/BUILD",
1185+
"load('//skylarkstub:skylark_stub.bzl', 'skylark_ios_application_stub')",
11711186
"genrule(",
11721187
" name = 'gen_hdrs',",
11731188
" outs = ['generated.h'],",
@@ -1179,6 +1194,10 @@ public void testMultiArchUserHeaderSearchPathsUsed() throws Exception {
11791194
" platform_type = 'ios',",
11801195
" hdrs = ['generated.h'],",
11811196
")",
1197+
"skylark_ios_application_stub(",
1198+
" name = 'stub_application',",
1199+
" binary = ':apple_bin',",
1200+
")",
11821201
"objc_binary(",
11831202
" name = 'bin',",
11841203
" srcs = ['bin.m'],",
@@ -1192,7 +1211,7 @@ public void testMultiArchUserHeaderSearchPathsUsed() throws Exception {
11921211
" srcs = ['test.m'],",
11931212
" xctest = 1,",
11941213
" xctest_app = ':testApp',",
1195-
" deps = [':apple_bin']",
1214+
" deps = [':stub_application']",
11961215
")");
11971216
CommandAction compileAction = compileAction("//x:test", "test.o");
11981217
// The genfiles root for child configurations must be present in the compile action so that

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ public void testFilesToCompileOutputGroup() throws Exception {
928928

929929
@Test
930930
public void testCustomModuleMap() throws Exception {
931-
checkCustomModuleMap(RULE_TYPE);
931+
checkCustomModuleMap(RULE_TYPE, false);
932932
}
933933

934934
@Test

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,6 @@ public void testDefaultEnabledFeatureIsUsed() throws Exception {
15641564

15651565
@Test
15661566
public void testCustomModuleMap() throws Exception {
1567-
checkCustomModuleMap(RULE_TYPE);
1567+
checkCustomModuleMap(RULE_TYPE, false);
15681568
}
15691569
}

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,12 @@ public void testErrorForUsesProtobufWithOptionsFile() throws Exception {
679679

680680
@Test
681681
public void testModulemapCreatedForNonLinkingTargets() throws Exception {
682-
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_protobuf");
682+
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_protobuf", false);
683683
}
684684

685685
@Test
686686
public void testModulemapNotCreatedForLinkingTargets() throws Exception {
687-
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_binary");
687+
checkOnlyLibModuleMapsArePresentForTarget("//package:opl_binary", true);
688688
}
689689

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

763-
private void checkOnlyLibModuleMapsArePresentForTarget(String target) throws Exception {
763+
private void checkOnlyLibModuleMapsArePresentForTarget(String target,
764+
boolean fromBinary) throws Exception {
764765
Artifact libModuleMap =
765766
getGenfilesArtifact(
766767
"opl_protobuf.modulemaps/module.modulemap",
@@ -770,7 +771,11 @@ private void checkOnlyLibModuleMapsArePresentForTarget(String target) throws Exc
770771
"protobuf_lib.modulemaps/module.modulemap",
771772
getConfiguredTarget("//objcproto:protobuf_lib"));
772773

773-
ObjcProvider provider = providerForTarget(target);
774+
ObjcProvider provider = fromBinary
775+
? getConfiguredTarget(target)
776+
.get(AppleExecutableBinaryProvider.SKYLARK_CONSTRUCTOR)
777+
.getDepsObjcProvider()
778+
: providerForTarget(target);
774779
assertThat(Artifact.toRootRelativePaths(provider.get(ObjcProvider.MODULE_MAP).toSet()))
775780
.containsExactlyElementsIn(
776781
Artifact.toRootRelativePaths(ImmutableSet.of(libModuleMap, protolibModuleMap)));

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4892,7 +4892,7 @@ public void checkFilesToCompileOutputGroup(RuleType ruleType) throws Exception {
48924892
.isEqualTo("a.o");
48934893
}
48944894

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

4923-
provider = providerForTarget("//x:x");
4923+
provider = fromBinary
4924+
? getConfiguredTarget("//x:x")
4925+
.get(AppleExecutableBinaryProvider.SKYLARK_CONSTRUCTOR)
4926+
.getDepsObjcProvider()
4927+
: providerForTarget("//x:x");
49244928
assertThat(Artifact.toExecPaths(provider.get(MODULE_MAP))).contains("y/module.modulemap");
49254929
}
49264930

0 commit comments

Comments
 (0)