diff options
author | Sameer Arora <sameerarora101@fb.com> | 2020-07-20 14:27:48 -0700 |
---|---|---|
committer | Sameer Arora <sameerarora101@fb.com> | 2020-08-07 14:29:24 -0700 |
commit | d9a9192984fafb6a81616aafcdcf388fba7b8e14 (patch) | |
tree | 609fb07604a3a85d25e22fd2a6e785859f879496 /llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp | |
parent | 38b419eb9330c1f1bcec31764f57e932c07fb42c (diff) | |
download | llvm-d9a9192984fafb6a81616aafcdcf388fba7b8e14.zip llvm-d9a9192984fafb6a81616aafcdcf388fba7b8e14.tar.gz llvm-d9a9192984fafb6a81616aafcdcf388fba7b8e14.tar.bz2 |
[llvm-libtool-darwin] Add support for -filelist option
Add support for `-filelist` option for llvm-libtool-darwin. `-filelist`
option allows for passing in a file containing a list of filenames.
Reviewed by jhenderson, smeenai
Differential Revision: https://reviews.llvm.org/D84206
Diffstat (limited to 'llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp')
-rw-r--r-- | llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp index bd1d9ac..d5eccaf 100644 --- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp +++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp @@ -16,6 +16,7 @@ #include "llvm/Object/ObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/LineIterator.h" #include "llvm/Support/WithColor.h" using namespace llvm; @@ -29,7 +30,7 @@ static cl::opt<std::string> OutputFile("o", cl::desc("Specify output filename"), static cl::list<std::string> InputFiles(cl::Positional, cl::desc("<input files>"), - cl::OneOrMore, + cl::ZeroOrMore, cl::cat(LibtoolCategory)); enum class Operation { Static }; @@ -41,6 +42,44 @@ static cl::opt<Operation> LibraryOperation( "Produce a statically linked library from the input files")), cl::Required, cl::cat(LibtoolCategory)); +static cl::opt<std::string> + FileList("filelist", + cl::desc("Pass in file containing a list of filenames"), + cl::value_desc("listfile[,dirname]"), cl::cat(LibtoolCategory)); + +static Error processFileList() { + StringRef FileName, DirName; + std::tie(FileName, DirName) = StringRef(FileList).rsplit(","); + + ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = + MemoryBuffer::getFileOrSTDIN(FileName, /*FileSize=*/-1, + /*RequiresNullTerminator=*/false); + if (std::error_code EC = FileOrErr.getError()) + return createFileError(FileName, errorCodeToError(EC)); + const MemoryBuffer &Ref = *FileOrErr.get(); + + line_iterator I(Ref, /*SkipBlanks=*/false); + if (I.is_at_eof()) + return createStringError(std::errc::invalid_argument, + "file list file: '%s' is empty", + FileName.str().c_str()); + for (; !I.is_at_eof(); ++I) { + StringRef Line = *I; + if (Line.empty()) + return createStringError(std::errc::invalid_argument, + "file list file: '%s': filename cannot be empty", + FileName.str().c_str()); + + SmallString<128> Path; + if (!DirName.empty()) + sys::path::append(Path, DirName, Line); + else + sys::path::append(Path, Line); + InputFiles.push_back(static_cast<std::string>(Path)); + } + return Error::success(); +} + static Error verifyMachOObject(const NewArchiveMember &Member) { auto MBRef = Member.Buf->getMemBufferRef(); Expected<std::unique_ptr<object::ObjectFile>> ObjOrErr = @@ -135,12 +174,25 @@ int main(int Argc, char **Argv) { InitLLVM X(Argc, Argv); cl::HideUnrelatedOptions({&LibtoolCategory, &ColorCategory}); cl::ParseCommandLineOptions(Argc, Argv, "llvm-libtool-darwin\n"); + if (!FileList.empty()) { + if (Error E = processFileList()) { + WithColor::defaultErrorHandler(std::move(E)); + return EXIT_FAILURE; + } + } + + if (InputFiles.empty()) { + Error E = createStringError(std::errc::invalid_argument, + "no input files specified"); + WithColor::defaultErrorHandler(std::move(E)); + return EXIT_FAILURE; + } switch (LibraryOperation) { case Operation::Static: if (Error E = createStaticLibrary()) { WithColor::defaultErrorHandler(std::move(E)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; } |