MRI scripts: Add addlib support.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-10-21 23:18:51 +00:00
parent 3c47b5cf7a
commit f6b403a753
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,17 @@
; RUN: echo create %t.a > %t.mri
; RUN: echo addlib %p/Inputs/GNU.a >> %t.mri
; RUN: echo addlib %p/Inputs/archive-test.a-gnu-minimal >> %t.mri
; RUN: echo save >> %t.mri
; RUN: echo end >> %t.mri
; RUN: llvm-ar -M < %t.mri
; RUN: llvm-ar t %t.a | FileCheck %s
; CHECK: evenlen
; CHECK-NEXT: oddlen
; CHECK-NEXT: very_long_bytecode_file_name.bc
; CHECK-NEXT: IsNAN.o
; CHECK-NEXT: test
; line_iterator is incompatible to CRLF.
; REQUIRES: shell

View File

@ -947,19 +947,22 @@ static int performOperation(ArchiveOperation Operation,
}
static void runMRIScript() {
enum class MRICommand { AddMod, Create, Save, End, Invalid };
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<NewArchiveIterator> NewMembers;
std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
std::vector<std::unique_ptr<object::Archive>> Archives;
for (line_iterator I(Ref, /*SkipBlanks*/ true, ';'), E; I != E; ++I) {
StringRef Line = *I;
StringRef CommandStr, Rest;
std::tie(CommandStr, Rest) = Line.split(' ');
auto Command = StringSwitch<MRICommand>(CommandStr.lower())
.Case("addlib", MRICommand::AddLib)
.Case("addmod", MRICommand::AddMod)
.Case("create", MRICommand::Create)
.Case("save", MRICommand::Save)
@ -967,6 +970,22 @@ static void runMRIScript() {
.Default(MRICommand::Invalid);
switch (Command) {
case MRICommand::AddLib: {
auto BufOrErr = MemoryBuffer::getFile(Rest, -1, false);
failIfError(BufOrErr.getError(), "Could not open library");
ArchiveBuffers.push_back(std::move(*BufOrErr));
auto LibOrErr =
object::Archive::create(ArchiveBuffers.back()->getMemBufferRef());
failIfError(LibOrErr.getError(), "Could not parse library");
Archives.push_back(std::move(*LibOrErr));
object::Archive &Lib = *Archives.back();
for (auto &Member : Lib.children()) {
ErrorOr<StringRef> NameOrErr = Member.getName();
failIfError(NameOrErr.getError());
addMember(NewMembers, Member, *NameOrErr);
}
break;
}
case MRICommand::AddMod:
addMember(NewMembers, Rest, sys::path::filename(Rest));
break;