[llvm] 0c8c050 - [llvm-ar] Modify usage printouts to use the correct toolname
Chris Jackson via llvm-commits
llvm-commits at lists.llvm.org
Tue May 3 09:45:31 PDT 2022
Author: Chris Jackson
Date: 2022-05-03T17:45:11+01:00
New Revision: 0c8c05064d57fe3bbbb1edd4c6e67f909c720578
URL: https://github.com/llvm/llvm-project/commit/0c8c05064d57fe3bbbb1edd4c6e67f909c720578
DIFF: https://github.com/llvm/llvm-project/commit/0c8c05064d57fe3bbbb1edd4c6e67f909c720578.diff
LOG: [llvm-ar] Modify usage printouts to use the correct toolname
Modify llvm-ar and llvm-ranlib to use the actual name of the executable
when printing the usage text via the '--help' flag.
Reviewers: Maskray, jhenderson, gbreynoo
Differential Revision: https://reviews.llvm.org/D124445
Added:
Modified:
llvm/test/tools/llvm-ar/tool-name.test
llvm/test/tools/llvm-ranlib/tool-name.test
llvm/tools/llvm-ar/llvm-ar.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-ar/tool-name.test b/llvm/test/tools/llvm-ar/tool-name.test
index cb656d3b47fef..f91ef716d5c3a 100644
--- a/llvm/test/tools/llvm-ar/tool-name.test
+++ b/llvm/test/tools/llvm-ar/tool-name.test
@@ -7,9 +7,14 @@
# RUN: ln -s llvm-ar %t/ar.exe
# RUN: ln -s llvm-ar %t/arm-pokymllib32-linux-gnueabi-llvm-ar-9
-# RUN: llvm-ar h | FileCheck %s
-# RUN: %t/llvm-ar-9 h | FileCheck %s
-# RUN: %t/ar.exe h | FileCheck %s
-# RUN: %t/arm-pokymllib32-linux-gnueabi-llvm-ar-9 h | FileCheck %s
+# RUN: llvm-ar h | FileCheck %s --check-prefix=DEFAULT
+# RUN: %t/llvm-ar-9 h | FileCheck %s --check-prefix=VERSION
+# RUN: %t/ar.exe h | FileCheck %s --check-prefix=SUFFIX
+## Ensure that the "lib" substring does not result in misidentification as the
+## llvm-lib tool.
+# RUN: %t/arm-pokymllib32-linux-gnueabi-llvm-ar-9 h | FileCheck %s --check-prefix=ARM
-# CHECK: USAGE: llvm-ar
+# DEFAULT: USAGE: llvm-ar{{ }}
+# VERSION: USAGE: llvm-ar-9{{ }}
+# SUFFIX: USAGE: ar{{ }}
+# ARM: USAGE: arm-pokymllib32-linux-gnueabi-llvm-ar-9{{ }}
diff --git a/llvm/test/tools/llvm-ranlib/tool-name.test b/llvm/test/tools/llvm-ranlib/tool-name.test
index bd2b496533153..d58783e4667b3 100644
--- a/llvm/test/tools/llvm-ranlib/tool-name.test
+++ b/llvm/test/tools/llvm-ranlib/tool-name.test
@@ -6,8 +6,10 @@
# RUN: ln -s llvm-ranlib %t/llvm-ranlib-9
# RUN: ln -s llvm-ranlib %t/ranlib.exe
-# RUN: llvm-ranlib -h | FileCheck %s
-# RUN: %t/llvm-ranlib-9 -h | FileCheck %s
-# RUN: %t/ranlib.exe -h | FileCheck %s
+# RUN: llvm-ranlib -h | FileCheck %s --check-prefix=DEFAULT
+# RUN: %t/llvm-ranlib-9 -h | FileCheck %s --check-prefix=VERSION
+# RUN: %t/ranlib.exe -h | FileCheck %s --check-prefix=SUFFIX
-# CHECK: USAGE: llvm-ranlib
+# DEFAULT: USAGE: llvm-ranlib{{ }}
+# VERSION: USAGE: llvm-ranlib-9{{ }}
+# SUFFIX: USAGE: ranlib{{ }}
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 2b0288321834d..81ac003e73141 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -62,25 +62,21 @@ static StringRef ToolName;
// The basename of this program.
static StringRef Stem;
-const char RanlibHelp[] = R"(OVERVIEW: LLVM Ranlib (llvm-ranlib)
-
- This program generates an index to speed access to archives
-
-USAGE: llvm-ranlib <archive-file>
-
-OPTIONS:
- -h --help - Display available options
- -v --version - Display the version of this program
- -D - Use zero for timestamps and uids/gids (default)
- -U - Use actual timestamps and uids/gids
-)";
-
-const char ArHelp[] = R"(OVERVIEW: LLVM Archiver
-
-USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [files]
- llvm-ar -M [<mri-script]
+static void printRanLibHelp(StringRef ToolName) {
+ outs() << "OVERVIEW: LLVM Ranlib\n\n"
+ << "This program generates an index to speed access to archives\n\n"
+ << "USAGE: " + ToolName + " <archive-file>\n\n"
+ << "OPTIONS:\n"
+ << " -h --help - Display available options\n"
+ << " -v --version - Display the version of this program\n"
+ << " -D - Use zero for timestamps and uids/gids "
+ "(default)\n"
+ << " -U - Use actual timestamps and uids/gids\n";
+}
-OPTIONS:
+static void printArHelp(StringRef ToolName) {
+ const char ArOptions[] =
+ R"(OPTIONS:
--format - archive format to create
=default - default
=gnu - gnu
@@ -127,11 +123,20 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
[V] - display the version and exit
)";
+ outs() << "OVERVIEW: LLVM Archiver\n\n"
+ << "USAGE: " + ToolName +
+ " [options] [-]<operation>[modifiers] [relpos] "
+ "[count] <archive> [files]\n"
+ << " " + ToolName + " -M [<mri-script]\n\n";
+
+ outs() << ArOptions;
+}
+
static void printHelpMessage() {
if (Stem.contains_insensitive("ranlib"))
- outs() << RanlibHelp;
+ printRanLibHelp(Stem);
else if (Stem.contains_insensitive("ar"))
- outs() << ArHelp;
+ printArHelp(Stem);
}
static unsigned MRILineNumber;
More information about the llvm-commits
mailing list