Make FindProgramByName return paths with slashes unmodified on Windows.
authorMikhail Glushenkov <foldr@codedgers.com>
Tue, 2 Nov 2010 20:32:39 +0000 (20:32 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Tue, 2 Nov 2010 20:32:39 +0000 (20:32 +0000)
This makes its behaviour more consistent across platforms.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118048 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Program.h
lib/System/Unix/Program.inc
lib/System/Win32/Program.inc

index 0c14076e309c1c7f3614a2e4eee1a3cd311a8fc4..c595082e8bae97a21540ac0df6d7bffe5e6f5cb3 100644 (file)
@@ -114,7 +114,8 @@ namespace sys {
 
     /// This static constructor (factory) will attempt to locate a program in
     /// the operating system's file system using some pre-determined set of
-    /// locations to search (e.g. the PATH on Unix).
+    /// locations to search (e.g. the PATH on Unix). Paths with slashes are
+    /// returned unmodified.
     /// @returns A Path object initialized to the path of the program or a
     /// Path object that is empty (invalid) if the program could not be found.
     /// @brief Construct a Program by finding it by name.
index 86d9b2a1d9a8b52717c9d3b2a705e137e22755c8..e06f80ba83306e6f9f2b5bd60f7f3cef74cac9ff 100644 (file)
@@ -66,8 +66,8 @@ Program::FindProgramByName(const std::string& progName) {
   if (progName.find('/') != std::string::npos)
     return temp;
 
-  // At this point, the file name does not contain slashes. Search for it
-  // through the directories specified in the PATH environment variable.
+  // At this point, the file name is valid and does not contain slashes. Search
+  // for it through the directories specified in the PATH environment variable.
 
   // Get the path. If its empty, we can't do anything to find it.
   const char *PathStr = getenv("PATH");
index b55aa2fa80ff4d781b517d33746c55a07c8be9cf..2d6e665377e01a230aff012b849bdad3eb0a4b38 100644 (file)
@@ -67,10 +67,12 @@ Program::FindProgramByName(const std::string& progName) {
   Path temp;
   if (!temp.set(progName)) // invalid name
     return Path();
-  if (temp.canExecute()) // already executable as is
+  // Return paths with slashes verbatim.
+  if (progName.find('\\') != std::string::npos ||
+      progName.find('/') != std::string::npos)
     return temp;
 
-  // At this point, the file name is valid and its not executable.
+  // At this point, the file name is valid and does not contain slashes.
   // Let Windows search for it.
   char buffer[MAX_PATH];
   char *dummy = NULL;