summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2007-06-06 20:20:02 (GMT)
committerBrad King <brad.king@kitware.com>2007-06-06 20:20:02 (GMT)
commitdb0f26e85264b47dabaa1d400ad2fec1eb848eac (patch)
tree9a1077fe904c820fa6ec3a4bb7af33a18ce03714 /Source/cmMakefile.cxx
parentd016b69af3304965f4ce7fd1953e9901def528a4 (diff)
downloadCMake-db0f26e85264b47dabaa1d400ad2fec1eb848eac.zip
CMake-db0f26e85264b47dabaa1d400ad2fec1eb848eac.tar.gz
CMake-db0f26e85264b47dabaa1d400ad2fec1eb848eac.tar.bz2
BUG: Fixed @ONLY configuration to not try to parse ${} syntax at all. This fixes the original fix to bug#4393 and adds a test.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx60
1 files changed, 56 insertions, 4 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 38b6d1f..30a0b7b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -87,7 +87,7 @@ cmMakefile::cmMakefile()
this->AddDefaultDefinitions();
this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
-
+ this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
this->PreOrder = false;
}
@@ -1745,7 +1745,7 @@ std::vector<std::string> cmMakefile
}
-const char *cmMakefile::ExpandVariablesInString(std::string& source) const
+const char *cmMakefile::ExpandVariablesInString(std::string& source)
{
return this->ExpandVariablesInString(source, false, false);
}
@@ -1757,12 +1757,65 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source,
const char* filename,
long line,
bool removeEmpty,
- bool replaceAt) const
+ bool replaceAt)
{
if ( source.empty() || source.find_first_of("$@\\") == source.npos)
{
return source.c_str();
}
+
+ // Special-case the @ONLY mode.
+ if(atOnly)
+ {
+ if(!noEscapes || !removeEmpty || !replaceAt)
+ {
+ // This case should never be called. At-only is for
+ // configure-file/string which always does no escapes.
+ abort();
+ }
+
+ // Store an original copy of the input.
+ std::string input = source;
+
+ // Start with empty output.
+ source = "";
+
+ // Look for one @VAR@ at a time.
+ const char* in = input.c_str();
+ while(this->cmAtVarRegex.find(in))
+ {
+ // Get the range of the string to replace.
+ const char* first = in + this->cmAtVarRegex.start();
+ const char* last = in + this->cmAtVarRegex.end();
+
+ // Store the unchanged part of the string now.
+ source.append(in, first-in);
+
+ // Lookup the definition of VAR.
+ std::string var(first+1, last-first-2);
+ if(const char* val = this->GetDefinition(var.c_str()))
+ {
+ // Store the value in the output escaping as requested.
+ if(escapeQuotes)
+ {
+ source.append(cmSystemTools::EscapeQuotes(val));
+ }
+ else
+ {
+ source.append(val);
+ }
+ }
+
+ // Continue looking for @VAR@ further along the string.
+ in = last;
+ }
+
+ // Append the rest of the unchanged part of the string.
+ source.append(in);
+
+ return source.c_str();
+ }
+
// This method replaces ${VAR} and @VAR@ where VAR is looked up
// with GetDefinition(), if not found in the map, nothing is expanded.
// It also supports the $ENV{VAR} syntax where VAR is looked up in
@@ -1775,7 +1828,6 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source,
parser.SetNoEscapeMode(noEscapes);
parser.SetReplaceAtSyntax(replaceAt);
parser.SetRemoveEmpty(removeEmpty);
- parser.SetAtOnly(atOnly);
int res = parser.ParseString(source.c_str(), 0);
if ( res )
{