Skip to content

Commit 45197b7

Browse files
googlewaltcopybara-github
authored andcommitted
Subtract imported_library in subtractSubtrees
This is needed for some upcoming changes to migrate linking info to CcInfo. During the migration we will put the linking info in both CcInfo and ObjcProvider, and it is possible in some code path (through swift_library, fwiw) for an imported_library to become a regular library. For avoid_deps to work, avoid_deps needs to add imported_library to the list of libraries to subtract. PiperOrigin-RevId: 490275745 Change-Id: I013950a2ffe988013ca1613d8b7802ca379d3170
1 parent 23ffce5 commit 45197b7

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ public ObjcProvider subtractSubtrees(
560560
for (Artifact libraryToAvoid : avoidProvider.getPropagable(LIBRARY).toList()) {
561561
avoidLibrariesSet.add(libraryToAvoid.getRunfilesPath());
562562
}
563+
for (Artifact libraryToAvoid : avoidProvider.getPropagable(IMPORTED_LIBRARY).toList()) {
564+
avoidLibrariesSet.add(libraryToAvoid.getRunfilesPath());
565+
}
563566
}
564567
ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder(semantics);
565568
for (Key<?> key : items.keySet()) {

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

+5
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ public void testAvoidDepsObjects_avoidViaCcLibrary() throws Exception {
565565
checkAvoidDepsObjects_avoidViaCcLibrary(getRuleType());
566566
}
567567

568+
@Test
569+
public void testAvoidDepsSubtractsImportedLibrary() throws Exception {
570+
checkAvoidDepsSubtractsImportedLibrary(getRuleType());
571+
}
572+
568573
@Test
569574
public void testBundleLoaderIsCorrectlyPassedToTheLinker() throws Exception {
570575
checkBundleLoaderIsCorrectlyPassedToTheLinker(getRuleType());

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

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ public void testAvoidDepsObjects_avoidViaCcLibrary() throws Exception {
118118
checkAvoidDepsObjects_avoidViaCcLibrary(RULE_TYPE);
119119
}
120120

121+
@Override
122+
@Test
123+
public void testAvoidDepsSubtractsImportedLibrary() throws Exception {
124+
checkAvoidDepsSubtractsImportedLibrary(RULE_TYPE);
125+
}
126+
121127
@Override
122128
@Test
123129
public void testLipoBinaryAction() throws Exception {

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

+61
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,67 @@ public void checkAvoidDepsObjects_avoidViaCcLibrary(RuleType ruleType) throws Ex
17771777
.isNull();
17781778
}
17791779

1780+
public void checkAvoidDepsSubtractsImportedLibrary(RuleType ruleType) throws Exception {
1781+
if (!ruleType.getRuleTypeName().equals("apple_binary_starlark")) {
1782+
addAppleBinaryStarlarkRule(scratch);
1783+
}
1784+
1785+
ruleType.scratchTarget(
1786+
scratch, "deps", "['//libs:objc_lib']", "avoid_deps", "['//libs:objc_avoid_lib']");
1787+
1788+
scratch.file(
1789+
"libs/defs.bzl",
1790+
"def _custom_library_impl(ctx):",
1791+
" return [",
1792+
" apple_common.new_objc_provider(",
1793+
" library=depset([ctx.file.library]),",
1794+
" ), CcInfo()",
1795+
" ]",
1796+
"custom_library = rule(",
1797+
" _custom_library_impl,",
1798+
" attrs={'library': attr.label(allow_single_file=True)},",
1799+
")",
1800+
"def _custom_static_framework_import_impl(ctx):",
1801+
" return [",
1802+
" apple_common.new_objc_provider(",
1803+
" imported_library=depset([ctx.file.library]),",
1804+
" ), CcInfo()",
1805+
" ]",
1806+
"custom_static_framework_import = rule(",
1807+
" _custom_static_framework_import_impl,",
1808+
" attrs={'library': attr.label(allow_single_file=True)},",
1809+
")");
1810+
1811+
scratch.file(
1812+
"libs/BUILD",
1813+
"load('//test_starlark:apple_binary_starlark.bzl', 'apple_binary_starlark')",
1814+
"load(':defs.bzl', 'custom_library', 'custom_static_framework_import')",
1815+
"objc_library(",
1816+
" name = 'objc_lib',",
1817+
" srcs = ['a.m'],",
1818+
" deps = [':framework_library'],",
1819+
")",
1820+
"custom_library(",
1821+
" name = 'framework_library',",
1822+
" library = 'buzzbuzz.framework/buzzbuzz',",
1823+
")",
1824+
"objc_library(",
1825+
" name = 'objc_avoid_lib',",
1826+
" srcs = ['b.m'],",
1827+
" deps = [':framework'],",
1828+
")",
1829+
"custom_static_framework_import(",
1830+
" name = 'framework',",
1831+
" library = 'buzzbuzz.framework/buzzbuzz',",
1832+
")");
1833+
1834+
Artifact binArtifact =
1835+
getFirstArtifactEndingWith(lipoBinAction("//x:x").getInputs(), "x/x_bin");
1836+
Action action = getGeneratingAction(binArtifact);
1837+
assertThat(Artifact.toRootRelativePaths(action.getInputs()))
1838+
.doesNotContain("libs/buzzbuzz.framework/buzzbuzz");
1839+
}
1840+
17801841
public void checkFilesToCompileOutputGroup(RuleType ruleType) throws Exception {
17811842
ruleType.scratchTarget(scratch);
17821843
ConfiguredTarget target = getConfiguredTarget("//x:x");

0 commit comments

Comments
 (0)