[PATCH] D68033: [llvm-ar] Make paths case insensitive when on windows
Owen Reynolds via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 09:15:32 PDT 2019
gbreynoo created this revision.
gbreynoo added reviewers: MaskRay, rupprecht, grimar.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When on windows gnu-ar treats member names as case insensitive. This diff implements the same behaviour.
Repository:
rL LLVM
https://reviews.llvm.org/D68033
Files:
llvm/test/tools/llvm-ar/windows-case.test
llvm/tools/llvm-ar/llvm-ar.cpp
Index: llvm/tools/llvm-ar/llvm-ar.cpp
===================================================================
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -484,8 +484,16 @@
}
static std::string normalizePath(StringRef Path) {
- return CompareFullPath ? sys::path::convert_to_slash(Path)
- : std::string(sys::path::filename(Path));
+ std::string NormalizedPath = CompareFullPath
+ ? sys::path::convert_to_slash(Path)
+ : std::string(sys::path::filename(Path));
+
+ if (Triple(sys::getProcessTriple()).isOSWindows()) {
+ std::transform(NormalizedPath.begin(), NormalizedPath.end(),
+ NormalizedPath.begin(), ::toupper);
+ }
+
+ return NormalizedPath;
}
// Implement the 'x' operation. This function extracts files back to the file
@@ -561,7 +569,7 @@
if (Filter) {
auto I = find_if(Members, [Name](StringRef Path) {
- return Name == normalizePath(Path);
+ return normalizePath(Name) == normalizePath(Path);
});
if (I == Members.end())
continue;
@@ -690,8 +698,9 @@
StringMap<int> &MemberCount) {
if (Operation == QuickAppend || Members.empty())
return IA_AddOldMember;
- auto MI = find_if(
- Members, [Name](StringRef Path) { return Name == normalizePath(Path); });
+ auto MI = find_if(Members, [Name](StringRef Path) {
+ return normalizePath(Name) == normalizePath(Path);
+ });
if (MI == Members.end())
return IA_AddOldMember;
@@ -749,7 +758,7 @@
int Pos = Ret.size();
Expected<StringRef> NameOrErr = Child.getName();
failIfError(NameOrErr.takeError());
- StringRef Name = NameOrErr.get();
+ std::string Name = normalizePath(NameOrErr.get());
if (Name == PosName) {
assert(AddAfter || AddBefore);
if (AddBefore)
@@ -1019,8 +1028,9 @@
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 normalizePath(M.MemberName) == Name;
+ });
break;
}
case MRICommand::Save:
Index: llvm/test/tools/llvm-ar/windows-case.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ar/windows-case.test
@@ -0,0 +1,24 @@
+## 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: llvm-ar rc %t/archive.a %t/UPPERCASE/FILE.TXT
+# RUN: llvm-ar t %t/archive.a | FileCheck %s --check-prefix=ARCHIVE --implicit-check-not {{.}}
+
+# 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: llvm-ar t %t/thin-archive.a | FileCheck %s --check-prefix=THIN-ARCHIVE --implicit-check-not {{.}} -DPATH=%/t
+# THIN-ARCHIVE: [[PATH]]/lowerCase/file.txt
+
+# RUN: llvm-ar dTP %t/thin-archive.a %t/LOWERCASE/FILE.TXT
+# RUN: llvm-ar t %t/thin-archive.a | count 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68033.221784.patch
Type: text/x-patch
Size: 3531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190925/a33b6ef2/attachment.bin>
More information about the llvm-commits
mailing list