Skip to content

Commit

Permalink
[llvm-ar] Enforce one-dash form for long options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay committed Jan 12, 2022
1 parent f8476fd commit 24e7371
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions llvm/test/Object/archive-format.test
Expand Up @@ -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
9 changes: 9 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ar/response.test
Expand Up @@ -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]]
5 changes: 4 additions & 1 deletion llvm/test/tools/llvm-ar/version.test
Expand Up @@ -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
6 changes: 2 additions & 4 deletions llvm/tools/llvm-ar/llvm-ar.cpp
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 24e7371

Please sign in to comment.