[llvm-objcopy/llvm-strip]: handle --version
authorJordan Rupprecht <rupprecht@google.com>
Fri, 21 Sep 2018 00:47:31 +0000 (00:47 +0000)
committerJordan Rupprecht <rupprecht@google.com>
Fri, 21 Sep 2018 00:47:31 +0000 (00:47 +0000)
Summary:
Implement --version for objcopy and strip.

I think there are LLVM utilities that automatically handle this, but that doesn't seem to work with custom parsing since this binary handles both objcopy and strip, so it uses custom parsing.

This fixes PR38298

Reviewers: jhenderson, alexshap, jakehehrlich

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D52328

llvm-svn: 342702

llvm/test/tools/llvm-objcopy/objcopy-version.test [new file with mode: 0644]
llvm/test/tools/llvm-objcopy/strip-version.test [new file with mode: 0644]
llvm/tools/llvm-objcopy/ObjcopyOpts.td
llvm/tools/llvm-objcopy/StripOpts.td
llvm/tools/llvm-objcopy/llvm-objcopy.cpp

diff --git a/llvm/test/tools/llvm-objcopy/objcopy-version.test b/llvm/test/tools/llvm-objcopy/objcopy-version.test
new file mode 100644 (file)
index 0000000..3b5cd59
--- /dev/null
@@ -0,0 +1,4 @@
+# RUN: llvm-objcopy -version | FileCheck %s
+# RUN: llvm-objcopy --version | FileCheck %s
+
+# CHECK: {{ version }}
diff --git a/llvm/test/tools/llvm-objcopy/strip-version.test b/llvm/test/tools/llvm-objcopy/strip-version.test
new file mode 100644 (file)
index 0000000..bd91dd3
--- /dev/null
@@ -0,0 +1,4 @@
+# RUN: llvm-strip -version | FileCheck %s
+# RUN: llvm-strip --version | FileCheck %s
+
+# CHECK: {{ version }}
index 9d77145..469f76d 100644 (file)
@@ -107,6 +107,9 @@ defm keep_global_symbols
          "with '#'. Leading and trailing whitespace is stripped from each "
          "line. May be repeated to read symbols from many files.">;
 
+def version : Flag<[ "-", "--" ], "version">,
+              HelpText<"Print the version and exit.">;
+
 defm weaken_symbol : Eq<"weaken-symbol">,
                        MetaVarName<"symbol">,
                        HelpText<"Mark <symbol> as weak">;
index 5abc23f..821dfa3 100644 (file)
@@ -47,6 +47,10 @@ def K : JoinedOrSeparate<["-"], "K">,
 
 def discard_all : Flag<["-", "--"], "discard-all">,
                   HelpText<"Remove all local symbols except file and section symbols">;
+
+def version : Flag<[ "-", "--" ], "version">,
+              HelpText<"Print the version and exit.">;
+
 def x : Flag<["-"], "x">,
         Alias<discard_all>;
 
index 36ed77a..ce2a1f1 100644 (file)
@@ -892,6 +892,11 @@ static DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
     exit(0);
   }
 
+  if (InputArgs.hasArg(OBJCOPY_version)) {
+    cl::PrintVersionMessage();
+    exit(0);
+  }
+
   SmallVector<const char *, 2> Positional;
 
   for (auto Arg : InputArgs.filtered(OBJCOPY_UNKNOWN))
@@ -1019,6 +1024,11 @@ static DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr) {
     exit(0);
   }
 
+  if (InputArgs.hasArg(STRIP_version)) {
+    cl::PrintVersionMessage();
+    exit(0);
+  }
+
   SmallVector<const char *, 2> Positional;
   for (auto Arg : InputArgs.filtered(STRIP_UNKNOWN))
     error("unknown argument '" + Arg->getAsString(InputArgs) + "'");