Skip to content

Commit e1f69b8

Browse files
authored
[readtapi] Add Extract & Remove architecture functionality (#72657)
This adds functionality to tbd files similar to what `lipo -extract` and `lipo -remove` does for binaries.
1 parent f45453a commit e1f69b8

File tree

7 files changed

+625
-5
lines changed

7 files changed

+625
-5
lines changed

llvm/test/tools/llvm-readtapi/command-line.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; RUN: not llvm-readtapi -merge -compact %t/tmp.tbd %t/tmp2.tbd --filetype=tbd-v2 2>&1 | FileCheck %s --check-prefix FILE_FORMAT
55

66
CHECK: OVERVIEW: LLVM TAPI file reader and manipulator
7-
CHECK: USAGE: llvm-readtapi [options] <inputs>
7+
CHECK: USAGE: llvm-readtapi [options] [-arch <arch>]* <inputs> [-o <output>]*
88
CHECK: OPTIONS:
99
CHECK: -help display this help
1010

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
; RUN: not llvm-readtapi -extract %t/libfoo.tbd %t/libbar.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix EXTRA
4+
; RUN: not llvm-readtapi -extract %t/libfoo.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix MISSING
5+
; RUN: not llvm-readtapi -arch x86_64 -extract %t/libfoo.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix MISMATCH
6+
7+
; EXTRA: error: extract only supports one input file
8+
; MISSING: extract requires -arch <arch>
9+
; MISMATCH: error: {{.*}}libfoo.tbd' file doesn't have architecture 'x86_64'
10+
11+
;--- libfoo.tbd
12+
--- !tapi-tbd
13+
tbd-version: 4
14+
targets: [ arm64-ios ]
15+
flags: [ not_app_extension_safe ]
16+
install-name: '/usr/lib/libfoo.dylib'
17+
exports:
18+
- targets: [ arm64-ios ]
19+
symbols: [ _bar ]
20+
...
21+
22+
;--- libbar.tbd
23+
{
24+
"main_library": {
25+
"exported_symbols": [
26+
{
27+
"data": {
28+
"global": [
29+
"_bar"
30+
]
31+
}
32+
}
33+
],
34+
"flags": [
35+
{
36+
"attributes": [
37+
"not_app_extension_safe"
38+
]
39+
}
40+
],
41+
"install_names": [
42+
{
43+
"name": "/usr/lib/libbar.dylib"
44+
}
45+
],
46+
"target_info": [
47+
{
48+
"target": "arm64-ios"
49+
}
50+
]
51+
},
52+
"tapi_tbd_version": 5
53+
}
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
; RUN: llvm-readtapi -arch x86_64 -extract %t/libfat.tbd -compact -o %t/libslim.tbd 2>&1 | FileCheck --allow-empty %s
4+
; RUN: llvm-readtapi --compare %t/libslim.tbd %t/libslim_expected.tbd 2>&1 | FileCheck --allow-empty %s
5+
6+
; RUN: llvm-readtapi -arch armv7s --extract %t/libfat2.tbd 2>&1 | FileCheck %s --check-prefix OUTPUT
7+
8+
; CHECK-NOT: error
9+
; CHECK-NOT: warning
10+
11+
; OUTPUT: {
12+
; OUTPUT-NEXT: "main_library": {
13+
; OUTPUT-NEXT: "install_names": [
14+
; OUTPUT-NEXT: {
15+
; OUTPUT-NEXT: "name": "/usr/lib/libfat.dylib"
16+
; OUTPUT-NEXT: }
17+
; OUTPUT-NEXT: ],
18+
; OUTPUT-NEXT: "target_info": [
19+
; OUTPUT-NEXT: {
20+
; OUTPUT-NEXT: "target": "armv7s-ios"
21+
; OUTPUT-NEXT: }
22+
; OUTPUT-NEXT: ]
23+
; OUTPUT-NEXT: },
24+
; OUTPUT-NEXT: "tapi_tbd_version": 5
25+
; OUTPUT-NEXT: }
26+
27+
//--- libfat.tbd
28+
{
29+
"libraries": [
30+
{
31+
"exported_symbols": [
32+
{
33+
"data": {
34+
"global": [
35+
"_sym1"
36+
]
37+
},
38+
"targets": [
39+
"x86_64-macos"
40+
]
41+
},
42+
{
43+
"data": {
44+
"global": [
45+
"_sym2"
46+
]
47+
},
48+
"targets": [
49+
"x86_64h-macos"
50+
]
51+
}
52+
],
53+
"install_names": [
54+
{
55+
"name": "/usr/lib/internal/libfat.dylib"
56+
}
57+
],
58+
"parent_umbrellas": [
59+
{
60+
"umbrella": "fat"
61+
}
62+
],
63+
"target_info": [
64+
{
65+
"target": "x86_64-macos"
66+
},
67+
{
68+
"target": "x86_64h-macos"
69+
}
70+
]
71+
}
72+
],
73+
"main_library": {
74+
"install_names": [
75+
{
76+
"name": "/usr/lib/libfat.dylib"
77+
}
78+
],
79+
"reexported_libraries": [
80+
{
81+
"names": [
82+
"/usr/lib/internal/libfat.dylib"
83+
]
84+
}
85+
],
86+
"target_info": [
87+
{
88+
"target": "x86_64-macos"
89+
},
90+
{
91+
"target": "x86_64h-macos"
92+
}
93+
]
94+
},
95+
"tapi_tbd_version": 5
96+
}
97+
98+
//--- libfat2.tbd
99+
{
100+
"libraries": [
101+
{
102+
"exported_symbols": [
103+
{
104+
"data": {
105+
"global": [
106+
"_sym1"
107+
]
108+
}
109+
}
110+
],
111+
"install_names": [
112+
{
113+
"name": "/usr/lib/internal/libfat.dylib"
114+
}
115+
],
116+
"target_info": [
117+
{
118+
"target": "arm64-ios"
119+
}
120+
]
121+
}
122+
],
123+
"main_library": {
124+
"install_names": [
125+
{
126+
"name": "/usr/lib/libfat.dylib"
127+
}
128+
],
129+
"reexported_libraries": [
130+
{
131+
"names": [
132+
"/usr/lib/internal/libfat.dylib"
133+
],
134+
"targets": [
135+
"arm64-ios"
136+
]
137+
}
138+
],
139+
"target_info": [
140+
{
141+
"target": "armv7s-ios"
142+
},
143+
{
144+
"target": "arm64-ios"
145+
}
146+
]
147+
},
148+
"tapi_tbd_version": 5
149+
}
150+
151+
//--- libslim_expected.tbd
152+
{
153+
"libraries": [
154+
{
155+
"exported_symbols": [
156+
{
157+
"data": {
158+
"global": [
159+
"_sym1"
160+
]
161+
}
162+
}
163+
],
164+
"install_names": [
165+
{
166+
"name": "/usr/lib/internal/libfat.dylib"
167+
}
168+
],
169+
"parent_umbrellas": [
170+
{
171+
"umbrella": "fat"
172+
}
173+
],
174+
"target_info": [
175+
{
176+
"target": "x86_64-macos"
177+
}
178+
]
179+
}
180+
],
181+
"main_library": {
182+
"install_names": [
183+
{
184+
"name": "/usr/lib/libfat.dylib"
185+
}
186+
],
187+
"reexported_libraries": [
188+
{
189+
"names": [
190+
"/usr/lib/internal/libfat.dylib"
191+
]
192+
}
193+
],
194+
"target_info": [
195+
{
196+
"target": "x86_64-macos"
197+
}
198+
]
199+
},
200+
"tapi_tbd_version": 5
201+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
; RUN: not llvm-readtapi --remove -arch arm64 %t/libslim.tbd 2>&1 | FileCheck %s
4+
5+
CHECK: {{.*}}libslim.tbd' cannot remove last architecture slice 'arm64'
6+
7+
//--- libslim.tbd
8+
{
9+
"libraries": [
10+
{
11+
"exported_symbols": [
12+
{
13+
"data": {
14+
"global": [
15+
"_sym1"
16+
]
17+
}
18+
}
19+
],
20+
"install_names": [
21+
{
22+
"name": "/usr/lib/internal/libfat.dylib"
23+
}
24+
],
25+
"parent_umbrellas": [
26+
{
27+
"umbrella": "fat"
28+
}
29+
],
30+
"target_info": [
31+
{
32+
"target": "arm64-macos"
33+
}
34+
]
35+
}
36+
],
37+
"main_library": {
38+
"install_names": [
39+
{
40+
"name": "/usr/lib/libfat.dylib"
41+
}
42+
],
43+
"reexported_libraries": [
44+
{
45+
"names": [
46+
"/usr/lib/internal/libfat.dylib"
47+
]
48+
}
49+
],
50+
"target_info": [
51+
{
52+
"target": "arm64-macos"
53+
}
54+
]
55+
},
56+
"tapi_tbd_version": 5
57+
}

0 commit comments

Comments
 (0)