llvm.org GIT mirror llvm / 913cfad
[llvm-ar] Resubmit recursive thin archive test with fix for full path names and better error messages git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351256 91177308-0d34-0410-b5e6-96231b3b80d8 Jordan Rupprecht 7 months ago
2 changed file(s) with 20 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
0 # Since llvm-ar cannot create thin archives that contain any thin archives,
1 # nested-thin-archive.a is a manually constructed thin archive that contains
2 # another (unflattened) thin archive.
3 # This test ensures that flat archives are recursively flattened.
4
5 RUN: rm -f %t.a
6 RUN: llvm-ar rcsT %t.a %S/Inputs/nested-thin-archive.a %S/Inputs/d.txt
7 RUN: llvm-ar t %t.a | FileCheck %s
8
9 CHECK: a.txt
10 CHECK-NEXT: b.txt
11 CHECK-NEXT: c.txt
12 CHECK-NEXT: d.txt
3232 #include "llvm/Support/StringSaver.h"
3333 #include "llvm/Support/TargetSelect.h"
3434 #include "llvm/Support/ToolOutputFile.h"
35 #include "llvm/Support/WithColor.h"
3536 #include "llvm/Support/raw_ostream.h"
3637 #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
3738 #include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
114115
115116 // Show the error message and exit.
116117 LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
117 errs() << ToolName << ": " << Error << ".\n";
118 WithColor::error(errs(), ToolName) << Error << ".\n";
118119 printHelpMessage();
119120 exit(1);
120121 }
220221
221222 static object::Archive &readLibrary(const Twine &Library) {
222223 auto BufOrErr = MemoryBuffer::getFile(Library, -1, false);
223 failIfError(BufOrErr.getError(), "Could not open library");
224 failIfError(BufOrErr.getError(), "Could not open library " + Library);
224225 ArchiveBuffers.push_back(std::move(*BufOrErr));
225226 auto LibOrErr =
226227 object::Archive::create(ArchiveBuffers.back()->getMemBufferRef());
531532 if (Members.empty())
532533 return;
533534 for (StringRef Name : Members)
534 errs() << Name << " was not found\n";
535 WithColor::error(errs(), ToolName) << "'" << Name << "' was not found\n";
535536 exit(1);
536537 }
537538
545546 failIfError(NMOrErr.takeError());
546547 if (FlattenArchive &&
547548 identify_magic(NMOrErr->Buf->getBuffer()) == file_magic::archive) {
548 Expected<StringRef> FileNameOrErr = M.getName();
549 Expected<std::string> FileNameOrErr = M.getFullName();
549550 failIfError(FileNameOrErr.takeError());
550551 object::Archive &Lib = readLibrary(*FileNameOrErr);
551552 // When creating thin archives, only flatten if the member is also thin.
852853 } else {
853854 if (!Create) {
854855 // Produce a warning if we should and we're creating the archive
855 errs() << ToolName << ": creating " << ArchiveName << "\n";
856 WithColor::warning(errs(), ToolName)
857 << "creating " << ArchiveName << "\n";
856858 }
857859 }
858860