Index: llvm/test/tools/llvm-ar/mri-delete.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-ar/mri-delete.test @@ -0,0 +1,14 @@ +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 "addmod %S/Inputs/elf.yaml" >> %t.mri +RUN: echo "delete %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 + +CHECK-NOT: mri-delete.test{{.*}}.o Index: llvm/tools/llvm-ar/llvm-ar.cpp =================================================================== --- llvm/tools/llvm-ar/llvm-ar.cpp +++ llvm/tools/llvm-ar/llvm-ar.cpp @@ -488,6 +488,17 @@ Members[Pos] = std::move(*NMOrErr); } +static void deleteMember(std::vector &Members, + StringRef FileName) { + StringRef MemberName = sys::path::filename(FileName); + for (auto Member = Members.begin(); Member != Members.end();) { + if (Member->MemberName == MemberName) + Member = Members.erase(Member); + else + ++Member; + } +} + enum InsertAction { IA_AddOldMember, IA_AddNewMember, @@ -758,7 +769,7 @@ } static void runMRIScript() { - enum class MRICommand { AddLib, AddMod, Create, Save, End, Invalid }; + enum class MRICommand { AddLib, AddMod, Create, Delete, Save, End, Invalid }; ErrorOr> Buf = MemoryBuffer::getSTDIN(); failIfError(Buf.getError()); @@ -779,6 +790,7 @@ .Case("addlib", MRICommand::AddLib) .Case("addmod", MRICommand::AddMod) .Case("create", MRICommand::Create) + .Case("delete", MRICommand::Delete) .Case("save", MRICommand::Save) .Case("end", MRICommand::End) .Default(MRICommand::Invalid); @@ -813,6 +825,9 @@ fail("File already saved"); ArchiveName = Rest; break; + case MRICommand::Delete: + deleteMember(NewMembers, Rest); + break; case MRICommand::Save: Saved = true; break;