cmMakefile: Add filename context to ExpandArguments.

The cmListFileArgument currently stores a FilePath for use in this
method.  The filename is the same as the CMAKE_CURRENT_LIST_FILE,
except if executing a macro or function defined in another file.

Set the context filename when expanding the arguments of macros and
functions using the filename recorded when defining the prototype.
This commit is contained in:
Stephen Kelly 2015-05-23 20:32:05 +02:00
parent 569f478537
commit 076760a63c
4 changed files with 33 additions and 10 deletions

View File

@ -215,7 +215,8 @@ ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf)
if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endfunction")) if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endfunction"))
{ {
std::vector<std::string> expandedArguments; std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.Arguments, expandedArguments); mf.ExpandArguments(lff.Arguments, expandedArguments,
this->GetStartingContext().FilePath.c_str());
// if the endfunction has arguments then make sure // if the endfunction has arguments then make sure
// they match the ones in the opening function command // they match the ones in the opening function command
if ((expandedArguments.empty() || if ((expandedArguments.empty() ||

View File

@ -251,7 +251,8 @@ ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf)
if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endmacro")) if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endmacro"))
{ {
std::vector<std::string> expandedArguments; std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.Arguments, expandedArguments); mf.ExpandArguments(lff.Arguments, expandedArguments,
this->GetStartingContext().FilePath.c_str());
// if the endmacro has arguments make sure they // if the endmacro has arguments make sure they
// match the arguments of the macro // match the arguments of the macro
if ((expandedArguments.empty() || if ((expandedArguments.empty() ||

View File

@ -3313,11 +3313,25 @@ bool cmMakefile::IsLoopBlock() const
return !this->LoopBlockCounter.empty() && this->LoopBlockCounter.top() > 0; return !this->LoopBlockCounter.empty() && this->LoopBlockCounter.top() > 0;
} }
std::string cmMakefile::GetExecutionFilePath() const
{
if (this->CallStack.empty())
{
return std::string();
}
return this->CallStack.back().Context->FilePath;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmMakefile::ExpandArguments( bool cmMakefile::ExpandArguments(
std::vector<cmListFileArgument> const& inArgs, std::vector<cmListFileArgument> const& inArgs,
std::vector<std::string>& outArgs) const std::vector<std::string>& outArgs, const char* filename) const
{ {
std::string efp = this->GetExecutionFilePath();
if (!filename)
{
filename = efp.c_str();
}
std::vector<cmListFileArgument>::const_iterator i; std::vector<cmListFileArgument>::const_iterator i;
std::string value; std::string value;
outArgs.reserve(inArgs.size()); outArgs.reserve(inArgs.size());
@ -3332,8 +3346,7 @@ bool cmMakefile::ExpandArguments(
// Expand the variables in the argument. // Expand the variables in the argument.
value = i->Value; value = i->Value;
this->ExpandVariablesInString(value, false, false, false, this->ExpandVariablesInString(value, false, false, false,
i->FilePath, i->Line, filename, i->Line, false, false);
false, false);
// If the argument is quoted, it should be one argument. // If the argument is quoted, it should be one argument.
// Otherwise, it may be a list of arguments. // Otherwise, it may be a list of arguments.
@ -3352,8 +3365,13 @@ bool cmMakefile::ExpandArguments(
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmMakefile::ExpandArguments( bool cmMakefile::ExpandArguments(
std::vector<cmListFileArgument> const& inArgs, std::vector<cmListFileArgument> const& inArgs,
std::vector<cmExpandedCommandArgument>& outArgs) const std::vector<cmExpandedCommandArgument>& outArgs, const char* filename) const
{ {
std::string efp = this->GetExecutionFilePath();
if (!filename)
{
filename = efp.c_str();
}
std::vector<cmListFileArgument>::const_iterator i; std::vector<cmListFileArgument>::const_iterator i;
std::string value; std::string value;
outArgs.reserve(inArgs.size()); outArgs.reserve(inArgs.size());
@ -3368,8 +3386,7 @@ bool cmMakefile::ExpandArguments(
// Expand the variables in the argument. // Expand the variables in the argument.
value = i->Value; value = i->Value;
this->ExpandVariablesInString(value, false, false, false, this->ExpandVariablesInString(value, false, false, false,
i->FilePath, i->Line, filename, i->Line, false, false);
false, false);
// If the argument is quoted, it should be one argument. // If the argument is quoted, it should be one argument.
// Otherwise, it may be a list of arguments. // Otherwise, it may be a list of arguments.

View File

@ -662,10 +662,12 @@ public:
* variable replacement and list expansion. * variable replacement and list expansion.
*/ */
bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs, bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
std::vector<std::string>& outArgs) const; std::vector<std::string>& outArgs,
const char* filename = 0) const;
bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs, bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
std::vector<cmExpandedCommandArgument>& outArgs) const; std::vector<cmExpandedCommandArgument>& outArgs,
const char* filename = 0) const;
/** /**
* Get the instance * Get the instance
@ -840,6 +842,8 @@ public:
const char* GetDefineFlagsCMP0059() const; const char* GetDefineFlagsCMP0059() const;
std::string GetExecutionFilePath() const;
protected: protected:
// add link libraries and directories to the target // add link libraries and directories to the target
void AddGlobalLinkInformation(const std::string& name, cmTarget& target); void AddGlobalLinkInformation(const std::string& name, cmTarget& target);