[llvm] ca133cd - [llvm-objcopy] Update help messages

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 11:20:11 PDT 2020


Author: Alexander Shaposhnikov
Date: 2020-06-24T11:19:56-07:00
New Revision: ca133cdecfeacf9a36f7f4b547239ca8b799641c

URL: https://github.com/llvm/llvm-project/commit/ca133cdecfeacf9a36f7f4b547239ca8b799641c
DIFF: https://github.com/llvm/llvm-project/commit/ca133cdecfeacf9a36f7f4b547239ca8b799641c.diff

LOG: [llvm-objcopy] Update help messages

This diff updates the help messages for llvm-objcopy, llvm-strip and
llvm-install-name-tool.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81907

Added: 
    

Modified: 
    llvm/test/tools/llvm-objcopy/ELF/help-message.test
    llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test
    llvm/tools/llvm-objcopy/CopyConfig.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/ELF/help-message.test b/llvm/test/tools/llvm-objcopy/ELF/help-message.test
index 0a093fe45c83..e8996c59b480 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/help-message.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/help-message.test
@@ -1,23 +1,22 @@
-# RUN: llvm-objcopy -h | FileCheck --check-prefix=OBJCOPY-USAGE %s
-# RUN: llvm-objcopy --help | FileCheck --check-prefix=OBJCOPY-USAGE %s
-# RUN: not llvm-objcopy 2>&1 | FileCheck --check-prefix=OBJCOPY-USAGE %s
+# RUN: llvm-objcopy -h | FileCheck --check-prefix=OBJCOPY-USAGE %s --match-full-lines
+# RUN: llvm-objcopy --help | FileCheck --check-prefix=OBJCOPY-USAGE %s --match-full-lines
+# RUN: not llvm-objcopy 2>&1 | FileCheck --check-prefix=OBJCOPY-USAGE %s --match-full-lines
 # RUN: not llvm-objcopy -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
 # RUN: not llvm-objcopy --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
 # RUN: not llvm-objcopy --strip-debug 2>&1 | FileCheck %s --check-prefix=NO-INPUT-FILES
 
-# RUN: llvm-strip -h | FileCheck --check-prefix=STRIP-USAGE %s
-# RUN: llvm-strip --help | FileCheck --check-prefix=STRIP-USAGE %s
-# RUN: not llvm-strip 2>&1 | FileCheck --check-prefix=STRIP-USAGE %s
+# RUN: llvm-strip -h | FileCheck --check-prefix=STRIP-USAGE %s --match-full-lines
+# RUN: llvm-strip --help | FileCheck --check-prefix=STRIP-USAGE %s --match-full-lines
+# RUN: not llvm-strip 2>&1 | FileCheck --check-prefix=STRIP-USAGE %s --match-full-lines
 # RUN: not llvm-strip -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
 # RUN: not llvm-strip --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
 # RUN: not llvm-strip --strip-debug 2>&1 | FileCheck %s --check-prefix=NO-INPUT-FILES
 
+# OBJCOPY-USAGE:  USAGE: llvm-objcopy [options] input [output]
+# OBJCOPY-USAGE:  Pass @FILE as argument to read options from FILE.
 
-# OBJCOPY-USAGE:  USAGE: llvm-objcopy
-# OBJCOPY-USAGE:  @FILE
-
-# STRIP-USAGE:    USAGE: llvm-strip
-# STRIP-USAGE:    @FILE
+# STRIP-USAGE:    USAGE: llvm-strip [options] inputs...
+# STRIP-USAGE:    Pass @FILE as argument to read options from FILE.
 
 # UNKNOWN-ARG:    unknown argument '{{-+}}abcabc'
 # NO-INPUT-FILES: no input file specified

diff  --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test
index 43e5290c3793..69f27a35a223 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test
@@ -1,10 +1,10 @@
-# RUN: llvm-install-name-tool -h | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s
-# RUN: llvm-install-name-tool --help | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s
-# RUN: not llvm-install-name-tool 2>&1 | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s
+# RUN: llvm-install-name-tool -h | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s --match-full-lines
+# RUN: llvm-install-name-tool --help | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s --match-full-lines
+# RUN: not llvm-install-name-tool 2>&1 | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s --match-full-lines
 # RUN: not llvm-install-name-tool -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
 # RUN: not llvm-install-name-tool --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
 
-# INSTALL-NAME-TOOL-USAGE: USAGE: llvm-install-name-tool
-# INSTALL-NAME-TOOL-USAGE: @FILE
+# INSTALL-NAME-TOOL-USAGE: USAGE: llvm-install-name-tool [options] input
+# INSTALL-NAME-TOOL-USAGE: Pass @FILE as argument to read options from FILE.
 
 # UNKNOWN-ARG: unknown argument '{{-+}}abcabc'

diff  --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index 93fa3d764adb..749df08a2d8b 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -393,9 +393,30 @@ template <class T> static ErrorOr<T> getAsInteger(StringRef Val) {
   return Result;
 }
 
+namespace {
+
+enum class ToolType { Objcopy, Strip, InstallNameTool };
+
+} // anonymous namespace
+
 static void printHelp(const opt::OptTable &OptTable, raw_ostream &OS,
-                      StringRef ToolName) {
-  OptTable.PrintHelp(OS, (ToolName + " input [output]").str().c_str(),
+                      ToolType Tool) {
+  StringRef HelpText, ToolName;
+  switch (Tool) {
+  case ToolType::Objcopy:
+    ToolName = "llvm-objcopy";
+    HelpText = " [options] input [output]";
+    break;
+  case ToolType::Strip:
+    ToolName = "llvm-strip";
+    HelpText = " [options] inputs...";
+    break;
+  case ToolType::InstallNameTool:
+    ToolName = "llvm-install-name-tool";
+    HelpText = " [options] input";
+    break;
+  }
+  OptTable.PrintHelp(OS, (ToolName + HelpText).str().c_str(),
                      (ToolName + " tool").str().c_str());
   // TODO: Replace this with libOption call once it adds extrahelp support.
   // The CommandLine library has a cl::extrahelp class to support this,
@@ -416,12 +437,12 @@ parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
       T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
 
   if (InputArgs.size() == 0) {
-    printHelp(T, errs(), "llvm-objcopy");
+    printHelp(T, errs(), ToolType::Objcopy);
     exit(1);
   }
 
   if (InputArgs.hasArg(OBJCOPY_help)) {
-    printHelp(T, outs(), "llvm-objcopy");
+    printHelp(T, outs(), ToolType::Objcopy);
     exit(0);
   }
 
@@ -807,12 +828,12 @@ parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr) {
       T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
 
   if (InputArgs.size() == 0) {
-    printHelp(T, errs(), "llvm-install-name-tool");
+    printHelp(T, errs(), ToolType::InstallNameTool);
     exit(1);
   }
 
   if (InputArgs.hasArg(INSTALL_NAME_TOOL_help)) {
-    printHelp(T, outs(), "llvm-install-name-tool");
+    printHelp(T, outs(), ToolType::InstallNameTool);
     exit(0);
   }
 
@@ -870,12 +891,12 @@ parseStripOptions(ArrayRef<const char *> ArgsArr,
       T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
 
   if (InputArgs.size() == 0) {
-    printHelp(T, errs(), "llvm-strip");
+    printHelp(T, errs(), ToolType::Strip);
     exit(1);
   }
 
   if (InputArgs.hasArg(STRIP_help)) {
-    printHelp(T, outs(), "llvm-strip");
+    printHelp(T, outs(), ToolType::Strip);
     exit(0);
   }
 


        


More information about the llvm-commits mailing list