From: Owen Reynolds Date: Thu, 6 Jun 2019 13:19:50 +0000 (+0000) Subject: [llvm-ar] Create thin archives with MRI scripts X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f8b01c36fb3ce2b8c2e67facc40c80a2513ecd4;p=llvm [llvm-ar] Create thin archives with MRI scripts This patch implements the "CREATE_THIN" MRI script command, allowing thin archives to be created via MRI scripts. Differential Revision: https://reviews.llvm.org/D62919 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362704 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/llvm-ar/mri-thin-archive.test b/test/tools/llvm-ar/mri-thin-archive.test new file mode 100644 index 00000000000..e759a9a25f2 --- /dev/null +++ b/test/tools/llvm-ar/mri-thin-archive.test @@ -0,0 +1,23 @@ +RUN: rm -rf %t && mkdir -p %t/addlib/ + +RUN: yaml2obj %S/Inputs/elf.yaml -o %t/elf.o +RUN: cp %t/elf.o %t/addlib/elf.o +RUN: cp %t/elf.o %t/delete.o + +RUN: cd %t && llvm-ar rTc addlib/addlib.ar addlib/elf.o + +RUN: echo "createthin %t/archive.ar" > %t/mri.script +RUN: echo "addmod elf.o" >> %t/mri.script +RUN: echo "addlib addlib/addlib.ar" >> %t/mri.script +RUN: echo "addmod delete.o" >> %t/mri.script +RUN: echo "delete delete.o" >> %t/mri.script +RUN: echo "save" >> %t/mri.script +RUN: echo "end" >> %t/mri.script + +RUN: cd %t && llvm-ar -M < mri.script +RUN: FileCheck -input-file=%t/archive.ar %s + +CHECK: ! +CHECK: elf.o +CHECK-NEXT: addlib/elf.o/ +CHECK-NOT: delete.o diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 0731f35ac45..ea6d0410a63 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -952,7 +952,7 @@ static int performOperation(ArchiveOperation Operation, } static void runMRIScript() { - enum class MRICommand { AddLib, AddMod, Create, Delete, Save, End, Invalid }; + enum class MRICommand { AddLib, AddMod, Create, CreateThin, Delete, Save, End, Invalid }; ErrorOr> Buf = MemoryBuffer::getSTDIN(); failIfError(Buf.getError()); @@ -976,6 +976,7 @@ static void runMRIScript() { .Case("addlib", MRICommand::AddLib) .Case("addmod", MRICommand::AddMod) .Case("create", MRICommand::Create) + .Case("createthin", MRICommand::CreateThin) .Case("delete", MRICommand::Delete) .Case("save", MRICommand::Save) .Case("end", MRICommand::End) @@ -995,6 +996,9 @@ static void runMRIScript() { case MRICommand::AddMod: addMember(NewMembers, Rest); break; + case MRICommand::CreateThin: + Thin = true; + LLVM_FALLTHROUGH; case MRICommand::Create: Create = true; if (!ArchiveName.empty())