Object: replace backslashes with slashes in embedded relative thin archive paths...
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 15 Nov 2016 21:36:35 +0000 (21:36 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 15 Nov 2016 21:36:35 +0000 (21:36 +0000)
This makes these thin archives portable between *nix and Windows.

Differential Revision: https://reviews.llvm.org/D26696

llvm-svn: 287038

llvm/lib/Object/ArchiveWriter.cpp
llvm/test/Object/archive-thin-paths.test [new file with mode: 0644]

index a7cd95f..64d04a0 100644 (file)
@@ -205,6 +205,12 @@ static std::string computeRelativePath(StringRef From, StringRef To) {
   for (auto ToE = sys::path::end(To); ToI != ToE; ++ToI)
     sys::path::append(Relative, *ToI);
 
+#ifdef LLVM_ON_WIN32
+  // Replace backslashes with slashes so that the path is portable between *nix
+  // and Windows.
+  std::replace(Relative.begin(), Relative.end(), '\\', '/');
+#endif
+
   return Relative.str();
 }
 
diff --git a/llvm/test/Object/archive-thin-paths.test b/llvm/test/Object/archive-thin-paths.test
new file mode 100644 (file)
index 0000000..21788b4
--- /dev/null
@@ -0,0 +1,9 @@
+REQUIRES: system-windows
+
+RUN: cd %T
+RUN: mkdir -p archive-thin-paths.dir
+RUN: echo foo > archive-thin-paths.dir/foo.o
+
+RUN: rm -f archive-thin-paths.a
+RUN: llvm-ar rcsT archive-thin-paths.a archive-thin-paths.dir\foo.o
+RUN: grep archive-thin-paths.dir/foo.o archive-thin-paths.a