summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2004-10-25 15:59:50 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2004-10-25 15:59:50 (GMT)
commit7ed631311c2b85eb927f22b01ed29619d957f132 (patch)
tree28d2d4251e7402e15145b479046d68e3ca6d0148
parenta3ce1fb293da2f5d5abb54bfbfa9afb35b238955 (diff)
downloadCMake-7ed631311c2b85eb927f22b01ed29619d957f132.zip
CMake-7ed631311c2b85eb927f22b01ed29619d957f132.tar.gz
CMake-7ed631311c2b85eb927f22b01ed29619d957f132.tar.bz2
FIX: fix RunSingleCommand to work with spaces in the path, and with an already quoted command
-rw-r--r--Source/cmSystemTools.cxx44
-rw-r--r--Tests/LoadCommand/LoadedCommand.cxx6
-rw-r--r--Tests/LoadCommandOneConfig/LoadedCommand.cxx6
3 files changed, 46 insertions, 10 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 26ebdca..b235b8c 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -427,26 +427,54 @@ bool cmSystemTools::RunSingleCommand(
verbose = false;
}
- std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
-
- if(args.size() < 1)
+ std::string program; // store name of program must be in scope function as it
+ // is put into argv list as a cont char*
+ std::vector<cmStdString> args; // store the program and args program is args[0]
+ std::vector<const char*> argv; // store args in a format so that process cmsysProcess can use it
+ // check to see if the command contains a double quoted string at the start
+ // if so, then just use parse arguments to split things up
+ if(command && *command == '\"')
{
- return false;
+ args = cmSystemTools::ParseArguments(command);
}
-
- std::vector<const char*> argv;
+ else
+ {
+ std::string argsTemp; // Store the arguments to the program
+ cmSystemTools::SplitProgramFromArgs(command, program, argsTemp);
+ // if there is no program to run then return false
+ if(program.size() < 1)
+ {
+ // check for a bad call to SplitProgramFromArgs
+ if(strlen(command) >= 1)
+ {
+ cmSystemTools::Error("Error in SplitProgramFromArgs for: ", command);
+ }
+ return false;
+ }
+ argv.push_back(program.c_str()); // put program in as argv[0]
+ if(argsTemp.size())
+ {
+ args = cmSystemTools::ParseArguments(argsTemp.c_str());
+ }
+ }
+ // copy args into argv
for(std::vector<cmStdString>::const_iterator a = args.begin();
a != args.end(); ++a)
{
argv.push_back(a->c_str());
}
+ // null terminate array
argv.push_back(0);
-
+ // if the only argument is null then there is nothing to run and return false
+ if(!argv[0])
+ {
+ return false;
+ }
+
if ( output )
{
*output = "";
}
-
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetWorkingDirectory(cp, dir);
diff --git a/Tests/LoadCommand/LoadedCommand.cxx b/Tests/LoadCommand/LoadedCommand.cxx
index 8c125f0..04daff0 100644
--- a/Tests/LoadCommand/LoadedCommand.cxx
+++ b/Tests/LoadCommand/LoadedCommand.cxx
@@ -17,7 +17,11 @@ int main ()
printf("Should have ADDED_DEFINITION defined\n");
return 1;
#endif
-
+ if(SIZEOF_CHAR != 1)
+ {
+ printf("Size of char is not one, something is broken\n");
+ }
+
#ifdef CMAKE_IS_FUN
return SIZEOF_CHAR-1;
#else
diff --git a/Tests/LoadCommandOneConfig/LoadedCommand.cxx b/Tests/LoadCommandOneConfig/LoadedCommand.cxx
index 8c125f0..04daff0 100644
--- a/Tests/LoadCommandOneConfig/LoadedCommand.cxx
+++ b/Tests/LoadCommandOneConfig/LoadedCommand.cxx
@@ -17,7 +17,11 @@ int main ()
printf("Should have ADDED_DEFINITION defined\n");
return 1;
#endif
-
+ if(SIZEOF_CHAR != 1)
+ {
+ printf("Size of char is not one, something is broken\n");
+ }
+
#ifdef CMAKE_IS_FUN
return SIZEOF_CHAR-1;
#else