[PATCH] Fix mach-o tests on Windows

Rui Ueyama ruiu at google.com
Tue Jul 29 11:34:16 PDT 2014


Hi t.p.northover,

The tests assume the path separator is '/', but if you run
them on Windows it is '\'. As a result the tests are failing
on Windows. This should be the minimal change to make these
tests to pass on Windows platform.

http://reviews.llvm.org/D4710

Files:
  include/lld/ReaderWriter/MachOLinkingContext.h
  lib/Driver/DarwinLdDriver.cpp
  lib/ReaderWriter/MachO/MachOLinkingContext.cpp

Index: include/lld/ReaderWriter/MachOLinkingContext.h
===================================================================
--- include/lld/ReaderWriter/MachOLinkingContext.h
+++ include/lld/ReaderWriter/MachOLinkingContext.h
@@ -14,6 +14,7 @@
 #include "lld/ReaderWriter/Reader.h"
 #include "lld/ReaderWriter/Writer.h"
 
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MachO.h"
 
Index: lib/Driver/DarwinLdDriver.cpp
===================================================================
--- lib/Driver/DarwinLdDriver.cpp
+++ lib/Driver/DarwinLdDriver.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Signals.h"
 
+#include <algorithm>
 
 namespace {
 
@@ -332,7 +333,11 @@
         diagnostics << "Unable to find library -l" << arg->getValue() << "\n";
         return false;
       } else if (ctx.testingLibResolution()) {
-        diagnostics << "Found library " << resolvedPath.get() << '\n';
+       // Test may be running on Windows. Canonicalize the path
+       // separator to '/' to get the consistent outputs for tests.
+       std::string path = resolvedPath.get();
+       std::replace(path.begin(), path.end(), '\\', '/');
+       diagnostics << "Found library " << path << '\n';
       }
       inputPath = resolvedPath.get();
       break;
Index: lib/ReaderWriter/MachO/MachOLinkingContext.cpp
===================================================================
--- lib/ReaderWriter/MachO/MachOLinkingContext.cpp
+++ lib/ReaderWriter/MachO/MachOLinkingContext.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Support/MachO.h"
 #include "llvm/Support/Path.h"
 
+#include <algorithm>
+
 using lld::mach_o::ArchHandler;
 using namespace llvm::MachO;
 
@@ -297,7 +299,9 @@
 
   // Otherwise, we're in test mode: only files explicitly provided on the
   // command-line exist.
-  return _existingPaths.find(path) != _existingPaths.end();
+  std::string key = path.str();
+  std::replace(key.begin(), key.end(), '\\', '/');
+  return _existingPaths.find(key) != _existingPaths.end();
 }
 
 void MachOLinkingContext::addModifiedSearchDir(
@@ -308,7 +312,7 @@
   //   + If the last -syslibroot is "/", all of them are ignored (don't ask).
   //   + -syslibroot only applies to absolute paths.
   if (!syslibRoots.empty() && syslibRoots.back() != "/" &&
-      llvm::sys::path::is_absolute(libPath)) {
+      libPath.startswith("/")) {
     for (auto syslibRoot : syslibRoots) {
       SmallString<256> path(syslibRoot);
       llvm::sys::path::append(path, libPath);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4710.11990.patch
Type: text/x-patch
Size: 2546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140729/d428139f/attachment.bin>


More information about the llvm-commits mailing list