[llvm] r351256 - [llvm-ar] Resubmit recursive thin archive test with fix for full path names and better error messages

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 15 13:52:32 PST 2019


Author: rupprecht
Date: Tue Jan 15 13:52:31 2019
New Revision: 351256

URL: http://llvm.org/viewvc/llvm-project?rev=351256&view=rev
Log:
[llvm-ar] Resubmit recursive thin archive test with fix for full path names and better error messages

Added:
    llvm/trunk/test/tools/llvm-ar/flatten-thin-archive-recursive.test
Modified:
    llvm/trunk/tools/llvm-ar/llvm-ar.cpp

Added: llvm/trunk/test/tools/llvm-ar/flatten-thin-archive-recursive.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ar/flatten-thin-archive-recursive.test?rev=351256&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ar/flatten-thin-archive-recursive.test (added)
+++ llvm/trunk/test/tools/llvm-ar/flatten-thin-archive-recursive.test Tue Jan 15 13:52:31 2019
@@ -0,0 +1,13 @@
+# Since llvm-ar cannot create thin archives that contain any thin archives,
+# nested-thin-archive.a is a manually constructed thin archive that contains
+# another (unflattened) thin archive.
+# This test ensures that flat archives are recursively flattened.
+
+RUN: rm -f %t.a
+RUN: llvm-ar rcsT %t.a %S/Inputs/nested-thin-archive.a %S/Inputs/d.txt
+RUN: llvm-ar t %t.a | FileCheck %s
+
+CHECK:      a.txt
+CHECK-NEXT: b.txt
+CHECK-NEXT: c.txt
+CHECK-NEXT: d.txt

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=351256&r1=351255&r2=351256&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Tue Jan 15 13:52:31 2019
@@ -33,6 +33,7 @@
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
 #include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
@@ -115,7 +116,7 @@ void printHelpMessage() {
 
 // Show the error message and exit.
 LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
-  errs() << ToolName << ": " << Error << ".\n";
+  WithColor::error(errs(), ToolName) << Error << ".\n";
   printHelpMessage();
   exit(1);
 }
@@ -221,7 +222,7 @@ std::vector<std::unique_ptr<object::Arch
 
 static object::Archive &readLibrary(const Twine &Library) {
   auto BufOrErr = MemoryBuffer::getFile(Library, -1, false);
-  failIfError(BufOrErr.getError(), "Could not open library");
+  failIfError(BufOrErr.getError(), "Could not open library " + Library);
   ArchiveBuffers.push_back(std::move(*BufOrErr));
   auto LibOrErr =
       object::Archive::create(ArchiveBuffers.back()->getMemBufferRef());
@@ -532,7 +533,7 @@ static void performReadOperation(Archive
   if (Members.empty())
     return;
   for (StringRef Name : Members)
-    errs() << Name << " was not found\n";
+    WithColor::error(errs(), ToolName) << "'" << Name << "' was not found\n";
   exit(1);
 }
 
@@ -546,7 +547,7 @@ static void addChildMember(std::vector<N
   failIfError(NMOrErr.takeError());
   if (FlattenArchive &&
       identify_magic(NMOrErr->Buf->getBuffer()) == file_magic::archive) {
-    Expected<StringRef> FileNameOrErr = M.getName();
+    Expected<std::string> FileNameOrErr = M.getFullName();
     failIfError(FileNameOrErr.takeError());
     object::Archive &Lib = readLibrary(*FileNameOrErr);
     // When creating thin archives, only flatten if the member is also thin.
@@ -853,7 +854,8 @@ static int performOperation(ArchiveOpera
   } else {
     if (!Create) {
       // Produce a warning if we should and we're creating the archive
-      errs() << ToolName << ": creating " << ArchiveName << "\n";
+      WithColor::warning(errs(), ToolName)
+          << "creating " << ArchiveName << "\n";
     }
   }
 




More information about the llvm-commits mailing list