Skip to content

Commit 7e0323e

Browse files
committed
[llvm-ranlib] Change -v (alias for --version) to -V
-V prints the version information in both BSD and GNU ar/ranlib. -v enables verbose output in BSD ranlib and GNU ar but is another alias for --version in GNU ranlib. The GNU ranlib behavior is inconsistent: `ranlib -v` is different from `ar -sv`. But it's not a major concern in practice: * Users typically use ranlib solely for creating archive symbol tables, and they don't need verbose output. * Verbose output in ranlib seems a no-op. * GNU ar creates an archive symbol table by default. Many ranlib uses have been eliminated. * Modern linkers like lld/ELF (since version 14) and lld don't rely on archive symbol tables anymore. https://reviews.llvm.org/D71554 introduced -v. This patch removes it so that `llvm-ranlib -v` and `llvm-ranlib -version` lead to errors (GNU ranlib rejects `-version` as well). -V is added as an alias for --version. Close llvm#87654 Pull Request: llvm#87661
1 parent be8fd86 commit 7e0323e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

llvm/test/tools/llvm-ranlib/help-message.test

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
# RUN: llvm-ranlib -help | FileCheck %s --check-prefix=HELP
66
# RUN: llvm-ranlib --help | FileCheck %s --check-prefix=HELP
77
# RUN: llvm-ranlib --version | FileCheck %s --check-prefix=VERSION
8-
# RUN: llvm-ranlib -version | FileCheck %s --check-prefix=VERSION
9-
# RUN: llvm-ranlib -v | FileCheck %s --check-prefix=VERSION
8+
# RUN: llvm-ranlib -V | FileCheck %s --check-prefix=VERSION
109

1110
## Also check combined options (first -h/-v flag wins)
1211
# RUN: llvm-ranlib -Dh | FileCheck %s --check-prefix=HELP
13-
# RUN: llvm-ranlib -Dvh | FileCheck %s --check-prefix=VERSION
14-
# RUN: llvm-ranlib -Dhv | FileCheck %s --check-prefix=HELP
12+
# RUN: llvm-ranlib -DVh | FileCheck %s --check-prefix=VERSION
13+
# RUN: llvm-ranlib -DhV | FileCheck %s --check-prefix=HELP
1514

1615
# HELP: USAGE: llvm-ranlib
1716
# VERSION: version
17+
18+
## -v enables verbose output in BSD ranlib and GNU ar but is another alias
19+
## for --version in GNU ranlib. Reject -v.
20+
# RUN: not llvm-ranlib -v 2>&1 | FileCheck %s --check-prefix=ERR1
21+
# RUN: not llvm-ranlib -version 2>&1 | FileCheck %s --check-prefix=ERR2
22+
# RUN: not llvm-ranlib -Dvh 2>&1 | FileCheck %s --check-prefix=ERR3
23+
24+
# ERR1: error: Invalid option: '-v'
25+
# ERR2: error: Invalid option: '-version'
26+
# ERR3: error: Invalid option: '-vh'

llvm/tools/llvm-ar/llvm-ar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void printRanLibHelp(StringRef ToolName) {
6565
<< "USAGE: " + ToolName + " archive...\n\n"
6666
<< "OPTIONS:\n"
6767
<< " -h --help - Display available options\n"
68-
<< " -v --version - Display the version of this program\n"
68+
<< " -V --version - Display the version of this program\n"
6969
<< " -D - Use zero for timestamps and uids/gids "
7070
"(default)\n"
7171
<< " -U - Use actual timestamps and uids/gids\n"
@@ -1439,7 +1439,7 @@ static int ranlib_main(int argc, char **argv) {
14391439
} else if (arg.front() == 'h') {
14401440
printHelpMessage();
14411441
return 0;
1442-
} else if (arg.front() == 'v') {
1442+
} else if (arg.front() == 'V') {
14431443
cl::PrintVersionMessage();
14441444
return 0;
14451445
} else if (arg.front() == 'X') {

0 commit comments

Comments
 (0)