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.

This commit is contained in:
Bill Hoffman 2004-06-23 16:34:38 -04:00
parent dc4a6f63b0
commit 2705b1bf73
5 changed files with 56 additions and 9 deletions

View File

@ -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;
}

View File

@ -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) )

View File

@ -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);

View File

@ -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;

View File

@ -441,9 +441,37 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
free(s1);
return TRUE;
}
output += "CreateProcessError ";
output += s2;
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;