[PATCH] D69418: [llvm-ar] Add output option for extract operation

Yi Kong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 24 17:34:08 PDT 2019


kongyi updated this revision to Diff 226364.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69418/new/

https://reviews.llvm.org/D69418

Files:
  llvm/test/tools/llvm-ar/extract.test
  llvm/tools/llvm-ar/llvm-ar.cpp


Index: llvm/tools/llvm-ar/llvm-ar.cpp
===================================================================
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -80,6 +80,7 @@
     =gnu                -   gnu
     =darwin             -   darwin
     =bsd                -   bsd
+  --output=<string>     - directory extract to
   --plugin=<string>     - ignored for compatibility
   -h --help             - display this help and exit
   --version             - print the version and exit
@@ -171,6 +172,7 @@
 }
 
 static Format FormatType = Default;
+static std::string outputPath;
 
 static std::string Options;
 
@@ -425,6 +427,8 @@
            "operations");
   if (OriginalDates && Operation != Extract)
     fail("the 'o' modifier is only applicable to the 'x' operation");
+  if (!outputPath.empty() && Operation != Extract)
+    fail("the 'output' option is only applicable to the 'x' operation");
   if (OnlyUpdate && Operation != ReplaceOrInsert)
     fail("the 'u' modifier is only applicable to the 'r' operation");
   if (AddLibrary && Operation != QuickAppend)
@@ -531,7 +535,10 @@
   sys::fs::perms Mode = ModeOrErr.get();
 
   int FD;
-  failIfError(sys::fs::openFileForWrite(sys::path::filename(Name), FD,
+  std::string outputFilePath = sys::path::filename(Name);
+  if (!outputPath.empty())
+    outputFilePath = outputPath + '/' + outputFilePath;
+  failIfError(sys::fs::openFileForWrite(outputFilePath, FD,
                                         sys::fs::CD_CreateAlways,
                                         sys::fs::OF_None, Mode),
               Name);
@@ -1130,6 +1137,8 @@
                          .Default(Unknown);
         if (FormatType == Unknown)
           fail(std::string("Invalid format ") + match);
+      } else if (MatchFlagWithArg("output")) {
+        outputPath = match;
       } else if (MatchFlagWithArg("plugin")) {
         // Ignored.
       } else {
Index: llvm/test/tools/llvm-ar/extract.test
===================================================================
--- llvm/test/tools/llvm-ar/extract.test
+++ llvm/test/tools/llvm-ar/extract.test
@@ -12,11 +12,11 @@
 RUN: llvm-ar rc %t/archive.a %t/a.txt %t/b.txt
 
 # Single member:
-RUN: cd %t/extracted && llvm-ar x %t/archive.a a.txt
+RUN: llvm-ar --output=%t/extracted x %t/archive.a a.txt
 RUN: diff %t/a.txt %t/extracted/a.txt 
 
 # All members:
 RUN: rm %t/extracted/a.txt
-RUN: cd %t/extracted && llvm-ar x %t/archive.a
+RUN: llvm-ar --output=%t/extracted x %t/archive.a
 RUN: diff %t/a.txt %t/extracted/a.txt 
 RUN: diff %t/b.txt %t/extracted/b.txt 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69418.226364.patch
Type: text/x-patch
Size: 2579 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191025/0c8a2f80/attachment.bin>


More information about the llvm-commits mailing list