[cmake-commits] king committed cmCustomCommand.cxx 1.17 1.18
cmCustomCommand.h 1.17 1.18 cmGlobalXCodeGenerator.cxx 1.121
1.122 cmLocalGenerator.cxx 1.151 1.152 cmLocalGenerator.h 1.64
1.65 cmLocalUnixMakefileGenerator3.cxx 1.175 1.176
cmLocalVisualStudio6Generator.cxx 1.104 1.105
cmLocalVisualStudio7Generator.cxx 1.146 1.147
cmLocalVisualStudioGenerator.cxx 1.6 1.7
cmLocalVisualStudioGenerator.h 1.3 1.4
cmake-commits at cmake.org
cmake-commits at cmake.org
Wed Sep 27 13:43:48 EDT 2006
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv23716
Modified Files:
cmCustomCommand.cxx cmCustomCommand.h
cmGlobalXCodeGenerator.cxx cmLocalGenerator.cxx
cmLocalGenerator.h cmLocalUnixMakefileGenerator3.cxx
cmLocalVisualStudio6Generator.cxx
cmLocalVisualStudio7Generator.cxx
cmLocalVisualStudioGenerator.cxx
cmLocalVisualStudioGenerator.h
Log Message:
ENH: Re-implemented command line argument shell quoting to support several platforms with one code base.
Index: cmLocalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.cxx,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- cmLocalVisualStudio7Generator.cxx 21 Sep 2006 19:14:06 -0000 1.146
+++ cmLocalVisualStudio7Generator.cxx 27 Sep 2006 17:43:45 -0000 1.147
@@ -1184,7 +1184,9 @@
// Construct the entire set of commands in one string.
std::string script =
this->ConstructScript(command->GetCommandLines(),
- command->GetWorkingDirectory());
+ command->GetWorkingDirectory(),
+ command->GetEscapeOldStyle(),
+ command->GetEscapeAllowMakeVars());
std::string comment = this->ConstructComment(*command);
const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
this->WriteCustomRule(fout, source.c_str(), script.c_str(),
@@ -1391,8 +1393,11 @@
fout << "\nCommandLine=\"";
init = true;
}
- std::string script =
- this->ConstructScript(cr->GetCommandLines(), cr->GetWorkingDirectory());
+ std::string script =
+ this->ConstructScript(cr->GetCommandLines(),
+ cr->GetWorkingDirectory(),
+ cr->GetEscapeOldStyle(),
+ cr->GetEscapeAllowMakeVars());
fout << this->EscapeForXML(script.c_str()).c_str();
}
if (init)
@@ -1413,8 +1418,11 @@
fout << "\nCommandLine=\"";
init = true;
}
- std::string script = this->ConstructScript(cr->GetCommandLines(),
- cr->GetWorkingDirectory());
+ std::string script =
+ this->ConstructScript(cr->GetCommandLines(),
+ cr->GetWorkingDirectory(),
+ cr->GetEscapeOldStyle(),
+ cr->GetEscapeAllowMakeVars());
fout << this->EscapeForXML(script.c_str()).c_str();
}
if (init)
@@ -1435,8 +1443,11 @@
fout << "\nCommandLine=\"";
init = true;
}
- std::string script =
- this->ConstructScript(cr->GetCommandLines(), cr->GetWorkingDirectory());
+ std::string script =
+ this->ConstructScript(cr->GetCommandLines(),
+ cr->GetWorkingDirectory(),
+ cr->GetEscapeOldStyle(),
+ cr->GetEscapeAllowMakeVars());
fout << this->EscapeForXML(script.c_str()).c_str();
}
if (init)
Index: cmLocalVisualStudioGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudioGenerator.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cmLocalVisualStudioGenerator.cxx 21 Sep 2006 19:14:06 -0000 1.6
+++ cmLocalVisualStudioGenerator.cxx 27 Sep 2006 17:43:46 -0000 1.7
@@ -24,6 +24,7 @@
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator()
{
this->WindowsShell = true;
+ this->WindowsVSIDE = true;
}
//----------------------------------------------------------------------------
@@ -110,6 +111,8 @@
cmLocalVisualStudioGenerator
::ConstructScript(const cmCustomCommandLines& commandLines,
const char* workingDirectory,
+ bool escapeOldStyle,
+ bool escapeAllowMakeVars,
const char* newline)
{
// Store the script in a string.
@@ -146,7 +149,15 @@
for(unsigned int j=1;j < commandLine.size(); ++j)
{
script += " ";
- script += this->EscapeForShell(commandLine[j].c_str());
+ if(escapeOldStyle)
+ {
+ script += this->EscapeForShellOldStyle(commandLine[j].c_str());
+ }
+ else
+ {
+ script += this->EscapeForShell(commandLine[j].c_str(),
+ escapeAllowMakeVars);
+ }
}
// End the line.
Index: cmLocalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- cmLocalGenerator.h 21 Sep 2006 20:10:47 -0000 1.64
+++ cmLocalGenerator.h 27 Sep 2006 17:43:45 -0000 1.65
@@ -202,8 +202,12 @@
};
/** Escape the given string to be used as a command line argument in
- the native build system shell. */
- std::string EscapeForShell(const char* str);
+ the native build system shell. Optionally allow the build
+ system to replace make variable references. */
+ std::string EscapeForShell(const char* str, bool makeVars = false);
+
+ /** Backwards-compatibility version of EscapeForShell. */
+ std::string EscapeForShellOldStyle(const char* str);
protected:
@@ -267,6 +271,7 @@
std::map<cmStdString, cmStdString> LanguageToIncludeFlags;
std::map<cmStdString, cmStdString> UniqueObjectNamesMap;
bool WindowsShell;
+ bool WindowsVSIDE;
bool ForceUnixPath;
bool UseRelativePaths;
bool IgnoreLibPrefix;
Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.151
retrieving revision 1.152
diff -u -d -r1.151 -r1.152
--- cmLocalGenerator.cxx 25 Sep 2006 14:22:47 -0000 1.151
+++ cmLocalGenerator.cxx 27 Sep 2006 17:43:45 -0000 1.152
@@ -39,6 +39,7 @@
this->ExcludeFromAll = false;
this->Parent = 0;
this->WindowsShell = false;
+ this->WindowsVSIDE = false;
this->IgnoreLibPrefix = false;
this->UseRelativePaths = false;
this->Configured = false;
@@ -2243,12 +2244,9 @@
}
//----------------------------------------------------------------------------
-std::string cmLocalGenerator::EscapeForShell(const char* str)
+std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
{
std::string result;
- // Temporarily use old shell escaping code until a means of backward
- // compatibility can be established in the new implementation.
-#if 1
bool forceOn = cmSystemTools::GetForceUnixPaths();
if(forceOn && this->WindowsShell)
{
@@ -2259,25 +2257,41 @@
{
cmSystemTools::SetForceUnixPaths(true);
}
-#else
+ return result;
+}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars)
+{
+ // Compute the flags for the target shell environment.
+ int flags = 0;
+ if(this->WindowsVSIDE)
+ {
+ flags |= cmsysSystem_Shell_Flag_VSIDE;
+ }
+ else
+ {
+ flags |= cmsysSystem_Shell_Flag_Make;
+ }
+ if(makeVars)
+ {
+ flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
+ }
+
+ // Compute the buffer size needed.
+ int size = (this->WindowsShell ?
+ cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
+ cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
+
+ // Compute the shell argument itself.
+ std::vector<char> arg(size);
if(this->WindowsShell)
{
- int size = cmsysSystem_Windows_ShellArgumentSize(str);
- std::vector<char> arg(size);
- cmsysSystem_Windows_ShellArgument(str, &arg[0]);
- result = &arg[0];
+ cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
}
else
{
- for(const char* c = str; *c; ++c)
- {
- if(*c == '\\' || *c == '\'' || *c == '"' || *c == ';' || *c == ' ')
- {
- result += "\\";
- }
- result += *c;
- }
+ cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
}
-#endif
- return result;
+ return std::string(&arg[0]);
}
Index: cmGlobalXCodeGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.cxx,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- cmGlobalXCodeGenerator.cxx 21 Sep 2006 20:10:47 -0000 1.121
+++ cmGlobalXCodeGenerator.cxx 27 Sep 2006 17:43:45 -0000 1.122
@@ -962,7 +962,8 @@
cmCustomCommand const& cc = *i;
if(!cc.GetCommandLines().empty())
{
-
+ bool escapeOldStyle = cc.GetEscapeOldStyle();
+ bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
makefileStream << "\n#" << "Custom command rule: " <<
cc.GetComment() << "\n";
const std::vector<std::string>& outputs = cc.GetOutputs();
@@ -1037,8 +1038,17 @@
for(unsigned int j=1; j < commandLine.size(); ++j)
{
cmd += " ";
- cmd += (this->CurrentLocalGenerator
- ->EscapeForShell(commandLine[j].c_str()));
+ if(escapeOldStyle)
+ {
+ cmd += (this->CurrentLocalGenerator
+ ->EscapeForShellOldStyle(commandLine[j].c_str()));
+ }
+ else
+ {
+ cmd += (this->CurrentLocalGenerator->
+ EscapeForShell(commandLine[j].c_str(),
+ escapeAllowMakeVars));
+ }
}
makefileStream << "\t" << cmd.c_str() << "\n";
}
Index: cmLocalVisualStudio6Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio6Generator.cxx,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- cmLocalVisualStudio6Generator.cxx 21 Sep 2006 19:14:06 -0000 1.104
+++ cmLocalVisualStudio6Generator.cxx 27 Sep 2006 17:43:45 -0000 1.105
@@ -461,6 +461,8 @@
std::string script =
this->ConstructScript(command->GetCommandLines(),
command->GetWorkingDirectory(),
+ command->GetEscapeOldStyle(),
+ command->GetEscapeAllowMakeVars(),
"\\\n\t");
std::string comment =
this->ConstructComment(*command,
@@ -775,6 +777,8 @@
}
customRuleCode += this->ConstructScript(cr->GetCommandLines(),
cr->GetWorkingDirectory(),
+ cr->GetEscapeOldStyle(),
+ cr->GetEscapeAllowMakeVars(),
prelink_newline);
}
for (std::vector<cmCustomCommand>::const_iterator cr =
@@ -787,6 +791,8 @@
}
customRuleCode += this->ConstructScript(cr->GetCommandLines(),
cr->GetWorkingDirectory(),
+ cr->GetEscapeOldStyle(),
+ cr->GetEscapeAllowMakeVars(),
prelink_newline);
}
if(prelink_total > 0)
@@ -814,6 +820,8 @@
}
customRuleCode += this->ConstructScript(cr->GetCommandLines(),
cr->GetWorkingDirectory(),
+ cr->GetEscapeOldStyle(),
+ cr->GetEscapeAllowMakeVars(),
postbuild_newline);
}
if(postbuild_total > 0)
Index: cmLocalVisualStudioGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudioGenerator.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmLocalVisualStudioGenerator.h 21 Sep 2006 19:14:06 -0000 1.3
+++ cmLocalVisualStudioGenerator.h 27 Sep 2006 17:43:46 -0000 1.4
@@ -39,6 +39,8 @@
/** Construct a script from the given list of command lines. */
std::string ConstructScript(const cmCustomCommandLines& commandLines,
const char* workingDirectory,
+ bool escapeOldStyle,
+ bool escapeAllowMakeVars,
const char* newline = "\n");
// Safe object file name generation.
Index: cmCustomCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCustomCommand.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmCustomCommand.cxx 11 Apr 2006 15:06:18 -0000 1.17
+++ cmCustomCommand.cxx 27 Sep 2006 17:43:45 -0000 1.18
@@ -19,6 +19,8 @@
//----------------------------------------------------------------------------
cmCustomCommand::cmCustomCommand()
{
+ this->EscapeOldStyle = true;
+ this->EscapeAllowMakeVars = false;
this->Used = false;
}
@@ -30,6 +32,8 @@
Comment(r.Comment),
WorkingDirectory(r.WorkingDirectory)
{
+ this->EscapeOldStyle = true;
+ this->EscapeAllowMakeVars = false;
this->Used = false;
}
@@ -45,6 +49,8 @@
Comment(comment?comment:""),
WorkingDirectory(workingDirectory?workingDirectory:"")
{
+ this->EscapeOldStyle = true;
+ this->EscapeAllowMakeVars = false;
this->Used = false;
}
@@ -81,3 +87,27 @@
{
return this->Comment.c_str();
}
+
+//----------------------------------------------------------------------------
+bool cmCustomCommand::GetEscapeOldStyle() const
+{
+ return this->EscapeOldStyle;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::SetEscapeOldStyle(bool b)
+{
+ this->EscapeOldStyle = b;
+}
+
+//----------------------------------------------------------------------------
+bool cmCustomCommand::GetEscapeAllowMakeVars() const
+{
+ return this->EscapeAllowMakeVars;
+}
+
+//----------------------------------------------------------------------------
+void cmCustomCommand::SetEscapeAllowMakeVars(bool b)
+{
+ this->EscapeAllowMakeVars = b;
+}
Index: cmCustomCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCustomCommand.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmCustomCommand.h 11 Apr 2006 15:06:18 -0000 1.17
+++ cmCustomCommand.h 27 Sep 2006 17:43:45 -0000 1.18
@@ -53,6 +53,15 @@
/** Get the comment string for the command. */
const char* GetComment() const;
+ /** Set/Get whether old-style escaping should be used. */
+ bool GetEscapeOldStyle() const;
+ void SetEscapeOldStyle(bool b);
+
+ /** Set/Get whether the build tool can replace variables in
+ arguments to the command. */
+ bool GetEscapeAllowMakeVars() const;
+ void SetEscapeAllowMakeVars(bool b);
+
/** set get the used status of the command */
void SetUsed() { this->Used = true;};
bool IsUsed() { return this->Used;};
@@ -63,6 +72,8 @@
cmCustomCommandLines CommandLines;
std::string Comment;
std::string WorkingDirectory;
+ bool EscapeAllowMakeVars;
+ bool EscapeOldStyle;
bool Used;
};
Index: cmLocalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.cxx,v
retrieving revision 1.175
retrieving revision 1.176
diff -u -d -r1.175 -r1.176
--- cmLocalUnixMakefileGenerator3.cxx 21 Sep 2006 21:21:13 -0000 1.175
+++ cmLocalUnixMakefileGenerator3.cxx 27 Sep 2006 17:43:45 -0000 1.176
@@ -899,6 +899,8 @@
{
dir = workingDir;
}
+ bool escapeOldStyle = cc.GetEscapeOldStyle();
+ bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
// Add each command line to the set of commands.
std::vector<std::string> commands1;
@@ -927,7 +929,15 @@
for(unsigned int j=1; j < commandLine.size(); ++j)
{
cmd += " ";
- cmd += this->EscapeForShell(commandLine[j].c_str());
+ if(escapeOldStyle)
+ {
+ cmd += this->EscapeForShellOldStyle(commandLine[j].c_str());
+ }
+ else
+ {
+ cmd += this->EscapeForShell(commandLine[j].c_str(),
+ escapeAllowMakeVars);
+ }
}
commands1.push_back(cmd);
}
More information about the Cmake-commits
mailing list