Browse Source

BUG: fix spaces in path on mingw, and change EXEC_PROGRAM to return false when it does not run, also do not convert the directory to an output path for EXEC_PROGRAM as this is done by the process execution, and doing it twice may cause trouble on some shells.

Bill Hoffman 21 years ago
parent
commit
2705b1bf73

+ 6 - 5
Source/cmExecProgramCommand.cxx

@@ -88,7 +88,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
   std::string command;
   if(arguments.size())
     {
-    command = cmSystemTools::ConvertToOutputPath(args[0].c_str());
+    command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str());
     command += " ";
     command += arguments;
     }
@@ -103,15 +103,16 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
     }
   int retVal = 0;
   std::string output;
+  bool result = true;
   if(args.size() - count == 2)
     {
     cmSystemTools::MakeDirectory(args[1].c_str());
-    cmSystemTools::RunCommand(command.c_str(), output, retVal,
-                              cmSystemTools::ConvertToOutputPath(args[1].c_str()).c_str(), verbose);
+    result = cmSystemTools::RunCommand(command.c_str(), output, retVal,
+                                       args[1].c_str(), verbose);
     }
   else
     {
-    cmSystemTools::RunCommand(command.c_str(), output, retVal, 0, verbose);
+    result = cmSystemTools::RunCommand(command.c_str(), output, retVal, 0, verbose);
     }
 
   if ( output_variable.size() > 0 )
@@ -138,6 +139,6 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
     m_Makefile->AddDefinition(return_variable.c_str(), buffer);
     }
   
-  return true;
+  return result;
 }
 

+ 14 - 1
Source/cmSystemTools.cxx

@@ -573,7 +573,6 @@ bool RunCommandViaWin32(const char* command,
     cmSystemTools::Error("No command specified");
     return false;
     }
-
   cmWin32ProcessExecution resProc;
   if(cmSystemTools::GetRunCommandHideConsole())
     {
@@ -586,6 +585,11 @@ bool RunCommandViaWin32(const char* command,
     }
   if ( !resProc.StartProcess(command, dir, verbose) )
     {
+    output = resProc.GetOutput();
+    if(verbose)
+      {
+      cmSystemTools::Stdout(output.c_str());
+      }
     return false;
     }
   resProc.Wait(timeout);
@@ -1148,6 +1152,15 @@ std::string cmSystemTools::ConvertToOutputPath(const char* path)
 #endif
 }
 
+std::string cmSystemTools::ConvertToRunCommandPath(const char* path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  return cmSystemTools::ConvertToWindowsOutputPath(path);
+#else
+  return cmSystemTools::ConvertToUnixOutputPath(path);
+#endif
+}
+
 bool cmSystemTools::StringEndsWith(const char* str1, const char* str2)
 {
   if ( !str1 || !str2 || strlen(str1) < strlen(str2) )

+ 5 - 0
Source/cmSystemTools.h

@@ -252,7 +252,12 @@ public:
     {
       s_ForceUnixPaths = v;
     }
+  // ConvertToOutputPath use s_ForceUnixPaths
   static std::string ConvertToOutputPath(const char* path);
+  // ConvertToRunCommandPath does not use s_ForceUnixPaths and should
+  // be used when RunCommand is called from cmake, because the 
+  // running cmake needs paths to be in its format
+  static std::string ConvertToRunCommandPath(const char* path);
 
   //! Check if the first string ends with the second one.
   static bool StringEndsWith(const char* str1, const char* str2);

+ 1 - 1
Source/cmTryRunCommand.cxx

@@ -94,7 +94,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
     if (fullPath.size() > 1)
       {
       std::string finalCommand = fullPath;
-      finalCommand = cmSystemTools::ConvertToOutputPath(fullPath.c_str());
+      finalCommand = cmSystemTools::ConvertToRunCommandPath(fullPath.c_str());
       if(runArgs.size())
         {
         finalCommand += runArgs;

+ 29 - 1
Source/cmWin32ProcessExecution.cxx

@@ -441,9 +441,37 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
     free(s1);
     return TRUE;
     }
-  output += "CreateProcessError ";
+  
+   LPVOID lpMsgBuf;
+
+  FormatMessage( 
+                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                NULL,
+                GetLastError(),
+                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+                (LPTSTR) &lpMsgBuf,
+                0,
+                NULL 
+                );
+  
+  // Free the buffer.
+ 
+  char* str = 0;
+  str = strcpy(new char[strlen((char*)lpMsgBuf)+1], (char*)lpMsgBuf); 
+  LocalFree( lpMsgBuf );
+  
+  output += "CreateProcessError: ";
+  output += str;
+  output += "\n";
+  output += "for command: ";
   output += s2;
+  if(path)
+    {
+    output += "\nin dir: ";
+    output += path;
+    }
   output += "\n";
+  delete [] str;
   free(s2);
   free(s1);
   return FALSE;