[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:22:38 PDT 2019
kongyi created this revision.
kongyi added reviewers: rupprecht, MaskRay, gbreynoo.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Both GNU ar or llvm-ar currently only supports extracting to the current working
directory. This creates a lot of complication when using it as part of build
process with both the llvm-ar tool path and the output file path are relative.
This change introduces `--output` option for extract operation, to coincide with
most other llvm-binutils tools.
Repository:
rL LLVM
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,8 @@
sys::fs::perms Mode = ModeOrErr.get();
int FD;
- failIfError(sys::fs::openFileForWrite(sys::path::filename(Name), FD,
+ const std::string outputFilePath = outputPath + '/' + Name.str();
+ failIfError(sys::fs::openFileForWrite(outputFilePath, FD,
sys::fs::CD_CreateAlways,
sys::fs::OF_None, Mode),
Name);
@@ -1130,6 +1135,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.226362.patch
Type: text/x-patch
Size: 2503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191025/8a604ceb/attachment.bin>
More information about the llvm-commits
mailing list