Merge topic 'remove-EscapeSpaces'

cb9ea26 Remove cmSystemTools::EscapeSpaces method
5383657 CTest: Avoid use of old EscapeSpaces method
This commit is contained in:
Brad King 2010-08-19 13:28:50 -04:00 committed by CMake Topic Stage
commit c873a83b6c
7 changed files with 62 additions and 99 deletions

View File

@ -201,8 +201,7 @@ void cmCTestMemCheckHandler::Initialize()
this->CustomMaximumPassedTestOutputSize = 0; this->CustomMaximumPassedTestOutputSize = 0;
this->CustomMaximumFailedTestOutputSize = 0; this->CustomMaximumFailedTestOutputSize = 0;
this->MemoryTester = ""; this->MemoryTester = "";
this->MemoryTesterOptionsParsed.clear(); this->MemoryTesterOptions.clear();
this->MemoryTesterOptions = "";
this->MemoryTesterStyle = UNKNOWN; this->MemoryTesterStyle = UNKNOWN;
this->MemoryTesterOutputFile = ""; this->MemoryTesterOutputFile = "";
int cc; int cc;
@ -249,12 +248,12 @@ void cmCTestMemCheckHandler::GenerateTestCommand(
std::vector<cmStdString>::size_type pp; std::vector<cmStdString>::size_type pp;
std::string memcheckcommand = ""; std::string memcheckcommand = "";
memcheckcommand = this->MemoryTester; memcheckcommand = this->MemoryTester;
for ( pp = 0; pp < this->MemoryTesterOptionsParsed.size(); pp ++ ) for ( pp = 0; pp < this->MemoryTesterOptions.size(); pp ++ )
{ {
args.push_back(this->MemoryTesterOptionsParsed[pp]); args.push_back(this->MemoryTesterOptions[pp]);
memcheckcommand += " "; memcheckcommand += " \"";
memcheckcommand += cmSystemTools::EscapeSpaces( memcheckcommand += this->MemoryTesterOptions[pp];
this->MemoryTesterOptionsParsed[pp].c_str()); memcheckcommand += "\"";
} }
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Memory check command: " cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Memory check command: "
<< memcheckcommand << std::endl); << memcheckcommand << std::endl);
@ -440,18 +439,21 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
} }
// Setup the options // Setup the options
std::string memoryTesterOptions;
if ( this->CTest->GetCTestConfiguration( if ( this->CTest->GetCTestConfiguration(
"MemoryCheckCommandOptions").size() ) "MemoryCheckCommandOptions").size() )
{ {
this->MemoryTesterOptions = this->CTest->GetCTestConfiguration( memoryTesterOptions = this->CTest->GetCTestConfiguration(
"MemoryCheckCommandOptions"); "MemoryCheckCommandOptions");
} }
else if ( this->CTest->GetCTestConfiguration( else if ( this->CTest->GetCTestConfiguration(
"ValgrindCommandOptions").size() ) "ValgrindCommandOptions").size() )
{ {
this->MemoryTesterOptions = this->CTest->GetCTestConfiguration( memoryTesterOptions = this->CTest->GetCTestConfiguration(
"ValgrindCommandOptions"); "ValgrindCommandOptions");
} }
this->MemoryTesterOptions
= cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
this->MemoryTesterOutputFile this->MemoryTesterOutputFile
= this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.log"; = this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.log";
@ -459,10 +461,14 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
if ( this->MemoryTester.find("valgrind") != std::string::npos ) if ( this->MemoryTester.find("valgrind") != std::string::npos )
{ {
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND; this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
if ( !this->MemoryTesterOptions.size() ) if ( this->MemoryTesterOptions.empty() )
{ {
this->MemoryTesterOptions = "-q --tool=memcheck --leak-check=yes " this->MemoryTesterOptions.push_back("-q");
"--show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=50"; this->MemoryTesterOptions.push_back("--tool=memcheck");
this->MemoryTesterOptions.push_back("--leak-check=yes");
this->MemoryTesterOptions.push_back("--show-reachable=yes");
this->MemoryTesterOptions.push_back("--workaround-gcc296-bugs=yes");
this->MemoryTesterOptions.push_back("--num-callers=50");
} }
if ( this->CTest->GetCTestConfiguration( if ( this->CTest->GetCTestConfiguration(
"MemoryCheckSuppressionFile").size() ) "MemoryCheckSuppressionFile").size() )
@ -476,17 +482,15 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
"MemoryCheckSuppressionFile").c_str() << std::endl); "MemoryCheckSuppressionFile").c_str() << std::endl);
return false; return false;
} }
this->MemoryTesterOptions += " --suppressions=" + std::string suppressions = "--suppressions="
cmSystemTools::EscapeSpaces(this->CTest->GetCTestConfiguration( + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
"MemoryCheckSuppressionFile").c_str()) + ""; this->MemoryTesterOptions.push_back(suppressions);
} }
} }
else if ( this->MemoryTester.find("purify") != std::string::npos ) else if ( this->MemoryTester.find("purify") != std::string::npos )
{ {
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY; this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
std::string outputFile = std::string outputFile;
cmSystemTools::EscapeSpaces(this->MemoryTesterOutputFile.c_str());
#ifdef _WIN32 #ifdef _WIN32
if( this->CTest->GetCTestConfiguration( if( this->CTest->GetCTestConfiguration(
"MemoryCheckSuppressionFile").size() ) "MemoryCheckSuppressionFile").size() )
@ -500,31 +504,29 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
"MemoryCheckSuppressionFile").c_str() << std::endl); "MemoryCheckSuppressionFile").c_str() << std::endl);
return false; return false;
} }
this->MemoryTesterOptions += " /FilterFiles=" + std::string filterFiles = "/FilterFiles="
cmSystemTools::EscapeSpaces(this->CTest->GetCTestConfiguration( + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
"MemoryCheckSuppressionFile").c_str()); this->MemoryTesterOptions.push_back(filterFiles);
} }
this->MemoryTesterOptions += " /SAVETEXTDATA=" + outputFile; outputFile = "/SAVETEXTDATA=";
#else #else
this->MemoryTesterOptions += " -log-file=" + outputFile; outputFile = "-log-file=";
#endif #endif
outputFile += this->MemoryTesterOutputFile;
this->MemoryTesterOptions.push_back(outputFile);
} }
else if ( this->MemoryTester.find("BC") != std::string::npos ) else if ( this->MemoryTester.find("BC") != std::string::npos )
{ {
this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile; this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile;
std::string outputFile =
cmSystemTools::EscapeSpaces(this->MemoryTesterOutputFile.c_str());
std::string dpbdFile = this->CTest->GetBinaryDir() std::string dpbdFile = this->CTest->GetBinaryDir()
+ "/Testing/Temporary/MemoryChecker.DPbd"; + "/Testing/Temporary/MemoryChecker.DPbd";
std::string errorFile = this->CTest->GetBinaryDir()
+ "/Testing/Temporary/MemoryChecker.error";
errorFile = cmSystemTools::EscapeSpaces(errorFile.c_str());
this->BoundsCheckerDPBDFile = dpbdFile; this->BoundsCheckerDPBDFile = dpbdFile;
dpbdFile = cmSystemTools::EscapeSpaces(dpbdFile.c_str());
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER; this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
this->MemoryTesterOptions += " /B " + dpbdFile; this->MemoryTesterOptions.push_back("/B");
this->MemoryTesterOptions += " /X " + outputFile; this->MemoryTesterOptions.push_back(dpbdFile);
this->MemoryTesterOptions += " /M "; this->MemoryTesterOptions.push_back("/X");
this->MemoryTesterOptions.push_back(this->MemoryTesterOutputFile);
this->MemoryTesterOptions.push_back("/M");
} }
else else
{ {
@ -534,8 +536,6 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
return false; return false;
} }
this->MemoryTesterOptionsParsed
= cmSystemTools::ParseArguments(this->MemoryTesterOptions.c_str());
std::vector<cmStdString>::size_type cc; std::vector<cmStdString>::size_type cc;
for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ ) for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
{ {

View File

@ -89,8 +89,7 @@ private:
std::string BoundsCheckerDPBDFile; std::string BoundsCheckerDPBDFile;
std::string BoundsCheckerXMLFile; std::string BoundsCheckerXMLFile;
std::string MemoryTester; std::string MemoryTester;
std::vector<cmStdString> MemoryTesterOptionsParsed; std::vector<cmStdString> MemoryTesterOptions;
std::string MemoryTesterOptions;
int MemoryTesterStyle; int MemoryTesterStyle;
std::string MemoryTesterOutputFile; std::string MemoryTesterOutputFile;
int MemoryTesterGlobalResults[NO_MEMORY_FAULT]; int MemoryTesterGlobalResults[NO_MEMORY_FAULT];

View File

@ -471,7 +471,7 @@ void cmCTestRunTest::ComputeArguments()
this->TestProperties->Args[1].c_str()); this->TestProperties->Args[1].c_str());
++j; //skip the executable (it will be actualCommand) ++j; //skip the executable (it will be actualCommand)
} }
this->TestCommand std::string testCommand
= cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str()); = cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
//Prepends memcheck args to our command string //Prepends memcheck args to our command string
@ -479,22 +479,24 @@ void cmCTestRunTest::ComputeArguments()
for(std::vector<std::string>::iterator i = this->Arguments.begin(); for(std::vector<std::string>::iterator i = this->Arguments.begin();
i != this->Arguments.end(); ++i) i != this->Arguments.end(); ++i)
{ {
this->TestCommand += " "; testCommand += " \"";
this->TestCommand += cmSystemTools::EscapeSpaces(i->c_str()); testCommand += *i;
testCommand += "\"";
} }
for(;j != this->TestProperties->Args.end(); ++j) for(;j != this->TestProperties->Args.end(); ++j)
{ {
this->TestCommand += " "; testCommand += " \"";
this->TestCommand += cmSystemTools::EscapeSpaces(j->c_str()); testCommand += *j;
testCommand += "\"";
this->Arguments.push_back(*j); this->Arguments.push_back(*j);
} }
this->TestResult.FullCommandLine = this->TestCommand; this->TestResult.FullCommandLine = testCommand;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
<< this->Index << ": " << this->Index << ": "
<< (this->TestHandler->MemCheck?"MemCheck":"Test") << (this->TestHandler->MemCheck?"MemCheck":"Test")
<< " command: " << this->TestCommand << " command: " << testCommand
<< std::endl); << std::endl);
} }

View File

@ -89,7 +89,6 @@ private:
cmCTestTestHandler::cmCTestTestResult TestResult; cmCTestTestHandler::cmCTestTestResult TestResult;
int Index; int Index;
std::string StartTime; std::string StartTime;
std::string TestCommand;
std::string ActualCommand; std::string ActualCommand;
std::vector<std::string> Arguments; std::vector<std::string> Arguments;
bool StopTimePassed; bool StopTimePassed;

View File

@ -2810,17 +2810,29 @@ cmLocalGenerator
std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str) std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
{ {
std::string result; std::string result;
bool forceOn = cmSystemTools::GetForceUnixPaths(); #if defined(_WIN32) && !defined(__CYGWIN__)
if(forceOn && this->WindowsShell) // if there are spaces
std::string temp = str;
if (temp.find(" ") != std::string::npos &&
temp.find("\"")==std::string::npos)
{ {
cmSystemTools::SetForceUnixPaths(false); result = "\"";
result += str;
result += "\"";
return result;
} }
result = cmSystemTools::EscapeSpaces(str); return str;
if(forceOn && this->WindowsShell) #else
for(const char* ch = str; *ch != '\0'; ++ch)
{ {
cmSystemTools::SetForceUnixPaths(true); if(*ch == ' ')
{
result += '\\';
}
result += *ch;
} }
return result; return result;
#endif
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -191,49 +191,6 @@ std::string cmSystemTools::EscapeQuotes(const char* str)
return result; return result;
} }
std::string cmSystemTools::EscapeSpaces(const char* str)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
bool useDoubleQ = true;
#else
bool useDoubleQ = false;
#endif
if(cmSystemTools::s_ForceUnixPaths)
{
useDoubleQ = false;
}
if(useDoubleQ)
{
std::string result;
// if there are spaces
std::string temp = str;
if (temp.find(" ") != std::string::npos &&
temp.find("\"")==std::string::npos)
{
result = "\"";
result += str;
result += "\"";
return result;
}
return str;
}
else
{
std::string result = "";
for(const char* ch = str; *ch != '\0'; ++ch)
{
if(*ch == ' ')
{
result += '\\';
}
result += *ch;
}
return result;
}
}
void cmSystemTools::Error(const char* m1, const char* m2, void cmSystemTools::Error(const char* m1, const char* m2,
const char* m3, const char* m4) const char* m3, const char* m4)
{ {

View File

@ -46,12 +46,6 @@ public:
static void ExpandRegistryValues(std::string& source, static void ExpandRegistryValues(std::string& source,
KeyWOW64 view = KeyWOW64_Default); KeyWOW64 view = KeyWOW64_Default);
/**
* Platform independent escape spaces, unix uses backslash,
* windows double quotes the string.
*/
static std::string EscapeSpaces(const char* str);
///! Escape quotes in a string. ///! Escape quotes in a string.
static std::string EscapeQuotes(const char* str); static std::string EscapeQuotes(const char* str);