diff options
author | Shoaib Meenai <smeenai@fb.com> | 2020-08-21 10:49:59 -0700 |
---|---|---|
committer | Shoaib Meenai <smeenai@fb.com> | 2020-08-24 13:48:23 -0700 |
commit | 68bae34c65b30ad3fe01555b4cf3020266cfec85 (patch) | |
tree | 5cb421e7d00a4ddb5ee8401370abc3baff242846 /llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp | |
parent | 47b0262d3f82a5574c7539afeb76cc1687417ca5 (diff) | |
download | llvm-68bae34c65b30ad3fe01555b4cf3020266cfec85.zip llvm-68bae34c65b30ad3fe01555b4cf3020266cfec85.tar.gz llvm-68bae34c65b30ad3fe01555b4cf3020266cfec85.tar.bz2 |
[llvm-libtool-darwin] Add support for -V option
The -V option in cctools' libtool prints out the version number and
performs any specified operation. Add this option to LLVM's version.
cctools is more forgiving of invalid command lines when -V is specified,
but I think it's better to give errors instead of silently producing no
output.
Unfortunately, when -V is present, options that would otherwise be
required aren't anymore, so we need to perform some manual argument
validation.
Reviewed By: alexshap
Differential Revision: https://reviews.llvm.org/D86359
Diffstat (limited to 'llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp')
-rw-r--r-- | llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp index e861b46..5a7608d 100644 --- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp +++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp @@ -32,7 +32,7 @@ typedef std::map<uint64_t, std::vector<NewArchiveMember>> cl::OptionCategory LibtoolCategory("llvm-libtool-darwin Options"); static cl::opt<std::string> OutputFile("o", cl::desc("Specify output filename"), - cl::value_desc("filename"), cl::Required, + cl::value_desc("filename"), cl::cat(LibtoolCategory)); static cl::list<std::string> InputFiles(cl::Positional, @@ -44,14 +44,14 @@ static cl::opt<std::string> ArchType( "arch_only", cl::desc("Specify architecture type for output library"), cl::value_desc("arch_type"), cl::ZeroOrMore, cl::cat(LibtoolCategory)); -enum class Operation { Static }; +enum class Operation { None, Static }; static cl::opt<Operation> LibraryOperation( cl::desc("Library Type: "), cl::values( clEnumValN(Operation::Static, "static", "Produce a statically linked library from the input files")), - cl::Required, cl::cat(LibtoolCategory)); + cl::init(Operation::None), cl::cat(LibtoolCategory)); static cl::opt<bool> DeterministicOption( "D", cl::desc("Use zero for timestamps and UIDs/GIDs (Default)"), @@ -81,6 +81,10 @@ static cl::list<std::string> LibrarySearchDirs( " libraries"), cl::ZeroOrMore, cl::Prefix, cl::cat(LibtoolCategory)); +static cl::opt<bool> + VersionOption("V", cl::desc("Print the version number and exit"), + cl::cat(LibtoolCategory)); + static const std::array<std::string, 3> StandardSearchDirs{ "/lib", "/usr/lib", @@ -444,6 +448,23 @@ static Expected<Config> parseCommandLine(int Argc, char **Argv) { Config C; cl::ParseCommandLineOptions(Argc, Argv, "llvm-libtool-darwin\n"); + if (LibraryOperation == Operation::None) { + if (!VersionOption) { + std::string Error; + raw_string_ostream Stream(Error); + LibraryOperation.error("must be specified", "", Stream); + return createStringError(std::errc::invalid_argument, Error.c_str()); + } + return C; + } + + if (OutputFile.empty()) { + std::string Error; + raw_string_ostream Stream(Error); + OutputFile.error("must be specified", "o", Stream); + return createStringError(std::errc::invalid_argument, Error.c_str()); + } + if (DeterministicOption && NonDeterministicOption) return createStringError(std::errc::invalid_argument, "cannot specify both -D and -U flags"); @@ -483,8 +504,13 @@ int main(int Argc, char **Argv) { return EXIT_FAILURE; } + if (VersionOption) + cl::PrintVersionMessage(); + Config C = *ConfigOrErr; switch (LibraryOperation) { + case Operation::None: + break; case Operation::Static: if (Error E = createStaticLibrary(C)) { WithColor::defaultErrorHandler(std::move(E)); |