Unverified Commit ae182dbb authored by Cyndy Ishida's avatar Cyndy Ishida Committed by GitHub
Browse files

[readtapi] Add Merge functionality (#72656)

Merge allows a user to merge different files (tbds for now or dylibs in
the future) to emit out a single tbd with all input contents. This does
require that all inputs represent the same library.
parent 144b2f57
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#ifndef LLVM_TEXTAPI_TEXTAPIWRITER_H
#define LLVM_TEXTAPI_TEXTAPIWRITER_H

#include "llvm/ADT/StringSwitch.h"
#include "llvm/TextAPI/InterfaceFile.h"

namespace llvm {
@@ -32,6 +33,19 @@ public:
  static Error writeToStream(raw_ostream &OS, const InterfaceFile &File,
                             const FileType FileKind = FileType::Invalid,
                             bool Compact = false);

  /// Get TAPI FileType from the input string.
  ///
  /// \param FT String of input to map to FileType.
  static FileType parseFileType(const StringRef FT) {
    return StringSwitch<FileType>(FT)
        .Case("tbd-v1", FileType::TBD_V1)
        .Case("tbd-v2", FileType::TBD_V2)
        .Case("tbd-v3", FileType::TBD_V3)
        .Case("tbd-v4", FileType::TBD_V4)
        .Case("tbd-v5", FileType::TBD_V5)
        .Default(FileType::Invalid);
  }
};

} // end namespace MachO.
+6 −0
Original line number Diff line number Diff line
; RUN: llvm-readtapi --help 2>&1 | FileCheck %s 
; RUN: llvm-readtapi -help 2>&1 | FileCheck %s 
; RUN: not llvm-readtapi -merge -compare -compact %t/tmp.tbd %t/tmp2.tbd 2>&1 | FileCheck %s --check-prefix MULTI_ACTION
; 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: OPTIONS:
CHECK:   -help    display this help

MULTI_ACTION: error: only one of the following actions can be specified: -merge -compare
FILE_FORMAT: error: deprecated filetype 'tbd-v2' is not supported to write
+1 −1
Original line number Diff line number Diff line
@@ -2,6 +2,6 @@
; RUN: yaml2obj %S/Inputs/macho.yaml -o %t/macho.dylib
; RUN: not llvm-readtapi --compare %S/Inputs/v4A.tbd %t/macho.dylib 2>&1 | FileCheck %s

; CHECK: error: {{.*}}macho.dylib' unsupported file format
; CHECK: error: {{.*}}macho.dylib' unsupported file type 
; CHECK-NOT: error:
; CHECK-NOT: warning:
+52 −0
Original line number Diff line number Diff line
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: not llvm-readtapi -merge %t/libfoo.tbd %t/libbar.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix DIFF
; RUN: not llvm-readtapi -merge %t/libfoo.tbd 2>&1 | FileCheck %s --allow-empty --check-prefix INPUT

; DIFF: install names do not match
; INPUT: merge requires at least two input files

;--- libfoo.tbd
{
  "main_library": {
    "allowable_clients": [
      {
        "clients": [
          "ClientAll"
        ]
      }
    ],
    "install_names": [
      {
        "name": "/usr/lib/libfoo.dylib"
      }
    ],
    "target_info": [
      {
        "min_deployment": "13.1",
        "target": "x86_64-macos"
      }
    ]
  },
  "tapi_tbd_version": 5
}

;--- libbar.tbd
--- !tapi-tbd
tbd-version:     4
targets:         [ arm64-macos ]
install-name:    '/usr/lib/libbar.dylib'
allowable-clients:
  - targets:         [ arm64-macos ]
    clients:         [ ClientAll ]
reexported-libraries:
  - targets:         [ arm64-macos ]
    libraries:       [ '/usr/lib/liball.dylib' ]
exports:
  - targets:         [ arm64-macos ]
    symbols:         [ _sym1 ]
    objc-classes:    [ _A ]
    objc-ivars:      [ _A._ivar1 ]
    weak-symbols:    [ _weak1 ]
    thread-local-symbols: [ _tlv1 ]
...
+139 −0
Original line number Diff line number Diff line
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: llvm-readtapi -merge %t/i386.tbd %t/x86_64.tbd %t/arm64.tbd --filetype tbd-v5 -o %t/out.tbd -compact 2>&1 | FileCheck %s --allow-empty 
; RUN: llvm-readtapi -merge %t/i386.tbd %t/x86_64.tbd %t/arm64.tbd --filetype=tbd-v5 --o %t/out.tbd -compact 2>&1 | FileCheck %s --allow-empty 
; RUN: llvm-readtapi -compare %t/out.tbd %t/expected.tbd 2>&1 | FileCheck %s --allow-empty 

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

;--- expected.tbd
{
    "main_library": {
        "allowable_clients": [{ "clients": ["ClientAll"] }],
        "exported_symbols": [
            {
                "data": {
                    "global": ["_sym1"],
                    "objc_class": ["_A"],
                    "thread_local": ["_tlv1"],
                    "weak": ["_weak1"]
                }
            },
            {
                "data": {
                    "objc_ivar": ["_A._ivar1"]
                },
                "targets": [ "x86_64-macos", "arm64-macos" ]
            }
        ],
        "install_names": [
            { "name": "/usr/lib/libfat.dylib" }
        ],
        "reexported_libraries": [
            {
                "names": [ "/usr/lib/liball.dylib" ]
            }
        ],
        "target_info": [
            { "target": "i386-macos" },
            {
                "min_deployment": "13.1",
                "target": "x86_64-macos"
            },
            {
                "target": "arm64-macos"
            }
        ]
    },
    "tapi_tbd_version": 5
}


;--- i386.tbd
--- !tapi-tbd-v3
archs:           [ i386 ]
platform:        macosx
install-name:    /usr/lib/libfat.dylib
exports:         
  - archs:           [ i386 ]
    allowable-clients: [ ClientAll ]
    re-exports:      [ /usr/lib/liball.dylib ]
    symbols:         [ _sym1 ]
    objc-classes:    [ _A ]
    weak-def-symbols: [ _weak1 ]
    thread-local-symbols: [ _tlv1 ]
...

;--- x86_64.tbd
{
  "main_library": {
    "allowable_clients": [
      {
        "clients": [
          "ClientAll"
        ]
      }
    ],
    "exported_symbols": [
      {
        "data": {
          "global": [
            "_sym1"
          ],
          "objc_class": [
            "_A"
          ],
          "objc_ivar": [
            "_A._ivar1"
          ],
          "thread_local": [
            "_tlv1"
          ],
          "weak": [
            "_weak1"
          ]
        }
      }
    ],
    "install_names": [
      {
        "name": "/usr/lib/libfat.dylib"
      }
    ],
    "reexported_libraries": [
      {
        "names": [
          "/usr/lib/liball.dylib"
        ]
      }
    ],
    "target_info": [
      {
        "min_deployment": "13.1",
        "target": "x86_64-macos"
      }
    ]
  },
  "tapi_tbd_version": 5
}

;--- arm64.tbd
--- !tapi-tbd
tbd-version:     4
targets:         [ arm64-macos ]
install-name:    '/usr/lib/libfat.dylib'
allowable-clients:
  - targets:         [ arm64-macos ]
    clients:         [ ClientAll ]
reexported-libraries:
  - targets:         [ arm64-macos ]
    libraries:       [ '/usr/lib/liball.dylib' ]
exports:
  - targets:         [ arm64-macos ]
    symbols:         [ _sym1 ]
    objc-classes:    [ _A ]
    objc-ivars:      [ _A._ivar1 ]
    weak-symbols:    [ _weak1 ]
    thread-local-symbols: [ _tlv1 ]
...
Loading