Skip to content

Commit 2d48489

Browse files
authoredNov 15, 2024··
[Clang][Darwin] Introduce SubFrameworks as a SDK default location (#115048)
* Have clang always append & pass System/Library/SubFrameworks when determining default sdk search paths. * Teach clang-installapi to traverse there for framework input. * Teach llvm-readtapi that the library files (TBD or binary) in there should be considered private. resolves: rdar://137457006
1 parent 2188a56 commit 2d48489

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed
 

‎clang/lib/InstallAPI/DirectoryScanner.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ llvm::Error DirectoryScanner::scanForFrameworks(StringRef Directory) {
277277
// Expect a certain directory structure and naming convention to find
278278
// frameworks.
279279
static const char *SubDirectories[] = {"System/Library/Frameworks/",
280-
"System/Library/PrivateFrameworks/"};
280+
"System/Library/PrivateFrameworks/",
281+
"System/Library/SubFrameworks"};
281282

282283
// Check if the directory is already a framework.
283284
if (isFramework(Directory)) {

‎clang/lib/Lex/InitHeaderSearch.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(
346346
AddPath("/System/DriverKit/System/Library/Frameworks", System, true);
347347
} else {
348348
AddPath("/System/Library/Frameworks", System, true);
349+
AddPath("/System/Library/SubFrameworks", System, true);
349350
AddPath("/Library/Frameworks", System, true);
350351
}
351352
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// UNSUPPORTED: system-windows
2+
// Windows is unsupported because we use the Unix path separator `\`.
3+
4+
// Add default directories before running clang to check default
5+
// search paths.
6+
// RUN: rm -rf %t && mkdir -p %t
7+
// RUN: cp -R %S/Inputs/MacOSX15.1.sdk %t/
8+
// RUN: mkdir -p %t/MacOSX15.1.sdk/System/Library/Frameworks
9+
// RUN: mkdir -p %t/MacOSX15.1.sdk/System/Library/SubFrameworks
10+
// RUN: mkdir -p %t/MacOSX15.1.sdk/usr/include
11+
12+
// RUN: %clang %s -target arm64-apple-darwin13.0 -isysroot %t/MacOSX15.1.sdk -E -v 2>&1 | FileCheck %s
13+
14+
// CHECK: -isysroot [[PATH:[^ ]*/MacOSX15.1.sdk]]
15+
// CHECK: #include <...> search starts here:
16+
// CHECK: [[PATH]]/usr/include
17+
// CHECK: [[PATH]]/System/Library/Frameworks (framework directory)
18+
// CHECK: [[PATH]]/System/Library/SubFrameworks (framework directory)

‎llvm/lib/TextAPI/Utils.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ bool llvm::MachO::isPrivateLibrary(StringRef Path, bool IsSymLink) {
120120
if (Path.starts_with("/System/Library/PrivateFrameworks"))
121121
return true;
122122

123+
if (Path.starts_with("/System/Library/SubFrameworks"))
124+
return true;
125+
123126
// Everything in /usr/lib/swift (including sub-directories) are considered
124127
// public.
125128
if (Path.consume_front("/usr/lib/swift/"))

‎llvm/test/tools/llvm-readtapi/stubify-delete.test

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
# Setup a mix of public and private libraries that resemble apple sdk.
33
; RUN: mkdir -p %t/sysroot/usr/local/lib/ %t/sysroot/usr/lib/
44
; RUN: mkdir -p %t/sysroot/System/Library/Frameworks/System.framework %t/sysroot/System/Library/PrivateFrameworks/Fat.framework
5+
; RUN: mkdir -p %t/sysroot/System/Library/SubFrameworks/Fat.framework/Headers
56
; RUN: yaml2obj %S/Inputs/libSystem.1.yaml -o %t/sysroot/System/Library/Frameworks/System.framework/System
67
; RUN: yaml2obj %S/Inputs/objc.yaml -o %t/sysroot/usr/lib/libobjc.dylib
78
; RUN: cp %t/sysroot/usr/lib/libobjc.dylib %t/sysroot/usr/local/lib/libobjc-unstable.dylib
89
; RUN: yaml2obj %S/Inputs/universal.yaml -o %t/sysroot/System/Library/PrivateFrameworks/Fat.framework/Fat
10+
; RUN: cp %t/sysroot/System/Library/PrivateFrameworks/Fat.framework/Fat %t/sysroot/System/Library/SubFrameworks/Fat.framework/Fat
11+
; RUN: touch %t/sysroot/System/Library/SubFrameworks/Fat.framework/Headers/Fat.h
912
; RUN: llvm-readtapi -stubify %t/sysroot --delete-input --delete-private-libraries 2>&1 | FileCheck %s --allow-empty --implicit-check-not warning: --implicit-check-not error:
1013
# Validate expected files are removed.
1114
; RUN: not test -f %t/sysroot/System/Library/PrivateFrameworks
1215
; RUN: not test -f %t/sysroot/usr/local
1316
; RUN: not test -f %t/sysroot/usr/lib/libobjc.dylib
1417
; RUN: not test -f %t/sysroot/System/Library/Frameworks/System.framework/System
18+
; RUN: not test -f %t/sysroot/System/Library/SubFrameworks/Fat.framework/Fat
1519
; RUN: test -f %t/sysroot/System/Library/Frameworks/System.framework/System.tbd
1620
; RUN: test -f %t/sysroot/usr/lib/libobjc.tbd
17-
18-
21+
; RUN: test -f %t/sysroot/System/Library/SubFrameworks/Fat.framework/Headers/Fat.h

‎llvm/tools/llvm-readtapi/llvm-readtapi.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,21 @@ static void stubifyDirectory(const StringRef InputPath, Context &Ctx) {
255255
if (EC)
256256
reportError(IT->path() + ": " + EC.message());
257257

258-
// Skip header directories (include/Headers/PrivateHeaders) and module
259-
// files.
258+
// Skip header directories (include/Headers/PrivateHeaders).
260259
StringRef Path = IT->path();
261-
if (Path.ends_with("/include") || Path.ends_with("/Headers") ||
262-
Path.ends_with("/PrivateHeaders") || Path.ends_with("/Modules") ||
263-
Path.ends_with(".map") || Path.ends_with(".modulemap")) {
264-
IT.no_push();
265-
continue;
260+
if (sys::fs::is_directory(Path)) {
261+
const StringRef Stem = sys::path::stem(Path);
262+
if ((Stem == "include") || (Stem == "Headers") ||
263+
(Stem == "PrivateHeaders") || (Stem == "Modules")) {
264+
IT.no_push();
265+
continue;
266+
}
266267
}
267268

269+
// Skip module files too.
270+
if (Path.ends_with(".map") || Path.ends_with(".modulemap"))
271+
continue;
272+
268273
// Check if the entry is a symlink. We don't follow symlinks but we record
269274
// their content.
270275
bool IsSymLink;

0 commit comments

Comments
 (0)
Please sign in to comment.