diff options
| author | Martin Storsjo <martin@martin.st> | 2017-11-03 20:09:10 +0000 | 
|---|---|---|
| committer | Martin Storsjo <martin@martin.st> | 2017-11-03 20:09:10 +0000 | 
| commit | 1a9593b251cfb9afce0edf5fd72ddb692bb7c938 (patch) | |
| tree | 871de7b50f0a2319ce82e6c637c6fd593a649f33 /llvm/tools/llvm-ar/llvm-ar.cpp | |
| parent | 639ea374d672119f5d86d3b5b3badfadd530de87 (diff) | |
| download | bcm5719-llvm-1a9593b251cfb9afce0edf5fd72ddb692bb7c938.tar.gz bcm5719-llvm-1a9593b251cfb9afce0edf5fd72ddb692bb7c938.zip | |
[llvm-ar] Support an options string that start with a dash
Some projects call $AR like "$AR -crs output input1 input2".
Differential Revision: https://reviews.llvm.org/D39538
llvm-svn: 317358
Diffstat (limited to 'llvm/tools/llvm-ar/llvm-ar.cpp')
| -rw-r--r-- | llvm/tools/llvm-ar/llvm-ar.cpp | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 576265cfe59..8c19f6b6af8 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -127,6 +127,8 @@ static cl::extrahelp MoreHelp(    "  [v] - be verbose about actions taken\n"  ); +static const char OptionChars[] = "dmpqrtxabiosSTucv"; +  // This enumeration delineates the kinds of operations on an archive  // that are permitted.  enum ArchiveOperation { @@ -864,6 +866,24 @@ int main(int argc, char **argv) {        Stem.find("lib") != StringRef::npos)      return libDriverMain(makeArrayRef(argv, argc)); +  for (int i = 1; i < argc; i++) { +    // If an argument starts with a dash and only contains chars +    // that belong to the options chars set, remove the dash. +    // We can't handle it after the command line options parsing +    // is done, since it will error out on an unrecognized string +    // starting with a dash. +    // Make sure this doesn't match the actual llvm-ar specific options +    // that start with a dash. +    StringRef S = argv[i]; +    if (S.startswith("-") && +        S.find_first_not_of(OptionChars, 1) == StringRef::npos) { +      argv[i]++; +      break; +    } +    if (S == "--") +      break; +  } +    // Have the command line options parsed and handle things    // like --help and --version.    cl::ParseCommandLineOptions(argc, argv, | 

