XFAIL the test cases for r186044 on Hexagon
[oota-llvm.git] / lib / Support / Windows / Program.inc
index 90a5cdb78ffd01f835433e9ab217934208d8c95d..a368407960c4bac4c10c55f3d35ecf209d9bc525 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Windows.h"
+#include "llvm/Support/FileSystem.h"
 #include <cstdio>
 #include <fcntl.h>
 #include <io.h>
@@ -33,13 +34,11 @@ namespace llvm {
 using namespace sys;
 
 // This function just uses the PATH environment variable to find the program.
-Path sys::FindProgramByName(const std::string& progName) {
+std::string sys::FindProgramByName(const std::string &progName) {
   // Check some degenerate cases
   if (progName.length() == 0) // no program
-    return Path();
-  Path temp;
-  if (!temp.set(progName)) // invalid name
-    return Path();
+    return "";
+  std::string temp = progName;
   // Return paths with slashes verbatim.
   if (progName.find('\\') != std::string::npos ||
       progName.find('/') != std::string::npos)
@@ -54,11 +53,11 @@ Path sys::FindProgramByName(const std::string& progName) {
 
   // See if it wasn't found.
   if (len == 0)
-    return Path();
+    return "";
 
   // See if we got the entire path.
   if (len < MAX_PATH)
-    return Path(buffer);
+    return std::string(buffer);
 
   // Buffer was too small; grow and retry.
   while (true) {
@@ -68,15 +67,15 @@ Path sys::FindProgramByName(const std::string& progName) {
     // It is unlikely the search failed, but it's always possible some file
     // was added or removed since the last search, so be paranoid...
     if (len2 == 0)
-      return Path();
+      return "";
     else if (len2 <= len)
-      return Path(b);
+      return std::string(b);
 
     len = len2;
   }
 }
 
-static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {
+static HANDLE RedirectIO(const StringRef *path, int fd, std::string* ErrMsg) {
   HANDLE h;
   if (path == 0) {
     DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),
@@ -85,19 +84,19 @@ static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {
     return h;
   }
 
-  const char *fname;
-  if (path->isEmpty())
+  std::string fname;
+  if (path->empty())
     fname = "NUL";
   else
-    fname = path->c_str();
+    fname = *path;
 
   SECURITY_ATTRIBUTES sa;
   sa.nLength = sizeof(sa);
   sa.lpSecurityDescriptor = 0;
   sa.bInheritHandle = TRUE;
 
-  h = CreateFile(fname, fd ? GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ,
-                 &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS,
+  h = CreateFile(fname.c_str(), fd ? GENERIC_WRITE : GENERIC_READ,
+                 FILE_SHARE_READ, &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS,
                  FILE_ATTRIBUTE_NORMAL, NULL);
   if (h == INVALID_HANDLE_VALUE) {
     MakeErrMsg(ErrMsg, std::string(fname) + ": Can't open file for " +
@@ -171,13 +170,13 @@ static unsigned int ArgLenWithQuotes(const char *Str) {
 }
 
 static bool Execute(void **Data,
-                    const Path& path,
+                    StringRef Program,
                     const char** args,
                     const char** envp,
-                    const Path** redirects,
+                    const StringRef** redirects,
                     unsigned memoryLimit,
                     std::string* ErrMsg) {
-  if (!path.canExecute()) {
+  if (!sys::fs::can_execute(Program)) {
     if (ErrMsg)
       *ErrMsg = "program not executable";
     return false;
@@ -297,7 +296,8 @@ static bool Execute(void **Data,
 
   fflush(stdout);
   fflush(stderr);
-  BOOL rc = CreateProcess(path.c_str(), command, NULL, NULL, TRUE, 0,
+  std::string ProgramStr = Program;
+  BOOL rc = CreateProcess(ProgramStr.c_str(), command, NULL, NULL, TRUE, 0,
                           envblock, NULL, &si, &pi);
   DWORD err = GetLastError();
 
@@ -311,7 +311,7 @@ static bool Execute(void **Data,
   if (!rc) {
     SetLastError(err);
     MakeErrMsg(ErrMsg, std::string("Couldn't execute program '") +
-               path.str() + "'");
+               ProgramStr + "'");
     return false;
   }
   if (Data) {
@@ -356,8 +356,8 @@ static bool Execute(void **Data,
   return true;
 }
 
-static int WaitAux(Win32ProcessInfo *wpi, const Path &path,
-                   unsigned secondsToWait, std::string *ErrMsg) {
+static int WaitAux(Win32ProcessInfo *wpi, unsigned secondsToWait,
+                   std::string *ErrMsg) {
   // Wait for the process to terminate.
   HANDLE hProcess = wpi->hProcess;
   DWORD millisecondsToWait = INFINITE;
@@ -398,10 +398,10 @@ static int WaitAux(Win32ProcessInfo *wpi, const Path &path,
   return 1;
 }
 
-static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
+static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,
                 std::string *ErrMsg) {
   Win32ProcessInfo *wpi = reinterpret_cast<Win32ProcessInfo *>(Data);
-  int Ret = WaitAux(wpi, path, secondsToWait, ErrMsg);
+  int Ret = WaitAux(wpi, secondsToWait, ErrMsg);
 
   CloseHandle(wpi->hProcess);
   delete wpi;