[llvm] 982604c - [llvm-tapi-diff] Replicate diff utility error handling
Cyndy Ishida via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 18 10:13:55 PST 2021
Author: Cyndy Ishida
Date: 2021-12-18T09:54:37-08:00
New Revision: 982604cc08caa56fc707fe88cb0050fb99a14de4
URL: https://github.com/llvm/llvm-project/commit/982604cc08caa56fc707fe88cb0050fb99a14de4
DIFF: https://github.com/llvm/llvm-project/commit/982604cc08caa56fc707fe88cb0050fb99a14de4.diff
LOG: [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
Added:
Modified:
llvm/test/tools/llvm-tapi-diff/tapi-diff-incorrect-format.test
llvm/test/tools/llvm-tapi-diff/tapi-diff-misspelled-tbd.test
llvm/tools/llvm-tapi-diff/llvm-tapi-diff.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -incorrect-format.test b/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -incorrect-format.test
index 4755f3abad3b..6eb0ab6a3aed 100644
--- a/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -incorrect-format.test
+++ b/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -incorrect-format.test
@@ -2,6 +2,6 @@
; 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
-; CHECK: {{.*}}: error: {{.*}}macho.dylib: Error when parsing file, unsupported file format
+; CHECK: error: {{.*}}macho.dylib' unsupported file format
; CHECK-NOT: error:
; CHECK-NOT: warning:
diff --git a/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -misspelled-tbd.test b/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -misspelled-tbd.test
index 5096c62557db..0df8af46f8ae 100644
--- a/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -misspelled-tbd.test
+++ b/llvm/test/tools/llvm-tapi-
diff /tapi-
diff -misspelled-tbd.test
@@ -1,5 +1,3 @@
-; RUN: not llvm-tapi-
diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck %s -DMSG=%errc_ENOENT
+; RUN: not llvm-tapi-
diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck %s
-; CHECK: {{.*}}: error: {{.*}}v4.tbd: [[MSG]]
-; CHECK-NOT: error:
-; CHECK-NOT: warning:
+; CHECK: error: {{.*}}v4.tbd' {{[Nn]}}o such file or directory
diff --git a/llvm/tools/llvm-tapi-
diff /llvm-tapi-
diff .cpp b/llvm/tools/llvm-tapi-
diff /llvm-tapi-
diff .cpp
index 40f1eec162be..772f124c5a59 100644
--- a/llvm/tools/llvm-tapi-
diff /llvm-tapi-
diff .cpp
+++ b/llvm/tools/llvm-tapi-
diff /llvm-tapi-
diff .cpp
@@ -1,6 +1,4 @@
-//===-- llvm-tapi-
diff .cpp - tbd comparator command-line driver ---*-
-// C++
-//-*-===//
+//===-- 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.
@@ -31,16 +29,8 @@ 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));
-
-std::string ToolName;
} // anonymous namespace
-ExitOnError ExitOnErr;
-
-void setErrorBanner(ExitOnError &ExitOnErr, std::string InputFile) {
- ExitOnErr.setBanner(ToolName + ": error: " + InputFile + ": ");
-}
-
Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFileOrSTDIN(Filename);
@@ -52,35 +42,29 @@ Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
int main(int Argc, char **Argv) {
InitLLVM X(Argc, Argv);
cl::HideUnrelatedOptions(NMCat);
- cl::ParseCommandLineOptions(
- Argc, Argv,
- "This tool will compare two tbd files and return the "
- "
diff erences in those files.");
+ cl::ParseCommandLineOptions(Argc, Argv, "Text-based Stubs Comparison Tool");
if (InputFileNameLHS.empty() || InputFileNameRHS.empty()) {
cl::PrintHelpMessage();
return EXIT_FAILURE;
}
- ToolName = Argv[0];
-
- setErrorBanner(ExitOnErr, InputFileNameLHS);
+ 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,
- "Error when parsing file, unsupported file format"));
+ ExitOnErr(createStringError(std::errc::executable_format_error,
+ "unsupported file format"));
}
- setErrorBanner(ExitOnErr, InputFileNameRHS);
+ 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,
- "Error when parsing file, unsupported file format"));
+ ExitOnErr(createStringError(std::errc::executable_format_error,
+ "unsupported file format"));
}
raw_ostream &OS = outs();
More information about the llvm-commits
mailing list