mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-24 20:44:09 +00:00
[llvm][tapi-diff] Transition diff-tool to be more general purpose
This is the first of transition tapi-diff to be readtapi. This tool will eventually replace functionality for Xcode's `xcrun tapi stubify` and `xcrun tapi archive`. This patch updates the tool name and is a minor refactor for the driver to handle more options. Reviewed By: zixuw Differential Revision: https://reviews.llvm.org/D153045
This commit is contained in:
parent
ec39506cfc
commit
5656d7971b
@ -131,7 +131,7 @@ set(LLVM_TEST_DEPENDS
|
||||
llvm-strip
|
||||
llvm-symbolizer
|
||||
llvm-tblgen
|
||||
llvm-tapi-diff
|
||||
llvm-readtapi
|
||||
llvm-tli-checker
|
||||
llvm-undname
|
||||
llvm-windres
|
||||
|
@ -225,7 +225,7 @@ tools.extend(
|
||||
"llvm-strings",
|
||||
"llvm-strip",
|
||||
"llvm-tblgen",
|
||||
"llvm-tapi-diff",
|
||||
"llvm-readtapi",
|
||||
"llvm-undname",
|
||||
"llvm-windres",
|
||||
"llvm-c-test",
|
||||
|
@ -1,6 +1,6 @@
|
||||
; RUN: mkdir -p %t
|
||||
; RUN: yaml2obj %S/Inputs/macho.yaml -o %t/macho.dylib
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %t/macho.dylib 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4A.tbd %t/macho.dylib 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK: error: {{.*}}macho.dylib' unsupported file format
|
||||
; CHECK-NOT: error:
|
@ -1,4 +1,4 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4B.tbd %S/Inputs/v4E.tbd 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4B.tbd %S/Inputs/v4E.tbd 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK:< {{.*}}/Inputs/v4B.tbd
|
||||
; CHECK:> {{.*}}/Inputs/v4E.tbd
|
@ -1,4 +1,4 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4B.tbd 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4A.tbd %S/Inputs/v4B.tbd 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK:< {{.*}}/Inputs/v4A.tbd
|
||||
; CHECK:> {{.*}}/Inputs/v4B.tbd
|
@ -0,0 +1,4 @@
|
||||
; RUN: llvm-readtapi --compare %S/Inputs/v4A.tbd %S/Inputs/v4A.tbd 2>&1 | FileCheck %s --allow-empty
|
||||
|
||||
; CHECK-NOT: error:
|
||||
; CHECK-NOT: warning:
|
@ -1,4 +1,4 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4B.tbd %S/Inputs/v4D.tbd 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4B.tbd %S/Inputs/v4D.tbd 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK:< {{.*}}/Inputs/v4B.tbd
|
||||
; CHECK:> {{.*}}/Inputs/v4D.tbd
|
@ -0,0 +1,3 @@
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck -DMSG=%errc_ENOENT %s
|
||||
|
||||
; CHECK: error: {{.*}}v4.tbd' [[MSG]]
|
@ -1,4 +1,4 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4D.tbd 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4A.tbd %S/Inputs/v4D.tbd 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK:< {{.*}}/Inputs/v4A.tbd
|
||||
; CHECK:> {{.*}}/Inputs/v4D.tbd
|
@ -1,4 +1,4 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4C.tbd 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4A.tbd %S/Inputs/v4C.tbd 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK:< {{.*}}/Inputs/v4A.tbd
|
||||
; CHECK:> {{.*}}/Inputs/v4C.tbd
|
@ -1,4 +1,4 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4B.tbd %S/Inputs/v4C.tbd 2>&1 | FileCheck %s
|
||||
; RUN: not llvm-readtapi --compare %S/Inputs/v4B.tbd %S/Inputs/v4C.tbd 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK:< {{.*}}/Inputs/v4B.tbd
|
||||
; CHECK:> {{.*}}/Inputs/v4C.tbd
|
@ -1,7 +1,7 @@
|
||||
; RUN: rm -rf %t
|
||||
; RUN: split-file %s %t
|
||||
; RUN: llvm-tapi-diff %t/Simple_v5.tbd %t/Simple_v5.tbd 2>&1 | FileCheck %s --allow-empty
|
||||
; RUN: llvm-tapi-diff %t/Simple_v5.tbd %t/Simple_v4.tbd 2>&1 | FileCheck %s --allow-empty
|
||||
; RUN: llvm-readtapi --compare %t/Simple_v5.tbd %t/Simple_v5.tbd 2>&1 | FileCheck %s --allow-empty
|
||||
; RUN: llvm-readtapi --compare %t/Simple_v5.tbd %t/Simple_v4.tbd 2>&1 | FileCheck %s --allow-empty
|
||||
|
||||
; CHECK-NOT: error:
|
||||
; CHECK-NOT: warning:
|
@ -1,4 +0,0 @@
|
||||
; RUN: llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4A.tbd 2>&1 | FileCheck %s --allow-empty
|
||||
|
||||
; CHECK-NOT: error:
|
||||
; CHECK-NOT: warning:
|
@ -1,3 +0,0 @@
|
||||
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck -DMSG=%errc_ENOENT %s
|
||||
|
||||
; CHECK: error: {{.*}}v4.tbd' [[MSG]]
|
@ -4,7 +4,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
TextAPI
|
||||
)
|
||||
|
||||
add_llvm_tool(llvm-tapi-diff
|
||||
llvm-tapi-diff.cpp
|
||||
add_llvm_tool(llvm-readtapi
|
||||
llvm-readtapi.cpp
|
||||
DiffEngine.cpp
|
||||
)
|
90
llvm/tools/llvm-readtapi/llvm-readtapi.cpp
Normal file
90
llvm/tools/llvm-readtapi/llvm-readtapi.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
//===-- llvm-readtapi.cpp - tapi file reader and manipulator -----*- C++-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the command-line driver for llvm-readtapi.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "DiffEngine.h"
|
||||
#include "llvm/Object/TapiUniversal.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/WithColor.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace MachO;
|
||||
using namespace object;
|
||||
|
||||
namespace {
|
||||
cl::OptionCategory TapiCat("llvm-readtapi options");
|
||||
cl::OptionCategory CompareCat("llvm-readtapi --compare options");
|
||||
|
||||
cl::opt<std::string> InputFileName(cl::Positional, cl::desc("<tapi file>"),
|
||||
cl::Required, cl::cat(TapiCat));
|
||||
cl::opt<std::string> CompareInputFileName(cl::Positional,
|
||||
cl::desc("<comparison file>"),
|
||||
cl::Required, cl::cat(CompareCat));
|
||||
enum OutputKind {
|
||||
Compare,
|
||||
};
|
||||
|
||||
cl::opt<OutputKind>
|
||||
Output(cl::desc("choose command action:"),
|
||||
cl::values(clEnumValN(Compare, "compare",
|
||||
"compare tapi file for library differences")),
|
||||
cl::init(OutputKind::Compare), cl::cat(TapiCat));
|
||||
} // anonymous namespace
|
||||
|
||||
Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
|
||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
||||
if (BufferOrErr.getError())
|
||||
return errorCodeToError(BufferOrErr.getError());
|
||||
return createBinary(BufferOrErr.get()->getMemBufferRef());
|
||||
}
|
||||
|
||||
int main(int Argc, char **Argv) {
|
||||
InitLLVM X(Argc, Argv);
|
||||
cl::HideUnrelatedOptions(TapiCat);
|
||||
cl::ParseCommandLineOptions(Argc, Argv,
|
||||
"TAPI File Reader and Manipulator Tool");
|
||||
|
||||
if (Output == OutputKind::Compare) {
|
||||
if (InputFileName.empty() || CompareInputFileName.empty()) {
|
||||
cl::PrintHelpMessage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ExitOnError ExitOnErr("error: '" + InputFileName + "' ",
|
||||
/*DefaultErrorExitCode=*/2);
|
||||
auto BinLHS = ExitOnErr(convertFileToBinary(InputFileName));
|
||||
|
||||
TapiUniversal *FileLHS = dyn_cast<TapiUniversal>(BinLHS.get());
|
||||
if (!FileLHS) {
|
||||
ExitOnErr(createStringError(std::errc::executable_format_error,
|
||||
"unsupported file format"));
|
||||
}
|
||||
|
||||
ExitOnErr.setBanner("error: '" + CompareInputFileName + "' ");
|
||||
auto BinRHS = ExitOnErr(convertFileToBinary(CompareInputFileName));
|
||||
|
||||
TapiUniversal *FileRHS = dyn_cast<TapiUniversal>(BinRHS.get());
|
||||
if (!FileRHS) {
|
||||
ExitOnErr(createStringError(std::errc::executable_format_error,
|
||||
"unsupported file format"));
|
||||
}
|
||||
|
||||
raw_ostream &OS = outs();
|
||||
return DiffEngine(FileLHS, FileRHS).compareFiles(OS);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
//===-- llvm-tapi-diff.cpp - tbd comparator command-line driver --*- C++-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the command-line driver for the llvm-tapi difference
|
||||
// engine.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "DiffEngine.h"
|
||||
#include "llvm/Object/TapiUniversal.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/WithColor.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace MachO;
|
||||
using namespace object;
|
||||
|
||||
namespace {
|
||||
cl::OptionCategory NMCat("llvm-tapi-diff Options");
|
||||
cl::opt<std::string> InputFileNameLHS(cl::Positional, cl::desc("<first file>"),
|
||||
cl::cat(NMCat));
|
||||
cl::opt<std::string> InputFileNameRHS(cl::Positional, cl::desc("<second file>"),
|
||||
cl::cat(NMCat));
|
||||
} // anonymous namespace
|
||||
|
||||
Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
|
||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
||||
if (BufferOrErr.getError())
|
||||
return errorCodeToError(BufferOrErr.getError());
|
||||
return createBinary(BufferOrErr.get()->getMemBufferRef());
|
||||
}
|
||||
|
||||
int main(int Argc, char **Argv) {
|
||||
InitLLVM X(Argc, Argv);
|
||||
cl::HideUnrelatedOptions(NMCat);
|
||||
cl::ParseCommandLineOptions(Argc, Argv, "Text-based Stubs Comparison Tool");
|
||||
if (InputFileNameLHS.empty() || InputFileNameRHS.empty()) {
|
||||
cl::PrintHelpMessage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ExitOnError ExitOnErr("error: '" + InputFileNameLHS + "' ",
|
||||
/*DefaultErrorExitCode=*/2);
|
||||
auto BinLHS = ExitOnErr(convertFileToBinary(InputFileNameLHS));
|
||||
|
||||
TapiUniversal *FileLHS = dyn_cast<TapiUniversal>(BinLHS.get());
|
||||
if (!FileLHS) {
|
||||
ExitOnErr(createStringError(std::errc::executable_format_error,
|
||||
"unsupported file format"));
|
||||
}
|
||||
|
||||
ExitOnErr.setBanner("error: '" + InputFileNameRHS + "' ");
|
||||
auto BinRHS = ExitOnErr(convertFileToBinary(InputFileNameRHS));
|
||||
|
||||
TapiUniversal *FileRHS = dyn_cast<TapiUniversal>(BinRHS.get());
|
||||
if (!FileRHS) {
|
||||
ExitOnErr(createStringError(std::errc::executable_format_error,
|
||||
"unsupported file format"));
|
||||
}
|
||||
|
||||
raw_ostream &OS = outs();
|
||||
|
||||
return DiffEngine(FileLHS, FileRHS).compareFiles(OS);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user