From 076760a63c665dd2269c74d415e323f55969f544 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 23 May 2015 20:32:05 +0200 Subject: 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. --- Source/cmFunctionCommand.cxx | 3 ++- Source/cmMacroCommand.cxx | 3 ++- Source/cmMakefile.cxx | 29 +++++++++++++++++++++++------ Source/cmMakefile.h | 8 ++++++-- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 848cfd1..662f77d 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -215,7 +215,8 @@ ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf) if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endfunction")) { std::vector expandedArguments; - mf.ExpandArguments(lff.Arguments, expandedArguments); + mf.ExpandArguments(lff.Arguments, expandedArguments, + this->GetStartingContext().FilePath.c_str()); // if the endfunction has arguments then make sure // they match the ones in the opening function command if ((expandedArguments.empty() || diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 7793dc4..c3e67d7 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -251,7 +251,8 @@ ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf) if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endmacro")) { std::vector expandedArguments; - mf.ExpandArguments(lff.Arguments, expandedArguments); + mf.ExpandArguments(lff.Arguments, expandedArguments, + this->GetStartingContext().FilePath.c_str()); // if the endmacro has arguments make sure they // match the arguments of the macro if ((expandedArguments.empty() || diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 63dbe27..72aa74c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3313,11 +3313,25 @@ bool cmMakefile::IsLoopBlock() const 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( std::vector const& inArgs, - std::vector& outArgs) const + std::vector& outArgs, const char* filename) const { + std::string efp = this->GetExecutionFilePath(); + if (!filename) + { + filename = efp.c_str(); + } std::vector::const_iterator i; std::string value; outArgs.reserve(inArgs.size()); @@ -3332,8 +3346,7 @@ bool cmMakefile::ExpandArguments( // Expand the variables in the argument. value = i->Value; this->ExpandVariablesInString(value, false, false, false, - i->FilePath, i->Line, - false, false); + filename, i->Line, false, false); // If the argument is quoted, it should be one argument. // Otherwise, it may be a list of arguments. @@ -3352,8 +3365,13 @@ bool cmMakefile::ExpandArguments( //---------------------------------------------------------------------------- bool cmMakefile::ExpandArguments( std::vector const& inArgs, - std::vector& outArgs) const + std::vector& outArgs, const char* filename) const { + std::string efp = this->GetExecutionFilePath(); + if (!filename) + { + filename = efp.c_str(); + } std::vector::const_iterator i; std::string value; outArgs.reserve(inArgs.size()); @@ -3368,8 +3386,7 @@ bool cmMakefile::ExpandArguments( // Expand the variables in the argument. value = i->Value; this->ExpandVariablesInString(value, false, false, false, - i->FilePath, i->Line, - false, false); + filename, i->Line, false, false); // If the argument is quoted, it should be one argument. // Otherwise, it may be a list of arguments. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 86bde0c..8930b6d 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -662,10 +662,12 @@ public: * variable replacement and list expansion. */ bool ExpandArguments(std::vector const& inArgs, - std::vector& outArgs) const; + std::vector& outArgs, + const char* filename = 0) const; bool ExpandArguments(std::vector const& inArgs, - std::vector& outArgs) const; + std::vector& outArgs, + const char* filename = 0) const; /** * Get the instance @@ -840,6 +842,8 @@ public: const char* GetDefineFlagsCMP0059() const; + std::string GetExecutionFilePath() const; + protected: // add link libraries and directories to the target void AddGlobalLinkInformation(const std::string& name, cmTarget& target); -- cgit v0.12