Skip to content

[readtapi] Add Extract & Remove architecture functionality #72657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-readtapi/command-line.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
; RUN: not llvm-readtapi -merge -compact %t/tmp.tbd %t/tmp2.tbd --filetype=tbd-v2 2>&1 | FileCheck %s --check-prefix FILE_FORMAT

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

Expand Down
53 changes: 53 additions & 0 deletions llvm/test/tools/llvm-readtapi/extract-invalid.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: not llvm-readtapi -extract %t/libfoo.tbd %t/libbar.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix EXTRA
; RUN: not llvm-readtapi -extract %t/libfoo.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix MISSING
; RUN: not llvm-readtapi -arch x86_64 -extract %t/libfoo.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix MISMATCH

; EXTRA: error: extract only supports one input file
; MISSING: extract requires -arch <arch>
; MISMATCH: error: {{.*}}libfoo.tbd' file doesn't have architecture 'x86_64'

;--- libfoo.tbd
--- !tapi-tbd
tbd-version: 4
targets: [ arm64-ios ]
flags: [ not_app_extension_safe ]
install-name: '/usr/lib/libfoo.dylib'
exports:
- targets: [ arm64-ios ]
symbols: [ _bar ]
...

;--- libbar.tbd
{
"main_library": {
"exported_symbols": [
{
"data": {
"global": [
"_bar"
]
}
}
],
"flags": [
{
"attributes": [
"not_app_extension_safe"
]
}
],
"install_names": [
{
"name": "/usr/lib/libbar.dylib"
}
],
"target_info": [
{
"target": "arm64-ios"
}
]
},
"tapi_tbd_version": 5
}
201 changes: 201 additions & 0 deletions llvm/test/tools/llvm-readtapi/extract.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: llvm-readtapi -arch x86_64 -extract %t/libfat.tbd -compact -o %t/libslim.tbd 2>&1 | FileCheck --allow-empty %s
; RUN: llvm-readtapi --compare %t/libslim.tbd %t/libslim_expected.tbd 2>&1 | FileCheck --allow-empty %s

; RUN: llvm-readtapi -arch armv7s --extract %t/libfat2.tbd 2>&1 | FileCheck %s --check-prefix OUTPUT

; CHECK-NOT: error
; CHECK-NOT: warning

; OUTPUT: {
; OUTPUT-NEXT: "main_library": {
; OUTPUT-NEXT: "install_names": [
; OUTPUT-NEXT: {
; OUTPUT-NEXT: "name": "/usr/lib/libfat.dylib"
; OUTPUT-NEXT: }
; OUTPUT-NEXT: ],
; OUTPUT-NEXT: "target_info": [
; OUTPUT-NEXT: {
; OUTPUT-NEXT: "target": "armv7s-ios"
; OUTPUT-NEXT: }
; OUTPUT-NEXT: ]
; OUTPUT-NEXT: },
; OUTPUT-NEXT: "tapi_tbd_version": 5
; OUTPUT-NEXT: }

//--- libfat.tbd
{
"libraries": [
{
"exported_symbols": [
{
"data": {
"global": [
"_sym1"
]
},
"targets": [
"x86_64-macos"
]
},
{
"data": {
"global": [
"_sym2"
]
},
"targets": [
"x86_64h-macos"
]
}
],
"install_names": [
{
"name": "/usr/lib/internal/libfat.dylib"
}
],
"parent_umbrellas": [
{
"umbrella": "fat"
}
],
"target_info": [
{
"target": "x86_64-macos"
},
{
"target": "x86_64h-macos"
}
]
}
],
"main_library": {
"install_names": [
{
"name": "/usr/lib/libfat.dylib"
}
],
"reexported_libraries": [
{
"names": [
"/usr/lib/internal/libfat.dylib"
]
}
],
"target_info": [
{
"target": "x86_64-macos"
},
{
"target": "x86_64h-macos"
}
]
},
"tapi_tbd_version": 5
}

//--- libfat2.tbd
{
"libraries": [
{
"exported_symbols": [
{
"data": {
"global": [
"_sym1"
]
}
}
],
"install_names": [
{
"name": "/usr/lib/internal/libfat.dylib"
}
],
"target_info": [
{
"target": "arm64-ios"
}
]
}
],
"main_library": {
"install_names": [
{
"name": "/usr/lib/libfat.dylib"
}
],
"reexported_libraries": [
{
"names": [
"/usr/lib/internal/libfat.dylib"
],
"targets": [
"arm64-ios"
]
}
],
"target_info": [
{
"target": "armv7s-ios"
},
{
"target": "arm64-ios"
}
]
},
"tapi_tbd_version": 5
}

//--- libslim_expected.tbd
{
"libraries": [
{
"exported_symbols": [
{
"data": {
"global": [
"_sym1"
]
}
}
],
"install_names": [
{
"name": "/usr/lib/internal/libfat.dylib"
}
],
"parent_umbrellas": [
{
"umbrella": "fat"
}
],
"target_info": [
{
"target": "x86_64-macos"
}
]
}
],
"main_library": {
"install_names": [
{
"name": "/usr/lib/libfat.dylib"
}
],
"reexported_libraries": [
{
"names": [
"/usr/lib/internal/libfat.dylib"
]
}
],
"target_info": [
{
"target": "x86_64-macos"
}
]
},
"tapi_tbd_version": 5
}
57 changes: 57 additions & 0 deletions llvm/test/tools/llvm-readtapi/remove-invalid.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: not llvm-readtapi --remove -arch arm64 %t/libslim.tbd 2>&1 | FileCheck %s

CHECK: {{.*}}libslim.tbd' cannot remove last architecture slice 'arm64'

//--- libslim.tbd
{
"libraries": [
{
"exported_symbols": [
{
"data": {
"global": [
"_sym1"
]
}
}
],
"install_names": [
{
"name": "/usr/lib/internal/libfat.dylib"
}
],
"parent_umbrellas": [
{
"umbrella": "fat"
}
],
"target_info": [
{
"target": "arm64-macos"
}
]
}
],
"main_library": {
"install_names": [
{
"name": "/usr/lib/libfat.dylib"
}
],
"reexported_libraries": [
{
"names": [
"/usr/lib/internal/libfat.dylib"
]
}
],
"target_info": [
{
"target": "arm64-macos"
}
]
},
"tapi_tbd_version": 5
}
Loading