Skip to content

Commit 982604c

Browse files
committed
[llvm-tapi-diff] Replicate diff utility error handling
For scripting purposes, use different error code for cases that aren't a result of different tbd files, e.g. bad input like a path to a broken symlink. This behaves more similiarly to how the unix `diff` command behaves. This also includes minor tweaks on error messages. Reviewed By: ributzka, JDevlieghere Differential Revision: https://reviews.llvm.org/D115905
1 parent 9927a06 commit 982604c

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

llvm/test/tools/llvm-tapi-diff/tapi-diff-incorrect-format.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
; RUN: yaml2obj %S/Inputs/macho.yaml -o %t/macho.dylib
33
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %t/macho.dylib 2>&1 | FileCheck %s
44

5-
; CHECK: {{.*}}: error: {{.*}}macho.dylib: Error when parsing file, unsupported file format
5+
; CHECK: error: {{.*}}macho.dylib' unsupported file format
66
; CHECK-NOT: error:
77
; CHECK-NOT: warning:
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck %s -DMSG=%errc_ENOENT
1+
; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck %s
22

3-
; CHECK: {{.*}}: error: {{.*}}v4.tbd: [[MSG]]
4-
; CHECK-NOT: error:
5-
; CHECK-NOT: warning:
3+
; CHECK: error: {{.*}}v4.tbd' {{[Nn]}}o such file or directory

llvm/tools/llvm-tapi-diff/llvm-tapi-diff.cpp

+9-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//===-- llvm-tapi-diff.cpp - tbd comparator command-line driver ---*-
2-
// C++
3-
//-*-===//
1+
//===-- llvm-tapi-diff.cpp - tbd comparator command-line driver --*- C++-*-===//
42
//
53
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
64
// See https://llvm.org/LICENSE.txt for license information.
@@ -31,16 +29,8 @@ cl::opt<std::string> InputFileNameLHS(cl::Positional, cl::desc("<first file>"),
3129
cl::cat(NMCat));
3230
cl::opt<std::string> InputFileNameRHS(cl::Positional, cl::desc("<second file>"),
3331
cl::cat(NMCat));
34-
35-
std::string ToolName;
3632
} // anonymous namespace
3733

38-
ExitOnError ExitOnErr;
39-
40-
void setErrorBanner(ExitOnError &ExitOnErr, std::string InputFile) {
41-
ExitOnErr.setBanner(ToolName + ": error: " + InputFile + ": ");
42-
}
43-
4434
Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
4535
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
4636
MemoryBuffer::getFileOrSTDIN(Filename);
@@ -52,35 +42,29 @@ Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
5242
int main(int Argc, char **Argv) {
5343
InitLLVM X(Argc, Argv);
5444
cl::HideUnrelatedOptions(NMCat);
55-
cl::ParseCommandLineOptions(
56-
Argc, Argv,
57-
"This tool will compare two tbd files and return the "
58-
"differences in those files.");
45+
cl::ParseCommandLineOptions(Argc, Argv, "Text-based Stubs Comparison Tool");
5946
if (InputFileNameLHS.empty() || InputFileNameRHS.empty()) {
6047
cl::PrintHelpMessage();
6148
return EXIT_FAILURE;
6249
}
6350

64-
ToolName = Argv[0];
65-
66-
setErrorBanner(ExitOnErr, InputFileNameLHS);
51+
ExitOnError ExitOnErr("error: '" + InputFileNameLHS + "' ",
52+
/*DefaultErrorExitCode=*/2);
6753
auto BinLHS = ExitOnErr(convertFileToBinary(InputFileNameLHS));
6854

6955
TapiUniversal *FileLHS = dyn_cast<TapiUniversal>(BinLHS.get());
7056
if (!FileLHS) {
71-
ExitOnErr(
72-
createStringError(std::errc::executable_format_error,
73-
"Error when parsing file, unsupported file format"));
57+
ExitOnErr(createStringError(std::errc::executable_format_error,
58+
"unsupported file format"));
7459
}
7560

76-
setErrorBanner(ExitOnErr, InputFileNameRHS);
61+
ExitOnErr.setBanner("error: '" + InputFileNameRHS + "' ");
7762
auto BinRHS = ExitOnErr(convertFileToBinary(InputFileNameRHS));
7863

7964
TapiUniversal *FileRHS = dyn_cast<TapiUniversal>(BinRHS.get());
8065
if (!FileRHS) {
81-
ExitOnErr(
82-
createStringError(std::errc::executable_format_error,
83-
"Error when parsing file, unsupported file format"));
66+
ExitOnErr(createStringError(std::errc::executable_format_error,
67+
"unsupported file format"));
8468
}
8569

8670
raw_ostream &OS = outs();

0 commit comments

Comments
 (0)