[PATCH] D43986: Allow MRI scripts as file input on cmd line
Dmitry Mikulin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 16:44:25 PST 2018
dmikulin created this revision.
dmikulin added a reviewer: Bigcheese.
With -M option llvm-ar expects input from stdin. Change it to optionally take file name for an MRI script as input to -M.
https://reviews.llvm.org/D43986
Files:
llvm/test/Object/mri5.test
llvm/test/tools/llvm-ar/mri.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
@@ -193,16 +193,28 @@
Members.push_back(Arg);
}
-static void runMRIScript();
+static void runMRIScript(const MemoryBuffer &Ref);
// Parse the command line options as presented and return the operation
// specified. Process all modifiers and check to make sure that constraints on
// modifier/operation pairs have not been violated.
static ArchiveOperation parseCommandLine() {
if (MRI) {
- if (!RestOfArgs.empty())
- fail("Cannot mix -M and other options");
- runMRIScript();
+ std::string MRIScriptName;
+ if (!RestOfArgs.empty()) {
+ MRIScriptName = RestOfArgs[0];
+ RestOfArgs.erase(RestOfArgs.begin());
+
+ if (!RestOfArgs.empty())
+ fail("Cannot mix -M and other options");
+ }
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr = MRIScriptName.empty() ?
+ MemoryBuffer::getSTDIN() : MemoryBuffer::getFile(MRIScriptName);
+
+ if (!MemBufOrErr)
+ fail("Cannot read MRI script '" + MRIScriptName + "'");
+ runMRIScript(*MemBufOrErr.get());
}
getOptions();
@@ -757,12 +769,9 @@
return 0;
}
-static void runMRIScript() {
+static void runMRIScript(const MemoryBuffer &Ref) {
enum class MRICommand { AddLib, AddMod, Create, Save, End, Invalid };
- ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getSTDIN();
- failIfError(Buf.getError());
- const MemoryBuffer &Ref = *Buf.get();
bool Saved = false;
std::vector<NewArchiveMember> NewMembers;
std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
Index: llvm/test/tools/llvm-ar/mri.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ar/mri.test
@@ -0,0 +1,16 @@
+RUN: yaml2obj %S/Inputs/elf.yaml -o %t.o
+RUN: rm -f %t.ar
+
+RUN: echo "create %t.ar" > %t.mri
+RUN: echo "addmod %t.o" >> %t.mri
+RUN: echo "save" >> %t.mri
+RUN: echo "end" >> %t.mri
+
+RUN: llvm-ar -M < %t.mri
+RUN: llvm-ar tv %t.ar | FileCheck %s
+
+RUN: rm -f %t.ar
+RUN: llvm-ar -M %t.mri
+RUN: llvm-ar tv %t.ar | FileCheck %s
+
+CHECK: mri.test{{.*}}.o
Index: llvm/test/Object/mri5.test
===================================================================
--- llvm/test/Object/mri5.test
+++ llvm/test/Object/mri5.test
@@ -1,2 +1,4 @@
-; RUN: not llvm-ar -M t < %s 2>&1 | FileCheck %s
+; RUN: not llvm-ar -M t x 2>&1 | FileCheck %s
+; RUN: not llvm-ar -M t < %s 2>&1 | FileCheck %s --check-prefix CHECK-FILE
; CHECK: Cannot mix -M and other options.
+; CHECK-FILE: Cannot read MRI script 't'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43986.136622.patch
Type: text/x-patch
Size: 2675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/e9f52231/attachment.bin>
More information about the llvm-commits
mailing list