From b215cbc07d997b19ad8c02b2159eb0538be6dee3 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 10 Feb 2023 17:51:46 -0500 Subject: Ninja: remove the modmap as an output of the scanner It's actually an output of the collator. --- Source/cmNinjaTargetGenerator.cxx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index cea58b7..da74fad 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1210,7 +1210,6 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName, const std::string& ppFileName, bool compilePP, bool compilePPWithDefines, cmNinjaBuild& objBuild, cmNinjaVars& vars, - std::string const& modmapFormat, const std::string& objectFileName, cmLocalGenerator* lg) { @@ -1279,15 +1278,6 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName, vars.erase("DEP_FILE"); } - if (!modmapFormat.empty()) { - // XXX(modmap): If changing this path construction, change - // `cmGlobalNinjaGenerator::WriteDyndep` to expect the corresponding - // file path. - std::string const ddModmapFile = cmStrCat(objectFileName, ".modmap"); - scanBuild.Variables["DYNDEP_MODULE_MAP_FILE"] = ddModmapFile; - scanBuild.ImplicitOuts.push_back(ddModmapFile); - } - return scanBuild; } } @@ -1482,7 +1472,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( cmNinjaBuild ppBuild = GetScanBuildStatement( scanRuleName, ppFileName, compilePP, compilePPWithDefines, objBuild, - vars, modmapFormat, objectFileName, this->LocalGenerator); + vars, objectFileName, this->LocalGenerator); if (compilePP) { // In case compilation requires flags that are incompatible with @@ -1519,6 +1509,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( vars["dyndep"] = dyndep; if (!modmapFormat.empty()) { + // XXX(modmap): If changing this path construction, change + // `cmGlobalNinjaGenerator::WriteDyndep` to expect the corresponding file + // path. std::string const ddModmapFile = cmStrCat(objectFileName, ".modmap"); vars["DYNDEP_MODULE_MAP_FILE"] = ddModmapFile; objBuild.OrderOnlyDeps.push_back(ddModmapFile); -- cgit v0.12 From 0ace6053e8a09656f2548697a8c61b9ad60a3cad Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 10 Feb 2023 17:52:17 -0500 Subject: Ninja: track modmap dependencies properly Mark modmaps as outputs of the collation step. --- Source/cmNinjaTargetGenerator.cxx | 27 ++++++++++++++++++++------- Source/cmNinjaTargetGenerator.h | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index da74fad..6f9bdbd 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1140,13 +1140,20 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( } } - for (auto const& langDDIFiles : this->Configs[config].DDIFiles) { - std::string const& language = langDDIFiles.first; - cmNinjaDeps const& ddiFiles = langDDIFiles.second; + for (auto const& langScanningFiles : this->Configs[config].ScanningInfo) { + std::string const& language = langScanningFiles.first; + std::vector const& scanningFiles = langScanningFiles.second; cmNinjaBuild build(this->LanguageDyndepRule(language, config)); build.Outputs.push_back(this->GetDyndepFilePath(language, config)); - build.ExplicitDeps = ddiFiles; + for (auto const& scanFiles : scanningFiles) { + if (!scanFiles.ScanningOutput.empty()) { + build.ExplicitDeps.push_back(scanFiles.ScanningOutput); + } + if (!scanFiles.ModuleMapFile.empty()) { + build.ImplicitOuts.push_back(scanFiles.ModuleMapFile); + } + } this->WriteTargetDependInfo(language, config); @@ -1493,9 +1500,10 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( vars["INCLUDES"] = cmStrCat(sourceDirectoryFlag, ' ', vars["INCLUDES"]); } + ScanningFiles scanningFiles; + if (firstForConfig) { - std::string const ddiFile = cmStrCat(objectFileName, ".ddi"); - this->Configs[config].DDIFiles[language].push_back(ddiFile); + scanningFiles.ScanningOutput = cmStrCat(objectFileName, ".ddi"); } this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), @@ -1512,9 +1520,14 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( // XXX(modmap): If changing this path construction, change // `cmGlobalNinjaGenerator::WriteDyndep` to expect the corresponding file // path. - std::string const ddModmapFile = cmStrCat(objectFileName, ".modmap"); + std::string ddModmapFile = cmStrCat(objectFileName, ".modmap"); vars["DYNDEP_MODULE_MAP_FILE"] = ddModmapFile; objBuild.OrderOnlyDeps.push_back(ddModmapFile); + scanningFiles.ModuleMapFile = std::move(ddModmapFile); + } + + if (!scanningFiles.IsEmpty()) { + this->Configs[config].ScanningInfo[language].emplace_back(scanningFiles); } } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 8bf7986..8f4a764 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -222,12 +222,23 @@ protected: private: cmLocalNinjaGenerator* LocalGenerator; + struct ScanningFiles + { + bool IsEmpty() const + { + return this->ScanningOutput.empty() && this->ModuleMapFile.empty(); + } + + std::string ScanningOutput; + std::string ModuleMapFile; + }; + struct ByConfig { /// List of object files for this target. cmNinjaDeps Objects; - // Fortran Support - std::map DDIFiles; + // Dyndep Support + std::map> ScanningInfo; // Swift Support Json::Value SwiftOutputMap; std::vector CustomCommands; -- cgit v0.12 From b6a53822176d120d1daa2fef5e261186767ab007 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 10 Feb 2023 18:42:02 -0500 Subject: Ninja: depend on language module information files directly Now that `GetLinkedTargetDirectories` can get the exact dependencies, use them to simplify the collation dependency graph. --- Source/cmNinjaTargetGenerator.cxx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 6f9bdbd..8663f46 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1146,6 +1146,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( cmNinjaBuild build(this->LanguageDyndepRule(language, config)); build.Outputs.push_back(this->GetDyndepFilePath(language, config)); + build.ImplicitOuts.push_back( + cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), + this->GetGlobalGenerator()->ConfigDirectory(config), '/', + language, "Modules.json")); for (auto const& scanFiles : scanningFiles) { if (!scanFiles.ScanningOutput.empty()) { build.ExplicitDeps.push_back(scanFiles.ScanningOutput); @@ -1157,17 +1162,10 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( this->WriteTargetDependInfo(language, config); - // Make sure dyndep files for all our dependencies have already - // been generated so that the 'Modules.json' files they - // produced as side-effects are available for us to read. - // Ideally we should depend on the 'Modules.json' files - // from our dependencies directly, but we don't know which of - // our dependencies produces them. Fixing this will require - // refactoring the Ninja generator to generate targets in - // dependency order so that we can collect the needed information. - this->GetLocalGenerator()->AppendTargetDepends( - this->GeneratorTarget, build.OrderOnlyDeps, config, fileConfig, - DependOnTargetArtifact); + for (std::string const& l : + this->GetLinkedTargetDirectories(language, config)) { + build.ImplicitDeps.push_back(cmStrCat(l, '/', language, "Modules.json")); + } this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), build); -- cgit v0.12