ENH: Refactor VS 7,8,9 build event generation
In cmLocalVisualStudio7Generator we generate pre-build, pre-link, and post-build events into project files. This refactors the generation code for the three event types into a private EventWriter class to avoid duplicate code.
This commit is contained in:
parent
17daa9398a
commit
4a9dd4aad4
|
@ -549,6 +549,64 @@ private:
|
||||||
bool& flag_handled);
|
bool& flag_handled);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// Helper class to write build event <Tool .../> elements.
|
||||||
|
class cmLocalVisualStudio7Generator::EventWriter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EventWriter(cmLocalVisualStudio7Generator* lg,
|
||||||
|
const char* config, std::ostream& os):
|
||||||
|
LG(lg), Config(config), Stream(os), First(true) {}
|
||||||
|
void Start(const char* tool)
|
||||||
|
{
|
||||||
|
this->First = true;
|
||||||
|
this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
|
||||||
|
}
|
||||||
|
void Finish()
|
||||||
|
{
|
||||||
|
this->Stream << (this->First? "" : "\"") << "/>\n";
|
||||||
|
}
|
||||||
|
void Write(std::vector<cmCustomCommand> const& ccs)
|
||||||
|
{
|
||||||
|
for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
|
||||||
|
ci != ccs.end(); ++ci)
|
||||||
|
{
|
||||||
|
this->Write(*ci);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Write(cmCustomCommand const& cc)
|
||||||
|
{
|
||||||
|
if(this->First)
|
||||||
|
{
|
||||||
|
const char* comment = cc.GetComment();
|
||||||
|
if(comment && *comment)
|
||||||
|
{
|
||||||
|
this->Stream << "\nDescription=\""
|
||||||
|
<< this->LG->EscapeForXML(comment) << "\"";
|
||||||
|
}
|
||||||
|
this->Stream << "\nCommandLine=\"";
|
||||||
|
this->First = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->Stream << this->LG->EscapeForXML("\n");
|
||||||
|
}
|
||||||
|
std::string script =
|
||||||
|
this->LG->ConstructScript(cc.GetCommandLines(),
|
||||||
|
cc.GetWorkingDirectory(),
|
||||||
|
this->Config,
|
||||||
|
cc.GetEscapeOldStyle(),
|
||||||
|
cc.GetEscapeAllowMakeVars());
|
||||||
|
this->Stream << this->LG->EscapeForXML(script.c_str());
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
cmLocalVisualStudio7Generator* LG;
|
||||||
|
const char* Config;
|
||||||
|
std::ostream& Stream;
|
||||||
|
bool First;
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
|
void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
|
||||||
const char* configName,
|
const char* configName,
|
||||||
const char *libName,
|
const char *libName,
|
||||||
|
@ -1628,128 +1686,26 @@ void cmLocalVisualStudio7Generator
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char* tool = "VCPreBuildEventTool";
|
EventWriter event(this, configName, fout);
|
||||||
if(this->FortranProject)
|
|
||||||
{
|
|
||||||
tool = "VFPreBuildEventTool";
|
|
||||||
}
|
|
||||||
// add the pre build rules
|
|
||||||
fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
|
|
||||||
bool init = false;
|
|
||||||
for (std::vector<cmCustomCommand>::const_iterator cr =
|
|
||||||
target.GetPreBuildCommands().begin();
|
|
||||||
cr != target.GetPreBuildCommands().end(); ++cr)
|
|
||||||
{
|
|
||||||
if(!init)
|
|
||||||
{
|
|
||||||
const char* comment = cr->GetComment();
|
|
||||||
if(comment && *comment)
|
|
||||||
{
|
|
||||||
fout << "\nDescription=\""
|
|
||||||
<< this->EscapeForXML(comment) << "\"";
|
|
||||||
}
|
|
||||||
fout << "\nCommandLine=\"";
|
|
||||||
init = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fout << this->EscapeForXML("\n");
|
|
||||||
}
|
|
||||||
std::string script =
|
|
||||||
this->ConstructScript(cr->GetCommandLines(),
|
|
||||||
cr->GetWorkingDirectory(),
|
|
||||||
configName,
|
|
||||||
cr->GetEscapeOldStyle(),
|
|
||||||
cr->GetEscapeAllowMakeVars());
|
|
||||||
fout << this->EscapeForXML(script.c_str()).c_str();
|
|
||||||
}
|
|
||||||
if (init)
|
|
||||||
{
|
|
||||||
fout << "\"";
|
|
||||||
}
|
|
||||||
fout << "/>\n";
|
|
||||||
|
|
||||||
// add the pre Link rules
|
// Add pre-build event.
|
||||||
tool = "VCPreLinkEventTool";
|
const char* tool =
|
||||||
if(this->FortranProject)
|
this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
|
||||||
{
|
event.Start(tool);
|
||||||
tool = "VFPreLinkEventTool";
|
event.Write(target.GetPreBuildCommands());
|
||||||
}
|
event.Finish();
|
||||||
fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
|
|
||||||
init = false;
|
|
||||||
for (std::vector<cmCustomCommand>::const_iterator cr =
|
|
||||||
target.GetPreLinkCommands().begin();
|
|
||||||
cr != target.GetPreLinkCommands().end(); ++cr)
|
|
||||||
{
|
|
||||||
if(!init)
|
|
||||||
{
|
|
||||||
const char* comment = cr->GetComment();
|
|
||||||
if(comment && *comment)
|
|
||||||
{
|
|
||||||
fout << "\nDescription=\""
|
|
||||||
<< this->EscapeForXML(comment) << "\"";
|
|
||||||
}
|
|
||||||
fout << "\nCommandLine=\"";
|
|
||||||
init = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fout << this->EscapeForXML("\n");
|
|
||||||
}
|
|
||||||
std::string script =
|
|
||||||
this->ConstructScript(cr->GetCommandLines(),
|
|
||||||
cr->GetWorkingDirectory(),
|
|
||||||
configName,
|
|
||||||
cr->GetEscapeOldStyle(),
|
|
||||||
cr->GetEscapeAllowMakeVars());
|
|
||||||
fout << this->EscapeForXML(script.c_str()).c_str();
|
|
||||||
}
|
|
||||||
if (init)
|
|
||||||
{
|
|
||||||
fout << "\"";
|
|
||||||
}
|
|
||||||
fout << "/>\n";
|
|
||||||
|
|
||||||
// add the PostBuild rules
|
// Add pre-link event.
|
||||||
tool = "VCPostBuildEventTool";
|
tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
|
||||||
if(this->FortranProject)
|
event.Start(tool);
|
||||||
{
|
event.Write(target.GetPreLinkCommands());
|
||||||
tool = "VFPostBuildEventTool";
|
event.Finish();
|
||||||
}
|
|
||||||
fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
|
// Add post-build event.
|
||||||
init = false;
|
tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
|
||||||
for (std::vector<cmCustomCommand>::const_iterator cr =
|
event.Start(tool);
|
||||||
target.GetPostBuildCommands().begin();
|
event.Write(target.GetPostBuildCommands());
|
||||||
cr != target.GetPostBuildCommands().end(); ++cr)
|
event.Finish();
|
||||||
{
|
|
||||||
if(!init)
|
|
||||||
{
|
|
||||||
const char* comment = cr->GetComment();
|
|
||||||
if(comment && *comment)
|
|
||||||
{
|
|
||||||
fout << "\nDescription=\""
|
|
||||||
<< this->EscapeForXML(comment) << "\"";
|
|
||||||
}
|
|
||||||
fout << "\nCommandLine=\"";
|
|
||||||
init = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fout << this->EscapeForXML("\n");
|
|
||||||
}
|
|
||||||
std::string script =
|
|
||||||
this->ConstructScript(cr->GetCommandLines(),
|
|
||||||
cr->GetWorkingDirectory(),
|
|
||||||
configName,
|
|
||||||
cr->GetEscapeOldStyle(),
|
|
||||||
cr->GetEscapeAllowMakeVars());
|
|
||||||
fout << this->EscapeForXML(script.c_str()).c_str();
|
|
||||||
}
|
|
||||||
if (init)
|
|
||||||
{
|
|
||||||
fout << "\"";
|
|
||||||
}
|
|
||||||
fout << "/>\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -123,6 +123,9 @@ private:
|
||||||
friend class cmLocalVisualStudio7GeneratorFCInfo;
|
friend class cmLocalVisualStudio7GeneratorFCInfo;
|
||||||
friend class cmLocalVisualStudio7GeneratorInternals;
|
friend class cmLocalVisualStudio7GeneratorInternals;
|
||||||
|
|
||||||
|
class EventWriter;
|
||||||
|
friend class EventWriter;
|
||||||
|
|
||||||
cmVS7FlagTable const* ExtraFlagTable;
|
cmVS7FlagTable const* ExtraFlagTable;
|
||||||
std::string ModuleDefinitionFile;
|
std::string ModuleDefinitionFile;
|
||||||
int Version;
|
int Version;
|
||||||
|
|
Loading…
Reference in New Issue