Support for $ENV{VAR} syntax (lookup in the environment vars)
This commit is contained in:
parent
c151f30861
commit
ce4f2718f2
@ -4,6 +4,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
FIND_PATH(DART_ROOT README.INSTALL
|
FIND_PATH(DART_ROOT README.INSTALL
|
||||||
|
$ENV{DART_ROOT}
|
||||||
${PROJECT_SOURCE_DIR}/Dart
|
${PROJECT_SOURCE_DIR}/Dart
|
||||||
/usr/share/Dart
|
/usr/share/Dart
|
||||||
"C:/Program Files/Dart"
|
"C:/Program Files/Dart"
|
||||||
|
@ -837,6 +837,8 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
{
|
{
|
||||||
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
||||||
// in the m_Definitions map, if not found in the map, nothing is expanded.
|
// in the m_Definitions map, if not found in the map, nothing is expanded.
|
||||||
|
// It also supports the $ENV{VAR} syntax where VAR is looked up in
|
||||||
|
// the current environment variables.
|
||||||
|
|
||||||
// start by look for $ or @ in the string
|
// start by look for $ or @ in the string
|
||||||
std::string::size_type markerPos = source.find_first_of("$@");
|
std::string::size_type markerPos = source.find_first_of("$@");
|
||||||
@ -856,7 +858,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
// and add it to the result
|
// and add it to the result
|
||||||
result += source.substr(currentPos, markerPos - currentPos);
|
result += source.substr(currentPos, markerPos - currentPos);
|
||||||
char endVariableMarker; // what is the end of the variable @ or }
|
char endVariableMarker; // what is the end of the variable @ or }
|
||||||
int markerStartSize = 1; // size of the start marker 1 or 2
|
int markerStartSize = 1; // size of the start marker 1 or 2 or 5
|
||||||
if(source[markerPos] == '$')
|
if(source[markerPos] == '$')
|
||||||
{
|
{
|
||||||
// ${var} case
|
// ${var} case
|
||||||
@ -865,6 +867,14 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
endVariableMarker = '}';
|
endVariableMarker = '}';
|
||||||
markerStartSize = 2;
|
markerStartSize = 2;
|
||||||
}
|
}
|
||||||
|
// $ENV{var} case
|
||||||
|
else if(markerPos+4 < source.size() &&
|
||||||
|
source[markerPos+4] == '{' &&
|
||||||
|
!source.compare(markerPos+1, 3, "ENV"))
|
||||||
|
{
|
||||||
|
endVariableMarker = '}';
|
||||||
|
markerStartSize = 5;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// bogus $ with no { so add $ to result and move on
|
// bogus $ with no { so add $ to result and move on
|
||||||
@ -878,7 +888,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
// @VAR case
|
// @VAR case
|
||||||
endVariableMarker = '@';
|
endVariableMarker = '@';
|
||||||
}
|
}
|
||||||
// if it was a valid variable (started with @ or ${ )
|
// if it was a valid variable (started with @ or ${ or $ENV{ )
|
||||||
if(endVariableMarker != ' ')
|
if(endVariableMarker != ' ')
|
||||||
{
|
{
|
||||||
markerPos += markerStartSize; // move past marker
|
markerPos += markerStartSize; // move past marker
|
||||||
@ -894,7 +904,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result += "${";
|
result += (markerStartSize == 5 ? "$ENV{" : "${");
|
||||||
}
|
}
|
||||||
currentPos = markerPos;
|
currentPos = markerPos;
|
||||||
}
|
}
|
||||||
@ -902,20 +912,41 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
{
|
{
|
||||||
// good variable remove it
|
// good variable remove it
|
||||||
std::string var = source.substr(markerPos, endVariablePos - markerPos);
|
std::string var = source.substr(markerPos, endVariablePos - markerPos);
|
||||||
DefinitionMap::const_iterator pos = m_Definitions.find(var.c_str());
|
bool found = false;
|
||||||
// if found add to result, if not, then it gets blanked
|
if (markerStartSize == 5) // $ENV{
|
||||||
if(pos != m_Definitions.end())
|
|
||||||
{
|
{
|
||||||
if (escapeQuotes)
|
char *ptr = getenv(var.c_str());
|
||||||
|
if (ptr)
|
||||||
{
|
{
|
||||||
result += cmSystemTools::EscapeQuotes((*pos).second.c_str());
|
if (escapeQuotes)
|
||||||
}
|
{
|
||||||
else
|
result += cmSystemTools::EscapeQuotes(ptr);
|
||||||
{
|
}
|
||||||
result += (*pos).second;
|
else
|
||||||
|
{
|
||||||
|
result += ptr;
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
DefinitionMap::const_iterator pos = m_Definitions.find(var.c_str());
|
||||||
|
if(pos != m_Definitions.end())
|
||||||
|
{
|
||||||
|
if (escapeQuotes)
|
||||||
|
{
|
||||||
|
result += cmSystemTools::EscapeQuotes((*pos).second.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += (*pos).second;
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if found add to result, if not, then it gets blanked
|
||||||
|
if (!found)
|
||||||
{
|
{
|
||||||
// if no definition is found then add the var back
|
// if no definition is found then add the var back
|
||||||
if(endVariableMarker == '@')
|
if(endVariableMarker == '@')
|
||||||
@ -926,7 +957,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result += "${";
|
result += (markerStartSize == 5 ? "$ENV{" : "${");
|
||||||
result += var;
|
result += var;
|
||||||
result += "}";
|
result += "}";
|
||||||
}
|
}
|
||||||
@ -944,11 +975,18 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
void cmMakefile::RemoveVariablesInString(std::string& source) const
|
void cmMakefile::RemoveVariablesInString(std::string& source) const
|
||||||
{
|
{
|
||||||
cmRegularExpression var("(\\${[A-Za-z_0-9]*})");
|
cmRegularExpression var("(\\${[A-Za-z_0-9]*})");
|
||||||
cmRegularExpression var2("(@[A-Za-z_0-9]*@)");
|
|
||||||
while (var.find(source))
|
while (var.find(source))
|
||||||
{
|
{
|
||||||
source.erase(var.start(),var.end() - var.start());
|
source.erase(var.start(),var.end() - var.start());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmRegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
|
||||||
|
while (varb.find(source))
|
||||||
|
{
|
||||||
|
source.erase(varb.start(),varb.end() - varb.start());
|
||||||
|
}
|
||||||
|
|
||||||
|
cmRegularExpression var2("(@[A-Za-z_0-9]*@)");
|
||||||
while (var2.find(source))
|
while (var2.find(source))
|
||||||
{
|
{
|
||||||
source.erase(var2.start(),var2.end() - var2.start());
|
source.erase(var2.start(),var2.end() - var2.start());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user