cmCustomCommandGenerator: Require cmLocalGenerator in API.

This commit is contained in:
Stephen Kelly 2015-07-25 17:52:10 +02:00
parent 26d1a9d356
commit d568eefe10
13 changed files with 36 additions and 32 deletions

View File

@ -12,14 +12,15 @@
#include "cmCustomCommandGenerator.h" #include "cmCustomCommandGenerator.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmLocalGenerator.h"
#include "cmCustomCommand.h" #include "cmCustomCommand.h"
#include "cmOutputConverter.h" #include "cmOutputConverter.h"
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmCustomCommandGenerator::cmCustomCommandGenerator( cmCustomCommandGenerator::cmCustomCommandGenerator(
cmCustomCommand const& cc, const std::string& config, cmMakefile* mf): cmCustomCommand const& cc, const std::string& config, cmLocalGenerator* lg):
CC(cc), Config(config), Makefile(mf), CC(cc), Config(config), LG(lg),
OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()), OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
GE(new cmGeneratorExpression(cc.GetBacktrace())), DependsDone(false) GE(new cmGeneratorExpression(cc.GetBacktrace())), DependsDone(false)
{ {
@ -41,13 +42,15 @@ unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
{ {
std::string const& argv0 = this->CC.GetCommandLines()[c][0]; std::string const& argv0 = this->CC.GetCommandLines()[c][0];
cmTarget* target = this->Makefile->FindTargetToUse(argv0); cmTarget* target = this->LG->GetMakefile()->FindTargetToUse(argv0);
if(target && target->GetType() == cmTarget::EXECUTABLE && if(target && target->GetType() == cmTarget::EXECUTABLE &&
(target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))) (target->IsImported()
|| !this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING")))
{ {
return target->GetLocation(this->Config); return target->GetLocation(this->Config);
} }
return this->GE->Parse(argv0)->Evaluate(this->Makefile, this->Config); return this->GE->Parse(argv0)->Evaluate(this->LG->GetMakefile(),
this->Config);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -87,8 +90,9 @@ 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->Parse(commandLine[j])->Evaluate(this->Makefile, std::string arg =
this->Config); this->GE->Parse(commandLine[j])->Evaluate(this->LG->GetMakefile(),
this->Config);
cmd += " "; cmd += " ";
if(this->OldStyle) if(this->OldStyle)
{ {
@ -96,7 +100,7 @@ cmCustomCommandGenerator
} }
else else
{ {
cmOutputConverter converter(this->Makefile->GetStateSnapshot()); cmOutputConverter converter(this->LG->GetMakefile()->GetStateSnapshot());
cmd += converter.EscapeForShell(arg, this->MakeVars); cmd += converter.EscapeForShell(arg, this->MakeVars);
} }
} }
@ -141,7 +145,7 @@ std::vector<std::string> const& cmCustomCommandGenerator::GetDepends() const
= this->GE->Parse(*i); = this->GE->Parse(*i);
std::vector<std::string> result; std::vector<std::string> result;
cmSystemTools::ExpandListArgument( cmSystemTools::ExpandListArgument(
cge->Evaluate(this->Makefile, this->Config), result); cge->Evaluate(this->LG->GetMakefile(), this->Config), result);
for (std::vector<std::string>::iterator it = result.begin(); for (std::vector<std::string>::iterator it = result.begin();
it != result.end(); ++it) it != result.end(); ++it)
{ {

View File

@ -15,14 +15,14 @@
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
class cmCustomCommand; class cmCustomCommand;
class cmMakefile; class cmLocalGenerator;
class cmGeneratorExpression; class cmGeneratorExpression;
class cmCustomCommandGenerator class cmCustomCommandGenerator
{ {
cmCustomCommand const& CC; cmCustomCommand const& CC;
std::string Config; std::string Config;
cmMakefile* Makefile; cmLocalGenerator* LG;
bool OldStyle; bool OldStyle;
bool MakeVars; bool MakeVars;
cmGeneratorExpression* GE; cmGeneratorExpression* GE;
@ -31,7 +31,7 @@ class cmCustomCommandGenerator
public: public:
cmCustomCommandGenerator(cmCustomCommand const& cc, cmCustomCommandGenerator(cmCustomCommand const& cc,
const std::string& config, const std::string& config,
cmMakefile* mf); cmLocalGenerator* lg);
~cmCustomCommandGenerator(); ~cmCustomCommandGenerator();
cmCustomCommand const& GetCC() const { return this->CC; } cmCustomCommand const& GetCC() const { return this->CC; }
unsigned int GetNumberOfCommands() const; unsigned int GetNumberOfCommands() const;

View File

@ -938,7 +938,8 @@ void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
const std::string& config, const std::string& config,
std::set<std::string>& emitted) std::set<std::string>& emitted)
{ {
cmCustomCommandGenerator ccg(cc, config, this->Makefile); cmCustomCommandGenerator ccg(cc, config,
this->GeneratorTarget->LocalGenerator);
const std::vector<std::string>& depends = ccg.GetDepends(); const std::vector<std::string>& depends = ccg.GetDepends();

View File

@ -1668,7 +1668,7 @@ void cmGlobalXCodeGenerator
for(std::vector<cmCustomCommand>::const_iterator i = commands.begin(); for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
i != commands.end(); ++i) i != commands.end(); ++i)
{ {
cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile); cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator);
if(ccg.GetNumberOfCommands() > 0) if(ccg.GetNumberOfCommands() > 0)
{ {
const std::vector<std::string>& outputs = ccg.GetOutputs(); const std::vector<std::string>& outputs = ccg.GetOutputs();
@ -1694,7 +1694,7 @@ void cmGlobalXCodeGenerator
for(std::vector<cmCustomCommand>::const_iterator i = commands.begin(); for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
i != commands.end(); ++i) i != commands.end(); ++i)
{ {
cmCustomCommandGenerator ccg(*i, configName, this->CurrentMakefile); cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator);
if(ccg.GetNumberOfCommands() > 0) if(ccg.GetNumberOfCommands() > 0)
{ {
makefileStream << "\n"; makefileStream << "\n";

View File

@ -404,7 +404,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc)) if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc))
return; return;
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile); cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this);
const std::vector<std::string> &outputs = ccg.GetOutputs(); const std::vector<std::string> &outputs = ccg.GetOutputs();
const std::vector<std::string> &byproducts = ccg.GetByproducts(); const std::vector<std::string> &byproducts = ccg.GetByproducts();

View File

@ -1007,8 +1007,7 @@ cmLocalUnixMakefileGenerator3
for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin(); for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
i != ccs.end(); ++i) i != ccs.end(); ++i)
{ {
cmCustomCommandGenerator ccg(*i, this->ConfigName, cmCustomCommandGenerator ccg(*i, this->ConfigName, this);
this->Makefile);
this->AppendCustomDepend(depends, ccg); this->AppendCustomDepend(depends, ccg);
} }
} }
@ -1043,8 +1042,7 @@ cmLocalUnixMakefileGenerator3
for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin(); for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
i != ccs.end(); ++i) i != ccs.end(); ++i)
{ {
cmCustomCommandGenerator ccg(*i, this->ConfigName, cmCustomCommandGenerator ccg(*i, this->ConfigName, this);
this->Makefile);
this->AppendCustomCommand(commands, ccg, target, true, relative); this->AppendCustomCommand(commands, ccg, target, true, relative);
} }
} }

View File

@ -62,7 +62,7 @@ public:
} }
void Write(cmCustomCommand const& cc) void Write(cmCustomCommand const& cc)
{ {
cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile()); cmCustomCommandGenerator ccg(cc, this->Config, this->LG);
if(this->First) if(this->First)
{ {
this->Code += this->Event + "_Cmds="; this->Code += this->Event + "_Cmds=";
@ -625,7 +625,7 @@ cmLocalVisualStudio6Generator
for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i) for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i)
{ {
std::string config = this->GetConfigName(*i); std::string config = this->GetConfigName(*i);
cmCustomCommandGenerator ccg(command, config, this->Makefile); cmCustomCommandGenerator ccg(command, config, this);
std::string comment = std::string comment =
this->ConstructComment(ccg, "Building Custom Rule $(InputPath)"); this->ConstructComment(ccg, "Building Custom Rule $(InputPath)");
if(comment == "<hack>") if(comment == "<hack>")

View File

@ -619,7 +619,7 @@ public:
} }
void Write(cmCustomCommand const& cc) void Write(cmCustomCommand const& cc)
{ {
cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile()); cmCustomCommandGenerator ccg(cc, this->Config, this->LG);
if(this->First) if(this->First)
{ {
const char* comment = ccg.GetComment(); const char* comment = ccg.GetComment();
@ -1903,7 +1903,7 @@ WriteCustomRule(std::ostream& fout,
for (std::vector<std::string>::const_iterator i = configs.begin(); for (std::vector<std::string>::const_iterator i = configs.begin();
i != configs.end(); ++i) i != configs.end(); ++i)
{ {
cmCustomCommandGenerator ccg(command, *i, this->Makefile); cmCustomCommandGenerator ccg(command, *i, this);
cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i]; cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
fout << "\t\t\t\t<FileConfiguration\n"; fout << "\t\t\t\t<FileConfiguration\n";
fout << "\t\t\t\t\tName=\"" << *i << "|" fout << "\t\t\t\t\tName=\"" << *i << "|"

View File

@ -167,7 +167,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
{ {
cmCustomCommandGenerator ccg(*(*si)->GetCustomCommand(), cmCustomCommandGenerator ccg(*(*si)->GetCustomCommand(),
this->ConfigName, this->ConfigName,
this->Makefile); this->LocalGenerator);
this->GenerateCustomRuleFile(ccg); this->GenerateCustomRuleFile(ccg);
if (clean) if (clean)
{ {
@ -1182,7 +1182,8 @@ cmMakefileTargetGenerator
{ {
if(cmCustomCommand* cc = (*source)->GetCustomCommand()) if(cmCustomCommand* cc = (*source)->GetCustomCommand())
{ {
cmCustomCommandGenerator ccg(*cc, this->ConfigName, this->Makefile); cmCustomCommandGenerator ccg(*cc, this->ConfigName,
this->LocalGenerator);
const std::vector<std::string>& outputs = ccg.GetOutputs(); const std::vector<std::string>& outputs = ccg.GetOutputs();
depends.insert(depends.end(), outputs.begin(), outputs.end()); depends.insert(depends.end(), outputs.begin(), outputs.end());
} }

View File

@ -608,7 +608,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
ci = cmdLists[i]->begin(); ci = cmdLists[i]->begin();
ci != cmdLists[i]->end(); ++ci) ci != cmdLists[i]->end(); ++ci)
{ {
cmCustomCommandGenerator ccg(*ci, cfgName, mf); cmCustomCommandGenerator ccg(*ci, cfgName, this->GetLocalGenerator());
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]); localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
std::vector<std::string> const& ccByproducts = ccg.GetByproducts(); std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
std::transform(ccByproducts.begin(), ccByproducts.end(), std::transform(ccByproducts.begin(), ccByproducts.end(),

View File

@ -509,7 +509,7 @@ cmNinjaTargetGenerator
{ {
cmCustomCommand const* cc = *cci; cmCustomCommand const* cc = *cci;
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
this->GetMakefile()); this->GetLocalGenerator());
const std::vector<std::string>& ccoutputs = ccg.GetOutputs(); const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
const std::vector<std::string>& ccbyproducts= ccg.GetByproducts(); const std::vector<std::string>& ccbyproducts= ccg.GetByproducts();
std::transform(ccoutputs.begin(), ccoutputs.end(), std::transform(ccoutputs.begin(), ccoutputs.end(),

View File

@ -44,7 +44,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
for (std::vector<cmCustomCommand>::const_iterator for (std::vector<cmCustomCommand>::const_iterator
ci = cmdLists[i]->begin(); ci != cmdLists[i]->end(); ++ci) { ci = cmdLists[i]->begin(); ci != cmdLists[i]->end(); ++ci) {
cmCustomCommandGenerator ccg(*ci, this->GetConfigName(), cmCustomCommandGenerator ccg(*ci, this->GetConfigName(),
this->GetMakefile()); this->GetLocalGenerator());
this->GetLocalGenerator()->AppendCustomCommandDeps(ccg, deps); this->GetLocalGenerator()->AppendCustomCommandDeps(ccg, deps);
this->GetLocalGenerator()->AppendCustomCommandLines(ccg, commands); this->GetLocalGenerator()->AppendCustomCommandLines(ccg, commands);
std::vector<std::string> const& ccByproducts = ccg.GetByproducts(); std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
@ -65,7 +65,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
if(cmCustomCommand* cc = (*source)->GetCustomCommand()) if(cmCustomCommand* cc = (*source)->GetCustomCommand())
{ {
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
this->GetMakefile()); this->GetLocalGenerator());
this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
// Depend on all custom command outputs. // Depend on all custom command outputs.

View File

@ -890,7 +890,7 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
i = this->Configurations.begin(); i = this->Configurations.begin();
i != this->Configurations.end(); ++i) i != this->Configurations.end(); ++i)
{ {
cmCustomCommandGenerator ccg(command, *i, this->Makefile); cmCustomCommandGenerator ccg(command, *i, this->LocalGenerator);
std::string comment = lg->ConstructComment(ccg); std::string comment = lg->ConstructComment(ccg);
comment = cmVS10EscapeComment(comment); comment = cmVS10EscapeComment(comment);
std::string script = std::string script =
@ -2794,7 +2794,7 @@ void cmVisualStudio10TargetGenerator::WriteEvent(
for(std::vector<cmCustomCommand>::const_iterator i = commands.begin(); for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
i != commands.end(); ++i) i != commands.end(); ++i)
{ {
cmCustomCommandGenerator ccg(*i, configName, this->Makefile); cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator);
comment += pre; comment += pre;
comment += lg->ConstructComment(ccg); comment += lg->ConstructComment(ccg);
script += pre; script += pre;