Index: llvm/test/tools/llvm-ar/flatten-thin-archive.test =================================================================== --- llvm/test/tools/llvm-ar/flatten-thin-archive.test +++ llvm/test/tools/llvm-ar/flatten-thin-archive.test @@ -1,19 +1,20 @@ # XFAIL: system-aix -# This test creates a thin archive that contains a thin archive, a regular -# archive, and a file. -# -# The inner thin archive should be flattened, but the regular archive should -# not. The order of members in the archive should match the input order, with -# flattened members appearing together. +## This test creates a thin archive that contains a thin archive, a regular +## archive, and a file. +## +## The inner thin archive should be flattened, but the regular archive should +## not. The order of members in the archive should match the input order, with +## flattened members appearing together. -RUN: touch %t-a.txt %t-b.txt %t-c.txt %t-d.txt %t-e.txt -RUN: rm -f %t-a-plus-b.a %t-d-plus-e.a %t.a -RUN: llvm-ar rcsT %t-a-plus-b.a %t-a.txt %t-b.txt -RUN: llvm-ar rcs %t-d-plus-e.a %t-d.txt %t-e.txt -RUN: llvm-ar rcsT %t.a %t-a-plus-b.a %t-c.txt %t-d-plus-e.a -RUN: llvm-ar t %t.a | FileCheck %s +# RUN: touch %t-a.txt %t-b.txt %t-c.txt %t-d.txt %t-e.txt +# RUN: rm -f %t-a-plus-b.a %t-d-plus-e.a %t.a +# RUN: llvm-ar rcs --thin %t-a-plus-b.a %t-a.txt %t-b.txt +# RUN: llvm-ar rcs %t-d-plus-e.a %t-d.txt %t-e.txt +# RUN: llvm-ar rcs --thin %t.a %t-a-plus-b.a %t-c.txt %t-d-plus-e.a +# RUN: FileCheck --input-file=%t.a %s -CHECK: a.txt -CHECK-NEXT: b.txt -CHECK-NEXT: c.txt -CHECK-NEXT: -d-plus-e.a +# CHECK: ! +# CHECK: a.txt +# CHECK-NEXT: b.txt +# CHECK-NEXT: c.txt +# CHECK-NEXT: -d-plus-e.a Index: llvm/test/tools/llvm-ar/full-to-thin-archive.test =================================================================== --- llvm/test/tools/llvm-ar/full-to-thin-archive.test +++ llvm/test/tools/llvm-ar/full-to-thin-archive.test @@ -2,14 +2,26 @@ ## Test archives do not convert to thin archives. # RUN: rm -rf %t && mkdir -p %t -# RUN: llvm-ar qc %t/archive.a %s -# RUN: not llvm-ar qT %t/archive.a %s 2>&1 | FileCheck %s -# RUN: not llvm-ar rT %t/archive.a %s 2>&1 | FileCheck %s +# RUN: llvm-ar qc %t/archive.a %S/Inputs/a.txt +# RUN: not llvm-ar q --thin %t/archive.a %s 2>&1 | FileCheck %s +# RUN: not llvm-ar r --thin %t/archive.a %s 2>&1 | FileCheck %s # CHECK: error: cannot convert a regular archive to a thin one -## Test that you can add a full archive's contents to a thin archive with 'L' -# RUN: llvm-ar -TqcL %t/thin.a %t/archive.a -# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin.a %s +## Test that you can add a full archive to a thin archive with 'L' +# RUN: llvm-ar -qcL --thin %t/thin1.a %S/Inputs/b.txt %t/archive.a +# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin1.a %s -THIN: ! +## Test that you can add a full archive to an existing thin archive with 'L' +# RUN: llvm-ar -q --thin %t/thin2.a %S/Inputs/b.txt +# RUN: llvm-ar -qL --thin %t/thin2.a %t/archive.a +# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin2.a %s + +# THIN: ! +# THIN: archive.a + +## Test archives do not convert to thin archives with use of 'L' and '--thin'. +# RUN: not llvm-ar -qL --thin %t/archive.a %t/thin2.a +# RUN: FileCheck --check-prefixes=FULL --input-file=%t/archive.a %s + +# FULL: ! Index: llvm/test/tools/llvm-ar/thin-to-full-archive.test =================================================================== --- llvm/test/tools/llvm-ar/thin-to-full-archive.test +++ llvm/test/tools/llvm-ar/thin-to-full-archive.test @@ -1,9 +1,9 @@ # XFAIL: system-aix ## Test thin archives do not siletly convert to full archives on write. -# RUN: rm -f %tthin.a %tfull.a +# RUN: rm -f %tthin.a %tfull1.a %tfull2.a -# RUN: llvm-ar -Trc %tthin.a %S/Inputs/a.txt +# RUN: llvm-ar -rc --thin %tthin.a %S/Inputs/a.txt # RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s # RUN: llvm-ar -q %tthin.a %S/Inputs/b.txt @@ -18,10 +18,22 @@ # RUN: llvm-ar -d %tthin.a %S/Inputs/c.txt # RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s -THIN: ! +# THIN: ! ## Test that you can add a thin archive's contents to a full archive with 'L' -# RUN: llvm-ar -qcL %tfull.a %tthin.a -# RUN: FileCheck --check-prefixes=FULL --input-file=%tfull.a %s +# RUN: llvm-ar -qcL %tfull1.a %tthin.a +# RUN: FileCheck --check-prefixes=FULL --input-file=%tfull1.a %s -FULL: ! +# FULL: ! +# NOT-FULL: thin.a +# FULL: a.txt +# FULL: b.txt + +## Test that you can add a thin archive's contents to an existing full archive with 'L' +# RUN: llvm-ar -q %tfull2.a %S/Inputs/d.txt +# RUN: llvm-ar -qL %tfull2.a %tthin.a +# RUN: FileCheck --check-prefixes=FULL --input-file=%tfull2.a %s + +## Test that thin archives do not convert to a full archive with 'L' and no use of '--thin' +# RUN: llvm-ar -qL %tthin.a %tfull2.a +# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s Index: llvm/tools/llvm-ar/llvm-ar.cpp =================================================================== --- llvm/tools/llvm-ar/llvm-ar.cpp +++ llvm/tools/llvm-ar/llvm-ar.cpp @@ -653,13 +653,6 @@ static void addChildMember(std::vector &Members, const object::Archive::Child &M, bool FlattenArchive = false) { - if (Thin && !M.getParent()->isThin()) - fail("cannot convert a regular archive to a thin one"); - - // Avoid converting an existing thin archive to a regular one. - if (!AddLibrary && M.getParent()->isThin()) - Thin = true; - Expected NMOrErr = NewArchiveMember::getOldMember(M, Deterministic); failIfError(NMOrErr.takeError()); @@ -1027,8 +1020,14 @@ "unable to load '" + ArchiveName + "'"); std::unique_ptr Archive = std::move(ArchiveOrError.get()); - if (Archive->isThin()) + if (Thin && !Archive->isThin()) + fail("cannot convert a regular archive to a thin one"); + + if (Archive->isThin()) { + Thin = true; CompareFullPath = true; + } + performOperation(Operation, Archive.get(), std::move(Buf.get()), NewMembers); return 0;