From f6b403a753f1c3f87edb8c6306aa959c7b5f0da3 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 21 Oct 2014 23:18:51 +0000 Subject: [PATCH] MRI scripts: Add addlib support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220346 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/mri-addlib.test | 17 +++++++++++++++++ tools/llvm-ar/llvm-ar.cpp | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/Object/mri-addlib.test diff --git a/test/Object/mri-addlib.test b/test/Object/mri-addlib.test new file mode 100644 index 00000000000..5af09e36907 --- /dev/null +++ b/test/Object/mri-addlib.test @@ -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 diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index aff8a04cce5..8411a1dad47 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -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> Buf = MemoryBuffer::getSTDIN(); failIfError(Buf.getError()); const MemoryBuffer &Ref = *Buf.get(); bool Saved = false; std::vector NewMembers; + std::vector> ArchiveBuffers; + std::vector> 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(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 NameOrErr = Member.getName(); + failIfError(NameOrErr.getError()); + addMember(NewMembers, Member, *NameOrErr); + } + break; + } case MRICommand::AddMod: addMember(NewMembers, Rest, sys::path::filename(Rest)); break;