diff options
author | Fangrui Song <i@maskray.me> | 2022-01-12 11:33:23 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-01-12 11:33:23 -0800 |
commit | 24e7371fef0d38bb7eeeb6863356d9b39430494e (patch) | |
tree | 65a89681e183ea9b9adcd1346f595e141a19e0b8 | |
parent | f8476fd47b539a14d6a8994e7a5e6401f9ed2a98 (diff) |
[llvm-ar] Enforce one-dash form for long options
binutils ar does not support one-dash long options (they conflict with
operation code and modifier flags).
```
% ar -help
ar: invalid option -- 'e'
...
% ar -version
ar: invalid option -- 'e'
...
% ar x --plugin=xx x.a # ok
% ar x -plugin=xx x.a
ar: two different operation options specified
% ar -plugin=/usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so x x.a
ar: x: No such file or directory
```
Drop one-dash long options to simplify code and match the usual practice for
command line utilities.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D116977
-rw-r--r-- | llvm/test/Object/archive-format.test | 3 | ||||
-rw-r--r-- | llvm/test/tools/llvm-ar/plugin.test | 9 | ||||
-rw-r--r-- | llvm/test/tools/llvm-ar/response.test | 2 | ||||
-rw-r--r-- | llvm/test/tools/llvm-ar/version.test | 5 | ||||
-rw-r--r-- | llvm/tools/llvm-ar/llvm-ar.cpp | 6 |
5 files changed, 19 insertions, 6 deletions
diff --git a/llvm/test/Object/archive-format.test b/llvm/test/Object/archive-format.test index fd9f0ae967bd..f24b5ad57667 100644 --- a/llvm/test/Object/archive-format.test +++ b/llvm/test/Object/archive-format.test @@ -89,3 +89,6 @@ RUN: cat -v %t/foo.a | FileCheck -strict-whitespace --check-prefix=SOLARIS %s SOLARIS: !<arch> SOLARIS-NEXT: / 0 0 0 0 8 ` SOLARIS-NEXT: ^@^@^@^@^@^@^@^@foo.o/ + +RUN: not llvm-ar -format=gnu rc %t.a 0123456789abcde 2>&1 | FileCheck --check-prefix=ONE-DASH %s +ONE-DASH: error: unknown option f diff --git a/llvm/test/tools/llvm-ar/plugin.test b/llvm/test/tools/llvm-ar/plugin.test new file mode 100644 index 000000000000..0dda3d98dde2 --- /dev/null +++ b/llvm/test/tools/llvm-ar/plugin.test @@ -0,0 +1,9 @@ +## Test that --plugin is ignored. + +# RUN: rm -f %t.a +# RUN: touch %t.txt +# RUN: llvm-ar rc %t.a %t.txt +# RUN: llvm-ar --plugin ignore t %t.a | FileCheck %s +# RUN: llvm-ar t --plugin=ignore %t.a | FileCheck %s + +# CHECK: {{.*}}.txt diff --git a/llvm/test/tools/llvm-ar/response.test b/llvm/test/tools/llvm-ar/response.test index 4e798c220103..02d9e8eec092 100644 --- a/llvm/test/tools/llvm-ar/response.test +++ b/llvm/test/tools/llvm-ar/response.test @@ -36,6 +36,6 @@ # RUN: FileCheck -DMSG=%errc_ENOENT %s --check-prefix=WIN # WIN: error: blah\foo: [[MSG]] -# RUN: not llvm-ar -rsp-quoting posix @%t-rsp.txt 2>&1 | \ +# RUN: not llvm-ar --rsp-quoting posix @%t-rsp.txt 2>&1 | \ # RUN: FileCheck -DMSG=%errc_ENOENT %s --check-prefix=POSIX # POSIX: error: blahfoo: [[MSG]] diff --git a/llvm/test/tools/llvm-ar/version.test b/llvm/test/tools/llvm-ar/version.test index 555e5fdf3244..0220f2cfe559 100644 --- a/llvm/test/tools/llvm-ar/version.test +++ b/llvm/test/tools/llvm-ar/version.test @@ -5,7 +5,10 @@ RUN: llvm-ar V | FileCheck %s RUN: llvm-ar xV | FileCheck %s RUN: llvm-ar -V | FileCheck %s RUN: llvm-ar -xV | FileCheck %s -RUN: llvm-ar -version | FileCheck %s RUN: llvm-ar --version | FileCheck %s CHECK: version + +RUN: not llvm-ar -version 2>&1 | FileCheck %s --check-prefix=ONE-DASH + +ONE-DASH: error: unknown option e diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 175ec8d022c2..674f57812df4 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -1111,11 +1111,11 @@ static void runMRIScript() { } static bool handleGenericOption(StringRef arg) { - if (arg == "-help" || arg == "--help" || arg == "-h") { + if (arg == "--help" || arg == "-h") { printHelpMessage(); return true; } - if (arg == "-version" || arg == "--version") { + if (arg == "--version") { cl::PrintVersionMessage(); return true; } @@ -1129,8 +1129,6 @@ static const char *matchFlagWithArg(StringRef Expected, if (Arg.startswith("--")) Arg = Arg.substr(2); - else if (Arg.startswith("-")) - Arg = Arg.substr(1); size_t len = Expected.size(); if (Arg == Expected) { |