ENH: fix more space problems, you can add args to the ExecProgram command separatly now

This commit is contained in:
Bill Hoffman 2002-04-03 16:14:06 -05:00
parent 1c73117b7a
commit d42055b283
9 changed files with 109 additions and 56 deletions

View File

@ -25,16 +25,45 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
this->SetError("called with incorrect number of arguments");
return false;
}
std::string arguments;
bool doingargs = false;
int count = 0;
for(int i=0; i < args.size(); ++i)
{
if(doingargs)
{
arguments += args[i];
arguments += " ";
count++;
}
else if(args[i] == "ARGS")
{
count++;
doingargs = true;
}
}
std::string command;
if(arguments.size())
{
command = cmSystemTools::ConvertToOutputPath(args[0].c_str());
command += " ";
command += arguments;
}
else
{
command = args[0];
}
std::string output;
if(args.size() == 2)
if(args.size() - count == 2)
{
cmSystemTools::MakeDirectory(args[1].c_str());
cmSystemTools::RunCommand(args[0].c_str(), output,
cmSystemTools::RunCommand(command.c_str(), output,
cmSystemTools::ConvertToOutputPath(args[1].c_str()).c_str());
}
else
{
cmSystemTools::RunCommand(args[0].c_str(), output);
cmSystemTools::RunCommand(command.c_str(), output);
}
return true;
}

View File

@ -64,7 +64,11 @@ public:
virtual const char* GetFullDocumentation()
{
return
"EXEC_PROGRAM(Executable [Directory to run in])";
"EXEC_PROGRAM(Executable [Directory to run in] [ARGS arguments to executable])"
"The executable is run in the optionally specified Directory. The executable "
"can include arguments if it is double quoted, but it is better to use the "
"optional ARGS argument to specify arguments to the program. This is because "
"cmake will then be able to escape spaces in the Executable path.";
}
cmTypeMacro(cmExecProgramCommand, cmCommand);

View File

@ -52,19 +52,14 @@ std::string cmNMakeMakefileGenerator::ShortPath(const char* path)
}
// if there are spaces then call GetShortPathName to get rid of them
char *buffer = new char[strlen(path)+1];
if(GetShortPathName(path, buffer,
static_cast<int>(strlen(path)+1)) != 0)
{
ret = buffer;
}
else
if(!cmSystemTools::GetShortPath(path, ret))
{
// if GetShortPathName failed for some reason use
// ConvertToOutputPath instead which will at least escape the spaces
ret = this->ConvertToOutputPath(path);
return ret;
}
delete [] buffer;
ret = this->ConvertToOutputPath(ret.c_str());
return ret;
}
@ -161,37 +156,37 @@ void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout)
m_Makefile->ExpandVariablesInString(replaceVars);
fout << replaceVars.c_str();
std::string ccommand = m_Makefile->GetDefinition("CCOMMAND_COMMAND");
fout << "RM = " << this->ConvertToOutputPath(ccommand.c_str()) << " remove -f\n";
fout << "RM = " << this->ShortPath(ccommand.c_str()) << " remove -f\n";
std::string ccompiler = m_Makefile->GetDefinition("CMAKE_C_COMPILER");
fout << "CMAKE_C_COMPILER = "
<< this->ConvertToOutputPath(ccompiler.c_str()) << "\n";
<< this->ShortPath(ccompiler.c_str()) << "\n";
std::string cxxcompiler = m_Makefile->GetDefinition("CMAKE_CXX_COMPILER");
fout << "CMAKE_CXX_COMPILER = "
<< this->ConvertToOutputPath(cxxcompiler.c_str()) << "\n";
<< this->ShortPath(cxxcompiler.c_str()) << "\n";
std::string linker = m_Makefile->GetDefinition("CMAKE_LINKER");
fout << "CMAKE_LINKER = " <<
this->ConvertToOutputPath(linker.c_str()) << "\n";
this->ShortPath(linker.c_str()) << "\n";
std::string lib_manager = m_Makefile->GetDefinition("CMAKE_LIBRARY_MANAGER");
fout << "CMAKE_LIBRARY_MANAGER = "
<< this->ConvertToOutputPath(lib_manager.c_str()) << "\n";
<< this->ShortPath(lib_manager.c_str()) << "\n";
std::string cmakecommand = m_Makefile->GetDefinition("CMAKE_COMMAND");
fout << "CMAKE_COMMAND = "
<< this->ConvertToOutputPath(cmakecommand.c_str()) << "\n";
<< this->ShortPath(cmakecommand.c_str()) << "\n";
fout << "CMAKE_CURRENT_SOURCE = "
<< ShortPath(m_Makefile->GetStartDirectory() )
<< this->ShortPath(m_Makefile->GetStartDirectory() )
<< "\n";
fout << "CMAKE_CURRENT_BINARY = "
<< ShortPath(m_Makefile->GetStartOutputDirectory())
<< this->ShortPath(m_Makefile->GetStartOutputDirectory())
<< "\n";
fout << "CMAKE_SOURCE_DIR = "
<< ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
<< this->ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
fout << "CMAKE_BINARY_DIR = "
<< ShortPath(m_Makefile->GetHomeOutputDirectory() )
<< this->ShortPath(m_Makefile->GetHomeOutputDirectory() )
<< "\n";
// Output Include paths

View File

@ -1275,20 +1275,13 @@ bool cmSystemTools::RunCommand(const char* command,
std::string shortCmd;
std::string cmd = quoted.match(1);
std::string args = quoted.match(2);
char *buffer = new char[cmd.size()+1];
if(GetShortPathName(cmd.c_str(), buffer,
int(cmd.size())) != 0)
if(!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd))
{
shortCmd = buffer;
shortCmd += " ";
shortCmd += args;
}
else
{
cmSystemTools::Error("Could not get GetShortPathName for ",
cmd.c_str());
cmSystemTools::Error("GetShortPath failed for " , cmd.c_str());
return false;
}
shortCmd += " ";
shortCmd += args;
return RunCommandViaSystem(shortCmd.c_str(), dir,
output, retVal, verbose);
}
@ -1845,3 +1838,44 @@ void cmSystemTools::ExpandListArguments(std::vector<std::string> const& argument
}
}
}
bool cmSystemTools::GetShortPath(const char* path, std::string& shortPath)
{
#if defined(WIN32) && !defined(__CYGWIN__)
const int size = int(strlen(path)) +1; // size of return
char *buffer = new char[size]; // create a buffer
buffer[0] = 0;
int ret = GetShortPathName(path, buffer, size);
if(buffer[0] == 0 || ret > size)
{
if(ret < size)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
cmSystemTools::Error((LPCTSTR)lpMsgBuf);
LocalFree( lpMsgBuf );
}
cmSystemTools::Error("Unable to get a short path: ", path);
return false;
}
else
{
shortPath = buffer;
delete [] buffer;
return true;
}
#else
shortPath = path;
return true;
#endif
}

View File

@ -267,6 +267,9 @@ public:
static bool RunCommand(const char* command, std::string& output,
int &retVal, const char* directory = 0, bool verbose = true);
///! for windows return the short path for the given path, unix just a pass through
static bool GetShortPath(const char* path, std::string& result);
///! change directory the the directory specified
static int ChangeDirectory(const char* dir);

View File

@ -157,13 +157,7 @@ int main (int argc, char **argv)
#if defined(_WIN32) && !defined(__CYGWIN__)
if(makeCommand.find(' ') != std::string::npos)
{
char *buffer = new char[makeCommand.size()+1];
if(GetShortPathName(makeCommand.c_str(), buffer,
int(makeCommand.size()+1)) != 0)
{
makeCommand = buffer;
}
delete [] buffer;\
cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
}
#endif
makeCommand += " ";
@ -177,13 +171,7 @@ int main (int argc, char **argv)
#if defined(_WIN32) && !defined(__CYGWIN__)
if(makeCommand.find(' ') != std::string::npos)
{
char *buffer = new char[makeCommand.size()+1];
if(GetShortPathName(makeCommand.c_str(), buffer,
int(makeCommand.size()+1)) != 0)
{
makeCommand = buffer;
}
delete [] buffer;\
cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
}
#endif
makeCommand += " ";

View File

@ -124,12 +124,12 @@ IF (WIN32)
${Complex_SOURCE_DIR}/Library/dummy
"${dir}/${file}"
COPYONLY IMMEDIATE)
EXEC_PROGRAM("${CCOMMAND_COMMAND} write_regv \"${hkey}\" \"${dir}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"")
FIND_PATH(REGISTRY_TEST_PATH
${file}
"[${hkey}]")
EXEC_PROGRAM("${CCOMMAND_COMMAND} delete_regv \"${hkey}\"")
EXEC_PROGRAM("${CCOMMAND_COMMAND} remove \"${dir}/${file}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"")
ENDIF (NOT UNIX)
ENDIF (WIN32)

View File

@ -124,12 +124,12 @@ IF (WIN32)
${Complex_SOURCE_DIR}/Library/dummy
"${dir}/${file}"
COPYONLY IMMEDIATE)
EXEC_PROGRAM("${CCOMMAND_COMMAND} write_regv \"${hkey}\" \"${dir}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"")
FIND_PATH(REGISTRY_TEST_PATH
${file}
"[${hkey}]")
EXEC_PROGRAM("${CCOMMAND_COMMAND} delete_regv \"${hkey}\"")
EXEC_PROGRAM("${CCOMMAND_COMMAND} remove \"${dir}/${file}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"")
ENDIF (NOT UNIX)
ENDIF (WIN32)

View File

@ -124,12 +124,12 @@ IF (WIN32)
${Complex_SOURCE_DIR}/Library/dummy
"${dir}/${file}"
COPYONLY IMMEDIATE)
EXEC_PROGRAM("${CCOMMAND_COMMAND} write_regv \"${hkey}\" \"${dir}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"")
FIND_PATH(REGISTRY_TEST_PATH
${file}
"[${hkey}]")
EXEC_PROGRAM("${CCOMMAND_COMMAND} delete_regv \"${hkey}\"")
EXEC_PROGRAM("${CCOMMAND_COMMAND} remove \"${dir}/${file}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"")
EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"")
ENDIF (NOT UNIX)
ENDIF (WIN32)