--- /dev/null
+## Test that on windows, members are case insensitive.
+# UNSUPPORTED: system-windows
+
+# RUN: mkdir -p %t
+# RUN: rm -rf %t/lowerCase %t/UPPERCASE && mkdir %t/lowerCase %t/UPPERCASE
+# RUN: echo lowerCase > %t/lowerCase/file.txt
+# RUN: echo UPPERCASE > %t/UPPERCASE/FILE.TXT
+
+# RUN: rm -f %t/archive.a
+# RUN: llvm-ar rc %t/archive.a %t/lowerCase/file.txt
+# RUN: llvm-ar rc %t/archive.a %t/UPPERCASE/FILE.TXT
+# RUN: FileCheck %s -input-file=%t/archive.a --check-prefix=ARCHIVE
+
+# ARCHIVE: file.txt
+# ARCHIVE: FILE.TXT
+
+# RUN: rm -f %t/thin-archive.a
+# RUN: llvm-ar Trc %t/thin-archive.a %t/lowerCase/file.txt %t/UPPERCASE/FILE.TXT
+# RUN: llvm-ar dTP %t/thin-archive.a %t/uppercase/file.txt
+
+# RUN: FileCheck %s -input-file=%t/thin-archive.a --check-prefix=THIN-ARCHIVE -DPATH=%/t
+
+# RUN: llvm-ar dTP %t/thin-archive.a %t/LOWERCASE/FILE.TXT
+# RUN: FileCheck %s -input-file=%t/thin-archive.a --check-prefix=THIN-ARCHIVE -DPATH=%/t
+
+# THIN-ARCHIVE: [[PATH]]/lowerCase/file.txt
+# THIN-ARCHIVE: [[PATH]]/UPPERCASE/FILE.TXT
--- /dev/null
+## Test that on windows, members are case insensitive.
+# REQUIRES: system-windows
+
+# RUN: mkdir -p %t
+# RUN: rm -rf %t/lowerCase %t/UPPERCASE && mkdir %t/lowerCase %t/UPPERCASE
+# RUN: echo lowerCase > %t/lowerCase/file.txt
+# RUN: echo UPPERCASE > %t/UPPERCASE/FILE.TXT
+
+# RUN: rm -f %t/archive.a
+# RUN: llvm-ar rc %t/archive.a %t/lowerCase/file.txt
+# RUN: FileCheck %s -input-file=%t/archive.a --check-prefix=LOWER --implicit-check-not=FILE.TXT
+# RUN: llvm-ar rc %t/archive.a %t/UPPERCASE/FILE.TXT
+# RUN: FileCheck %s -input-file=%t/archive.a --check-prefix=UPPER --implicit-check-not=file.txt
+
+# LOWER: file.txt
+# UPPER: FILE.TXT
+
+# RUN: rm -f %t/thin-archive.a
+# RUN: llvm-ar Trc %t/thin-archive.a %t/lowerCase/file.txt %t/UPPERCASE/FILE.txt
+# RUN: llvm-ar dTP %t/thin-archive.a %t/uppercase/file.txt
+
+# RUN: FileCheck %s -input-file=%t/thin-archive.a --check-prefix=THIN-ARCHIVE -DPATH=%/t
+# THIN-ARCHIVE-NOT: [[PATH]]/UPPERCASE/FILE.TXT
+# THIN-ARCHIVE: [[PATH]]/lowerCase/file.txt
+
+# RUN: llvm-ar dTP %t/thin-archive.a %t/LOWERCASE/FILE.TXT
+# RUN: FileCheck %s -input-file=%t/thin-archive.a --check-prefix=EMPTY --implicit-check-not {{.}}
+
+EMPTY: !<thin>
#include <io.h>
#endif
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
using namespace llvm;
// The name this program was invoked as.
: std::string(sys::path::filename(Path));
}
+static bool comparePaths(StringRef Path1, StringRef Path2) {
+// When on Windows this function calls CompareStringOrdinal
+// as Windows file paths are case-insensitive.
+// CompareStringOrdinal compares two Unicode strings for
+// binary equivalence and allows for case insensitivity.
+#ifdef _WIN32
+ SmallVector<wchar_t, 128> WPath1, WPath2;
+ failIfError(sys::path::widenPath(normalizePath(Path1), WPath1));
+ failIfError(sys::path::widenPath(normalizePath(Path2), WPath2));
+
+ return CompareStringOrdinal(WPath1.data(), WPath1.size(), WPath2.data(),
+ WPath2.size(), true) == CSTR_EQUAL;
+#else
+ return normalizePath(Path1) == normalizePath(Path2);
+#endif
+}
+
// Implement the 'x' operation. This function extracts files back to the file
// system.
static void doExtract(StringRef Name, const object::Archive::Child &C) {
if (Filter) {
auto I = find_if(Members, [Name](StringRef Path) {
- return Name == normalizePath(Path);
+ return comparePaths(Name, Path);
});
if (I == Members.end())
continue;
if (Operation == QuickAppend || Members.empty())
return IA_AddOldMember;
auto MI = find_if(
- Members, [Name](StringRef Path) { return Name == normalizePath(Path); });
+ Members, [Name](StringRef Path) { return comparePaths(Name, Path); });
if (MI == Members.end())
return IA_AddOldMember;
std::vector<NewArchiveMember> Moved;
int InsertPos = -1;
if (OldArchive) {
- std::string PosName = normalizePath(RelPos);
Error Err = Error::success();
StringMap<int> MemberCount;
for (auto &Child : OldArchive->children(Err)) {
int Pos = Ret.size();
Expected<StringRef> NameOrErr = Child.getName();
failIfError(NameOrErr.takeError());
- StringRef Name = NameOrErr.get();
- if (Name == PosName) {
+ std::string Name = NameOrErr.get();
+ if (comparePaths(Name, RelPos)) {
assert(AddAfter || AddBefore);
if (AddBefore)
InsertPos = Pos;
ArchiveName = Rest;
break;
case MRICommand::Delete: {
- std::string Name = normalizePath(Rest);
- llvm::erase_if(NewMembers,
- [=](NewArchiveMember &M) { return M.MemberName == Name; });
+ llvm::erase_if(NewMembers, [=](NewArchiveMember &M) {
+ return comparePaths(M.MemberName, Rest);
+ });
break;
}
case MRICommand::Save: