Ninja: GlobalNinjaGenerator WriteBuild and WritePhonyBuild non static

To properly track the usage of dependencies that are generated at
compile time as the side effect of other build steps we need
to make the WriteBuild and WritePhonyBuild commands non static
This commit is contained in:
Robert Maynard 2013-06-07 14:25:33 -04:00 committed by Brad King
parent 88d27ad014
commit 874e17120d
6 changed files with 133 additions and 126 deletions

View File

@ -208,14 +208,14 @@ void cmGlobalNinjaGenerator::WritePhonyBuild(std::ostream& os,
const cmNinjaDeps& orderOnlyDeps, const cmNinjaDeps& orderOnlyDeps,
const cmNinjaVars& variables) const cmNinjaVars& variables)
{ {
cmGlobalNinjaGenerator::WriteBuild(os, this->WriteBuild(os,
comment, comment,
"phony", "phony",
outputs, outputs,
explicitDeps, explicitDeps,
implicitDeps, implicitDeps,
orderOnlyDeps, orderOnlyDeps,
variables); variables);
} }
void cmGlobalNinjaGenerator::AddCustomCommandRule() void cmGlobalNinjaGenerator::AddCustomCommandRule()
@ -251,14 +251,14 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
vars["COMMAND"] = cmd; vars["COMMAND"] = cmd;
vars["DESC"] = EncodeLiteral(description); vars["DESC"] = EncodeLiteral(description);
cmGlobalNinjaGenerator::WriteBuild(*this->BuildFileStream, this->WriteBuild(*this->BuildFileStream,
comment, comment,
"CUSTOM_COMMAND", "CUSTOM_COMMAND",
outputs, outputs,
deps, deps,
cmNinjaDeps(), cmNinjaDeps(),
orderOnlyDeps, orderOnlyDeps,
vars); vars);
} }
void void
@ -293,14 +293,14 @@ cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input,
deps.push_back(input); deps.push_back(input);
cmNinjaVars vars; cmNinjaVars vars;
cmGlobalNinjaGenerator::WriteBuild(*this->BuildFileStream, this->WriteBuild(*this->BuildFileStream,
"", "",
"COPY_OSX_CONTENT", "COPY_OSX_CONTENT",
outputs, outputs,
deps, deps,
cmNinjaDeps(), cmNinjaDeps(),
cmNinjaDeps(), cmNinjaDeps(),
cmNinjaVars()); cmNinjaVars());
} }
void cmGlobalNinjaGenerator::WriteRule(std::ostream& os, void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
@ -896,10 +896,10 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
cmNinjaDeps deps; cmNinjaDeps deps;
this->AppendTargetOutputs(i->second, deps); this->AppendTargetOutputs(i->second, deps);
cmGlobalNinjaGenerator::WritePhonyBuild(os, this->WritePhonyBuild(os,
"", "",
cmNinjaDeps(1, i->first), cmNinjaDeps(1, i->first),
deps); deps);
} }
} }
@ -920,10 +920,10 @@ void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
cmNinjaDeps outputs; cmNinjaDeps outputs;
outputs.push_back("all"); outputs.push_back("all");
cmGlobalNinjaGenerator::WritePhonyBuild(os, this->WritePhonyBuild(os,
"The main all target.", "The main all target.",
outputs, outputs,
this->AllDependencies); this->AllDependencies);
cmGlobalNinjaGenerator::WriteDefault(os, cmGlobalNinjaGenerator::WriteDefault(os,
outputs, outputs,
@ -970,19 +970,19 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
implicitDeps.end()); implicitDeps.end());
implicitDeps.push_back("CMakeCache.txt"); implicitDeps.push_back("CMakeCache.txt");
WriteBuild(os, this->WriteBuild(os,
"Re-run CMake if any of its inputs changed.", "Re-run CMake if any of its inputs changed.",
"RERUN_CMAKE", "RERUN_CMAKE",
/*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE), /*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE),
/*explicitDeps=*/ cmNinjaDeps(), /*explicitDeps=*/ cmNinjaDeps(),
implicitDeps, implicitDeps,
/*orderOnlyDeps=*/ cmNinjaDeps(), /*orderOnlyDeps=*/ cmNinjaDeps(),
/*variables=*/ cmNinjaVars()); /*variables=*/ cmNinjaVars());
WritePhonyBuild(os, this->WritePhonyBuild(os,
"A missing CMake input file is not an error.", "A missing CMake input file is not an error.",
implicitDeps, implicitDeps,
cmNinjaDeps()); cmNinjaDeps());
} }
std::string cmGlobalNinjaGenerator::ninjaCmd() const std::string cmGlobalNinjaGenerator::ninjaCmd() const

View File

@ -77,27 +77,27 @@ public:
* It also writes the variables bound to this build statement. * It also writes the variables bound to this build statement.
* @warning no escaping of any kind is done here. * @warning no escaping of any kind is done here.
*/ */
static void WriteBuild(std::ostream& os, void WriteBuild(std::ostream& os,
const std::string& comment, const std::string& comment,
const std::string& rule, const std::string& rule,
const cmNinjaDeps& outputs, const cmNinjaDeps& outputs,
const cmNinjaDeps& explicitDeps, const cmNinjaDeps& explicitDeps,
const cmNinjaDeps& implicitDeps, const cmNinjaDeps& implicitDeps,
const cmNinjaDeps& orderOnlyDeps, const cmNinjaDeps& orderOnlyDeps,
const cmNinjaVars& variables, const cmNinjaVars& variables,
const std::string& rspfile = std::string(), const std::string& rspfile = std::string(),
int cmdLineLimit = -1); int cmdLineLimit = -1);
/** /**
* Helper to write a build statement with the special 'phony' rule. * Helper to write a build statement with the special 'phony' rule.
*/ */
static void WritePhonyBuild(std::ostream& os, void WritePhonyBuild(std::ostream& os,
const std::string& comment, const std::string& comment,
const cmNinjaDeps& outputs, const cmNinjaDeps& outputs,
const cmNinjaDeps& explicitDeps, const cmNinjaDeps& explicitDeps,
const cmNinjaDeps& implicitDeps = cmNinjaDeps(), const cmNinjaDeps& implicitDeps = cmNinjaDeps(),
const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps(), const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps(),
const cmNinjaVars& variables = cmNinjaVars()); const cmNinjaVars& variables = cmNinjaVars());
void WriteCustomCommandBuild(const std::string& command, void WriteCustomCommandBuild(const std::string& command,
const std::string& description, const std::string& description,

View File

@ -340,14 +340,15 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
this->AppendCustomCommandLines(cc, cmdLines); this->AppendCustomCommandLines(cc, cmdLines);
if (cmdLines.empty()) { if (cmdLines.empty()) {
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), this->GetGlobalNinjaGenerator()->WritePhonyBuild(
"Phony custom command for " + this->GetBuildFileStream(),
ninjaOutputs[0], "Phony custom command for " +
ninjaOutputs, ninjaOutputs[0],
ninjaDeps, ninjaOutputs,
cmNinjaDeps(), ninjaDeps,
orderOnlyDeps, cmNinjaDeps(),
cmNinjaVars()); orderOnlyDeps,
cmNinjaVars());
} else { } else {
this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild( this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild(
this->BuildCommandLine(cmdLines), this->BuildCommandLine(cmdLines),

View File

@ -598,32 +598,37 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
#endif #endif
} }
//Get the global generator as we are going to be call WriteBuild numerous
//times in the following section
cmGlobalNinjaGenerator* globalGenerator = this->GetGlobalGenerator();
const std::string rspfile = std::string const std::string rspfile = std::string
(cmake::GetCMakeFilesDirectoryPostSlash()) + (cmake::GetCMakeFilesDirectoryPostSlash()) +
this->GetTarget()->GetName() + ".rsp"; this->GetTarget()->GetName() + ".rsp";
// Write the build statement for this target. // Write the build statement for this target.
cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), globalGenerator->WriteBuild(this->GetBuildFileStream(),
comment.str(), comment.str(),
this->LanguageLinkerRule(), this->LanguageLinkerRule(),
outputs, outputs,
explicitDeps, explicitDeps,
implicitDeps, implicitDeps,
emptyDeps, emptyDeps,
vars, vars,
rspfile, rspfile,
commandLineLengthLimit); commandLineLengthLimit);
if (targetOutput != targetOutputReal) { if (targetOutput != targetOutputReal) {
if (targetType == cmTarget::EXECUTABLE) { if (targetType == cmTarget::EXECUTABLE) {
cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), globalGenerator->WriteBuild(this->GetBuildFileStream(),
"Create executable symlink " + targetOutput, "Create executable symlink " + targetOutput,
"CMAKE_SYMLINK_EXECUTABLE", "CMAKE_SYMLINK_EXECUTABLE",
cmNinjaDeps(1, targetOutput), cmNinjaDeps(1, targetOutput),
cmNinjaDeps(1, targetOutputReal), cmNinjaDeps(1, targetOutputReal),
emptyDeps, emptyDeps,
emptyDeps, emptyDeps,
symlinkVars); symlinkVars);
} else { } else {
cmNinjaDeps symlinks; cmNinjaDeps symlinks;
const std::string soName = this->GetTargetFilePath(this->TargetNameSO); const std::string soName = this->GetTargetFilePath(this->TargetNameSO);
@ -635,30 +640,30 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
symlinks.push_back(soName); symlinks.push_back(soName);
} }
symlinks.push_back(targetOutput); symlinks.push_back(targetOutput);
cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), globalGenerator->WriteBuild(this->GetBuildFileStream(),
"Create library symlink " + targetOutput, "Create library symlink " + targetOutput,
"CMAKE_SYMLINK_LIBRARY", "CMAKE_SYMLINK_LIBRARY",
symlinks, symlinks,
cmNinjaDeps(1, targetOutputReal), cmNinjaDeps(1, targetOutputReal),
emptyDeps, emptyDeps,
emptyDeps, emptyDeps,
symlinkVars); symlinkVars);
} }
} }
if (!this->TargetNameImport.empty()) { if (!this->TargetNameImport.empty()) {
// Since using multiple outputs would mess up the $out variable, use an // Since using multiple outputs would mess up the $out variable, use an
// alias for the import library. // alias for the import library.
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), globalGenerator->WritePhonyBuild(this->GetBuildFileStream(),
"Alias for import library.", "Alias for import library.",
cmNinjaDeps(1, targetOutputImplib), cmNinjaDeps(1, targetOutputImplib),
cmNinjaDeps(1, targetOutputReal)); cmNinjaDeps(1, targetOutputReal));
} }
// Add aliases for the file name and the target name. // Add aliases for the file name and the target name.
this->GetGlobalGenerator()->AddTargetAlias(this->TargetNameOut, globalGenerator->AddTargetAlias(this->TargetNameOut,
this->GetTarget()); this->GetTarget());
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), globalGenerator->AddTargetAlias(this->GetTargetName(),
this->GetTarget()); this->GetTarget());
} }
@ -669,11 +674,11 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
cmNinjaDeps outputs; cmNinjaDeps outputs;
this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs); this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
cmNinjaDeps depends = this->GetObjects(); cmNinjaDeps depends = this->GetObjects();
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
"Object library " "Object library "
+ this->GetTargetName(), + this->GetTargetName(),
outputs, outputs,
depends); depends);
// Add aliases for the target name. // Add aliases for the target name.
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),

View File

@ -642,24 +642,24 @@ cmNinjaTargetGenerator
sourceFileName); sourceFileName);
} }
cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
comment, comment,
rule, rule,
outputs, outputs,
explicitDeps, explicitDeps,
implicitDeps, implicitDeps,
orderOnlyDeps, orderOnlyDeps,
vars); vars);
if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) { if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
std::vector<std::string> outputList; std::vector<std::string> outputList;
cmSystemTools::ExpandListArgument(objectOutputs, outputList); cmSystemTools::ExpandListArgument(objectOutputs, outputList);
std::transform(outputList.begin(), outputList.end(), outputList.begin(), std::transform(outputList.begin(), outputList.end(), outputList.begin(),
MapToNinjaPath()); MapToNinjaPath());
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
"Additional output files.", "Additional output files.",
outputList, outputList,
outputs); outputs);
} }
} }

View File

@ -61,11 +61,11 @@ void cmNinjaUtilityTargetGenerator::Generate()
this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps); this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps);
if (commands.empty()) { if (commands.empty()) {
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
"Utility command for " "Utility command for "
+ this->GetTargetName(), + this->GetTargetName(),
outputs, outputs,
deps); deps);
} else { } else {
std::string command = std::string command =
this->GetLocalGenerator()->BuildCommandLine(commands); this->GetLocalGenerator()->BuildCommandLine(commands);
@ -105,10 +105,11 @@ void cmNinjaUtilityTargetGenerator::Generate()
cmNinjaDeps(1, utilCommandName), cmNinjaDeps(1, utilCommandName),
deps); deps);
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
"", "",
outputs, outputs,
cmNinjaDeps(1, utilCommandName)); cmNinjaDeps(1, utilCommandName)
);
} }
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),