Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 52468c8

Browse files
milendfacebook-github-bot
authored andcommitted
Fix incorrect skipping of SDKROOT-rooted frameworks
Summary: # Context The Apple platform compiler (clang) and linker (ld64) have a default list of framework search paths. Such search paths should not be included as part of the compiler and linker commands for two reasons: - It's unnecessary - It's behaviourally incorrectly when compiling Catalyst apps As per the [docs](https://www.manpagez.com/man/1/ld64/): > The default framework search path is `/Library/Frameworks` then `/System/Library/Frameworks`. (Note: previously, `/Network/Library/Frameworks` was at the end of the default path. If you need that functionality, you need to explicitly add `-F/Network/Library/Frameworks`). > ... > The `-syslibroot` option will prepend a prefix to all search paths. # Before Previously, we would not include **any** framework search path rooted in `$SDKROOT`. That's incorrect because we **only** must skip `$SDKROOT`-rooted frameworks **if** they're part of the default search path as defined by the [docs](https://www.manpagez.com/man/1/ld64/). # After We now only skip frameworks which are already part of the default search path. This makes it possible to use the `StoreKitTest` framework located at `$SDKROOT/Developer/Library/Frameworks/StoreKitTest.framework`. fbshipit-source-id: 9dbde3af4f9e3eb074ef59d6571807b802ca56d2
1 parent d81a468 commit 52468c8

6 files changed

Lines changed: 63 additions & 2 deletions

File tree

src/com/facebook/buck/cxx/CxxIncludePaths.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ImmutableList<String> getFlags(
9393
MoreIterables.zipAndConcat(
9494
Iterables.cycle("-F"),
9595
getFPaths().stream()
96-
.filter(x -> !x.isSDKROOTFrameworkPath())
96+
.filter(x -> !x.isImplicitlyIncludedInSearchPaths())
9797
.map(frameworkPathTransformer)
9898
.filter(Optional::isPresent)
9999
.map(Optional::get)

src/com/facebook/buck/rules/coercer/FrameworkPath.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
@BuckStyleValue
4141
public abstract class FrameworkPath implements Comparable<FrameworkPath>, AddsToRuleKey {
4242

43+
/**
44+
* A list of implicitly included framework search paths relative to SDKROOT. Those paths do not
45+
* require passing -F parameters when compiling and linking. All other SDKROOT framework paths
46+
* require -F params.
47+
*/
48+
private static final String[] IMPLICIT_SDKROOT_FRAMEWORK_SEARCH_PATHS =
49+
new String[] {
50+
"Library/Frameworks", "System/Library/Frameworks",
51+
};
52+
4353
/** The type of framework entry this object represents. */
4454
protected enum Type {
4555
/** An Xcode style {@link SourceTreePath}. */
@@ -84,6 +94,28 @@ public boolean isSDKROOTFrameworkPath() {
8494
return false;
8595
}
8696

97+
/**
98+
* Determines whether a framework path is implicitly included as part of the compiler and linker.
99+
* If a framework is implicitly included, there's no neeed
100+
*/
101+
public boolean isImplicitlyIncludedInSearchPaths() {
102+
return getSourceTreePath()
103+
.map(
104+
sourceTreePath -> {
105+
if (sourceTreePath.getSourceTree() == PBXReference.SourceTree.SDKROOT) {
106+
Path path = sourceTreePath.getPath();
107+
for (String implicitPath : IMPLICIT_SDKROOT_FRAMEWORK_SEARCH_PATHS) {
108+
if (path.startsWith(implicitPath)) {
109+
return true;
110+
}
111+
}
112+
}
113+
114+
return false;
115+
})
116+
.orElse(false);
117+
}
118+
87119
/** Returns true if the framework is in the PLATFORM_DIR */
88120
public boolean isPlatformDirFrameworkPath() {
89121
if (getSourceTreePath().isPresent()) {

src/com/facebook/buck/swift/SwiftCompileBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public ImmutableList<String> constructCompilerArgs(SourcePathResolverAdapter res
402402

403403
argBuilder.addAll(
404404
Streams.concat(frameworks.stream(), cxxDeps.getFrameworkPaths().stream())
405-
.filter(x -> !x.isSDKROOTFrameworkPath())
405+
.filter(x -> !x.isImplicitlyIncludedInSearchPaths())
406406
.map(frameworkPathToSearchPath)
407407
.filter(Optional::isPresent)
408408
.map(Optional::get)

test/com/facebook/buck/apple/AppleTestIntegrationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ public void testSetsFrameworkSearchPathAndLinksCorrectly() throws IOException {
209209
testSetsFrameworkSearchPathAndLinksCorrectlyWithTargetName("foo");
210210
}
211211

212+
@Test
213+
public void testSetsFrameworkSearchPathAndLinksCorrectlyForDevFramework() throws IOException {
214+
testSetsFrameworkSearchPathAndLinksCorrectlyWithTargetName("dev_framework_usage");
215+
}
216+
212217
private void testSetsFrameworkSearchPathAndLinksCorrectlyWithTargetName(String targetName)
213218
throws IOException {
214219
ProjectWorkspace workspace =

test/com/facebook/buck/apple/testdata/apple_test_framework_search_path/BUCK.fixture

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ apple_test(
77
],
88
info_plist = "Test.plist",
99
)
10+
11+
apple_test(
12+
name = "dev_framework_usage",
13+
srcs = ["DevFrameworkUsage.m"],
14+
frameworks = [
15+
"$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework",
16+
"$SDKROOT/Developer/Library/Frameworks/StoreKitTest.framework",
17+
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
18+
],
19+
info_plist = "Test.plist",
20+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import <XCTest/XCTest.h>
2+
#import <StoreKitTest/StoreKitTest.h>
3+
4+
@interface FooTest : XCTestCase
5+
@end
6+
7+
@implementation FooTest
8+
9+
- (void)testFoo {
10+
XCTFail(@"whoops");
11+
}
12+
13+
@end

0 commit comments

Comments
 (0)