cmGeneratorExpression: Port users to two-stage processing
Removing the Process() API and removing the parameters from the constructor will allow cmGeneratorExpressions to be cached and evaluated with multiple configs for example, such as when evaluating target properties. This requires the creation of a new compiled representation of cmGeneratorExpression. The cmListFileBacktrace remains in the constructor so that we can record where a particular generator expression appeared in the CMakeLists file.
This commit is contained in:
parent
f1eacf0e07
commit
91011bd217
@ -21,7 +21,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(
|
|||||||
cmCustomCommand const& cc, const char* config, cmMakefile* mf):
|
cmCustomCommand const& cc, const char* config, cmMakefile* mf):
|
||||||
CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
|
CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
|
||||||
OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
|
OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
|
||||||
GE(new cmGeneratorExpression(mf, config, cc.GetBacktrace()))
|
GE(new cmGeneratorExpression(cc.GetBacktrace()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
|
|||||||
{
|
{
|
||||||
return target->GetLocation(this->Config);
|
return target->GetLocation(this->Config);
|
||||||
}
|
}
|
||||||
return this->GE->Process(argv0);
|
return this->GE->Parse(argv0).Evaluate(this->Makefile, this->Config);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -58,7 +58,8 @@ cmCustomCommandGenerator
|
|||||||
cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
|
cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
|
||||||
for(unsigned int j=1;j < commandLine.size(); ++j)
|
for(unsigned int j=1;j < commandLine.size(); ++j)
|
||||||
{
|
{
|
||||||
std::string arg = this->GE->Process(commandLine[j]);
|
std::string arg = this->GE->Parse(commandLine[j]).Evaluate(this->Makefile,
|
||||||
|
this->Config);
|
||||||
cmd += " ";
|
cmd += " ";
|
||||||
if(this->OldStyle)
|
if(this->OldStyle)
|
||||||
{
|
{
|
||||||
|
@ -22,48 +22,50 @@
|
|||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmGeneratorExpression::cmGeneratorExpression(
|
cmGeneratorExpression::cmGeneratorExpression(
|
||||||
cmMakefile* mf, const char* config,
|
cmListFileBacktrace const& backtrace):
|
||||||
cmListFileBacktrace const& backtrace, bool quiet):
|
Backtrace(backtrace), CompiledExpression(0)
|
||||||
Makefile(mf), Config(config), Backtrace(backtrace), Quiet(quiet),
|
|
||||||
NeedsParsing(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmGeneratorExpression::Process(std::string const& input)
|
const cmCompiledGeneratorExpression &
|
||||||
|
cmGeneratorExpression::Parse(std::string const& input)
|
||||||
{
|
{
|
||||||
return this->Process(input.c_str());
|
return this->Parse(input.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmGeneratorExpression::Process(const char* input)
|
const cmCompiledGeneratorExpression &
|
||||||
|
cmGeneratorExpression::Parse(const char* input)
|
||||||
{
|
{
|
||||||
this->Parse(input);
|
|
||||||
return this->Evaluate(this->Makefile, this->Config, this->Quiet);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
void cmGeneratorExpression::Parse(const char* input)
|
|
||||||
{
|
|
||||||
this->Evaluators.clear();
|
|
||||||
|
|
||||||
this->Input = input;
|
|
||||||
cmGeneratorExpressionLexer l;
|
cmGeneratorExpressionLexer l;
|
||||||
std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(this->Input);
|
std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(input);
|
||||||
this->NeedsParsing = l.GetSawGeneratorExpression();
|
bool needsParsing = l.GetSawGeneratorExpression();
|
||||||
|
std::vector<cmGeneratorExpressionEvaluator*> evaluators;
|
||||||
|
|
||||||
if (!this->NeedsParsing)
|
if (needsParsing)
|
||||||
{
|
{
|
||||||
return;
|
cmGeneratorExpressionParser p(tokens);
|
||||||
|
p.Parse(evaluators);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmGeneratorExpressionParser p(tokens);
|
delete this->CompiledExpression;
|
||||||
p.Parse(this->Evaluators);
|
this->CompiledExpression = new cmCompiledGeneratorExpression(
|
||||||
|
this->Backtrace,
|
||||||
|
evaluators,
|
||||||
|
input,
|
||||||
|
needsParsing);
|
||||||
|
return *this->CompiledExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmGeneratorExpression::~cmGeneratorExpression()
|
||||||
|
{
|
||||||
|
delete this->CompiledExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char *cmGeneratorExpression::Evaluate(
|
const char *cmCompiledGeneratorExpression::Evaluate(
|
||||||
cmMakefile* mf, const char* config, bool quiet)
|
cmMakefile* mf, const char* config, bool quiet) const
|
||||||
{
|
{
|
||||||
if (!this->NeedsParsing)
|
if (!this->NeedsParsing)
|
||||||
{
|
{
|
||||||
@ -99,8 +101,19 @@ const char *cmGeneratorExpression::Evaluate(
|
|||||||
return this->Output.c_str();
|
return this->Output.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
|
||||||
|
cmListFileBacktrace const& backtrace,
|
||||||
|
const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
|
||||||
|
const char *input, bool needsParsing)
|
||||||
|
: Backtrace(backtrace), Evaluators(evaluators), Input(input),
|
||||||
|
NeedsParsing(needsParsing)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmGeneratorExpression::~cmGeneratorExpression()
|
cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
|
||||||
{
|
{
|
||||||
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
|
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
|
||||||
= this->Evaluators.begin();
|
= this->Evaluators.begin();
|
||||||
|
@ -21,6 +21,8 @@ class cmListFileBacktrace;
|
|||||||
|
|
||||||
struct cmGeneratorExpressionEvaluator;
|
struct cmGeneratorExpressionEvaluator;
|
||||||
|
|
||||||
|
class cmCompiledGeneratorExpression;
|
||||||
|
|
||||||
/** \class cmGeneratorExpression
|
/** \class cmGeneratorExpression
|
||||||
* \brief Evaluate generate-time query expression syntax.
|
* \brief Evaluate generate-time query expression syntax.
|
||||||
*
|
*
|
||||||
@ -33,34 +35,48 @@ struct cmGeneratorExpressionEvaluator;
|
|||||||
class cmGeneratorExpression
|
class cmGeneratorExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Construct with an evaluation context and configuration. */
|
/** Construct. */
|
||||||
cmGeneratorExpression(cmMakefile* mf, const char* config,
|
cmGeneratorExpression(cmListFileBacktrace const& backtrace);
|
||||||
cmListFileBacktrace const& backtrace,
|
|
||||||
bool quiet = false);
|
|
||||||
|
|
||||||
~cmGeneratorExpression();
|
~cmGeneratorExpression();
|
||||||
|
|
||||||
/** Evaluate generator expressions in a string. */
|
const cmCompiledGeneratorExpression& Parse(std::string const& input);
|
||||||
const char* Process(std::string const& input);
|
const cmCompiledGeneratorExpression& Parse(const char* input);
|
||||||
const char* Process(const char* input);
|
|
||||||
|
|
||||||
void Parse(const char* input);
|
private:
|
||||||
|
cmGeneratorExpression(const cmGeneratorExpression &);
|
||||||
|
void operator=(const cmGeneratorExpression &);
|
||||||
|
|
||||||
|
cmListFileBacktrace const& Backtrace;
|
||||||
|
cmCompiledGeneratorExpression *CompiledExpression;
|
||||||
|
};
|
||||||
|
|
||||||
|
class cmCompiledGeneratorExpression
|
||||||
|
{
|
||||||
|
public:
|
||||||
const char* Evaluate(cmMakefile* mf, const char* config,
|
const char* Evaluate(cmMakefile* mf, const char* config,
|
||||||
bool quiet = false);
|
bool quiet = false) const;
|
||||||
|
|
||||||
/** Get set of targets found during evaluations. */
|
/** Get set of targets found during evaluations. */
|
||||||
std::set<cmTarget*> const& GetTargets() const
|
std::set<cmTarget*> const& GetTargets() const
|
||||||
{ return this->Targets; }
|
{ return this->Targets; }
|
||||||
|
|
||||||
|
~cmCompiledGeneratorExpression();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
|
cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
|
||||||
cmMakefile* Makefile;
|
const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
|
||||||
const char* Config;
|
const char *input, bool needsParsing);
|
||||||
|
|
||||||
|
friend class cmGeneratorExpression;
|
||||||
|
|
||||||
|
cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
|
||||||
|
void operator=(const cmCompiledGeneratorExpression &);
|
||||||
|
|
||||||
cmListFileBacktrace const& Backtrace;
|
cmListFileBacktrace const& Backtrace;
|
||||||
bool Quiet;
|
const std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
|
||||||
|
const char* const Input;
|
||||||
|
const bool NeedsParsing;
|
||||||
|
|
||||||
std::set<cmTarget*> Targets;
|
mutable std::set<cmTarget*> Targets;
|
||||||
const char* Input;
|
mutable std::string Output;
|
||||||
bool NeedsParsing;
|
|
||||||
|
|
||||||
std::string Output;
|
|
||||||
};
|
};
|
||||||
|
@ -1623,7 +1623,11 @@ cmTargetTraceDependencies
|
|||||||
{
|
{
|
||||||
// Transform command names that reference targets built in this
|
// Transform command names that reference targets built in this
|
||||||
// project to corresponding target-level dependencies.
|
// project to corresponding target-level dependencies.
|
||||||
cmGeneratorExpression ge(this->Makefile, 0, cc.GetBacktrace(), true);
|
cmGeneratorExpression ge(cc.GetBacktrace());
|
||||||
|
|
||||||
|
// Add target-level dependencies referenced by generator expressions.
|
||||||
|
std::set<cmTarget*> targets;
|
||||||
|
|
||||||
for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
|
for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
|
||||||
cit != cc.GetCommandLines().end(); ++cit)
|
cit != cc.GetCommandLines().end(); ++cit)
|
||||||
{
|
{
|
||||||
@ -1645,12 +1649,17 @@ cmTargetTraceDependencies
|
|||||||
for(cmCustomCommandLine::const_iterator cli = cit->begin();
|
for(cmCustomCommandLine::const_iterator cli = cit->begin();
|
||||||
cli != cit->end(); ++cli)
|
cli != cit->end(); ++cli)
|
||||||
{
|
{
|
||||||
ge.Process(*cli);
|
const cmCompiledGeneratorExpression &cge = ge.Parse(*cli);
|
||||||
|
cge.Evaluate(this->Makefile, 0, true);
|
||||||
|
std::set<cmTarget*> geTargets = cge.GetTargets();
|
||||||
|
for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
|
||||||
|
it != geTargets.end(); ++it)
|
||||||
|
{
|
||||||
|
targets.insert(*it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add target-level dependencies referenced by generator expressions.
|
|
||||||
std::set<cmTarget*> targets = ge.GetTargets();
|
|
||||||
for(std::set<cmTarget*>::iterator ti = targets.begin();
|
for(std::set<cmTarget*>::iterator ti = targets.begin();
|
||||||
ti != targets.end(); ++ti)
|
ti != targets.end(); ++ti)
|
||||||
{
|
{
|
||||||
|
@ -91,8 +91,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
this->TestGenerated = true;
|
this->TestGenerated = true;
|
||||||
|
|
||||||
// Set up generator expression evaluation context.
|
// Set up generator expression evaluation context.
|
||||||
cmMakefile* mf = this->Test->GetMakefile();
|
cmGeneratorExpression ge(this->Test->GetBacktrace());
|
||||||
cmGeneratorExpression ge(mf, config, this->Test->GetBacktrace());
|
|
||||||
|
|
||||||
// Start the test command.
|
// Start the test command.
|
||||||
os << indent << "ADD_TEST(" << this->Test->GetName() << " ";
|
os << indent << "ADD_TEST(" << this->Test->GetName() << " ";
|
||||||
@ -103,6 +102,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
// Check whether the command executable is a target whose name is to
|
// Check whether the command executable is a target whose name is to
|
||||||
// be translated.
|
// be translated.
|
||||||
std::string exe = command[0];
|
std::string exe = command[0];
|
||||||
|
cmMakefile* mf = this->Test->GetMakefile();
|
||||||
cmTarget* target = mf->FindTargetToUse(exe.c_str());
|
cmTarget* target = mf->FindTargetToUse(exe.c_str());
|
||||||
if(target && target->GetType() == cmTarget::EXECUTABLE)
|
if(target && target->GetType() == cmTarget::EXECUTABLE)
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Use the command name given.
|
// Use the command name given.
|
||||||
exe = ge.Process(exe.c_str());
|
exe = ge.Parse(exe.c_str()).Evaluate(mf, config);
|
||||||
cmSystemTools::ConvertToUnixSlashes(exe);
|
cmSystemTools::ConvertToUnixSlashes(exe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
for(std::vector<std::string>::const_iterator ci = command.begin()+1;
|
for(std::vector<std::string>::const_iterator ci = command.begin()+1;
|
||||||
ci != command.end(); ++ci)
|
ci != command.end(); ++ci)
|
||||||
{
|
{
|
||||||
os << " " << lg->EscapeForCMake(ge.Process(*ci));
|
os << " " << lg->EscapeForCMake(ge.Parse(*ci).Evaluate(mf, config));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish the test command.
|
// Finish the test command.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user