From 96601b33fae71b7f516be4b7457dd040622f94db Mon Sep 17 00:00:00 2001 From: kai Date: Sat, 22 Jun 2013 16:58:56 +0200 Subject: [PATCH] Fix ldmd for LLVM 3.4 The Path::canExecute() method is gone. As a first fix just copy the source. --- driver/ldmd.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp index 82201b96..a269027c 100644 --- a/driver/ldmd.cpp +++ b/driver/ldmd.cpp @@ -54,6 +54,11 @@ #include "llvm/Support/raw_ostream.h" #if LDC_LLVM_VER >= 304 #include "llvm/Support/PathV1.h" +#if _WIN32 +#include "Windows.h" +#else +#include +#endif #endif #include #include @@ -96,6 +101,28 @@ static ls::Path PrependMainExecutablePath(const std::string &ExeName, } #endif +static bool canExecute(const ls::Path &p) +{ +#if LDC_LLVM_VER >= 304 +#if _WIN32 + // FIXME: take security attributes into account. + DWORD attr = GetFileAttributes(p.c_str()); + return attr != INVALID_FILE_ATTRIBUTES; +#else + if (0 != access(p.c_str(), R_OK | X_OK )) + return false; + struct stat buf; + if (0 != stat(p.c_str(), &buf)) + return false; + if (!S_ISREG(buf.st_mode)) + return false; + return true; +#endif +#else + return p.canExecute(); +#endif +} + // We reuse DMD's response file parsing routine for maximum compatibilty - it // handles quotes in a very peciuliar way. int response_expand(size_t *pargc, char ***pargv); @@ -923,14 +950,14 @@ ls::Path locateBinary(std::string exeName, const char* argv0) { ls::Path path = llvm::PrependMainExecutablePath(exeName, argv0, (void*)&locateBinary); - if (path.canExecute()) return path; + if (canExecute(path)) return path; #if LDC_LLVM_VER >= 304 path = ls::FindProgramByName(exeName); #else path = ls::Program::FindProgramByName(exeName); #endif - if (path.canExecute()) return path; + if (canExecute(path)) return path; return ls::Path(); }