From e37ff5694c043507f133dc774dc8eeaeb923c56b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 23 Nov 2022 17:28:40 -0500 Subject: cmGeneratorTarget: factor out fileset info and scanning detection --- Source/cmGeneratorTarget.cxx | 82 ++++++++++++++++++++++++++++++++++++ Source/cmGeneratorTarget.h | 14 ++++++ Source/cmNinjaTargetGenerator.cxx | 89 ++------------------------------------- Source/cmNinjaTargetGenerator.h | 9 ---- 4 files changed, 99 insertions(+), 95 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bf0aa8e..27e31d4 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -8885,3 +8885,85 @@ bool cmGeneratorTarget::NeedDyndep(std::string const& lang, { return lang == "Fortran"_s || this->NeedCxxModuleSupport(lang, config); } + +cmFileSet const* cmGeneratorTarget::GetFileSetForSource( + std::string const& config, cmSourceFile const* sf) const +{ + this->BuildFileSetInfoCache(config); + + auto const& path = sf->GetFullPath(); + auto const& per_config = this->Configs[config]; + + auto const fsit = per_config.FileSetCache.find(path); + if (fsit == per_config.FileSetCache.end()) { + return nullptr; + } + return fsit->second; +} + +bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang, + std::string const& config, + cmSourceFile const* sf) const +{ + bool const needDyndep = this->NeedDyndep(lang, config); + if (!needDyndep) { + return false; + } + auto const* fs = this->GetFileSetForSource(config, sf); + if (fs && + (fs->GetType() == "CXX_MODULES"_s || + fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) { + return true; + } + auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES"); + if (sfProp.IsSet()) { + return sfProp.IsOn(); + } + auto const tgtProp = this->GetProperty("CXX_SCAN_FOR_MODULES"); + if (tgtProp.IsSet()) { + return tgtProp.IsOn(); + } + return true; +} + +void cmGeneratorTarget::BuildFileSetInfoCache(std::string const& config) const +{ + auto& per_config = this->Configs[config]; + + if (per_config.BuiltFileSetCache) { + return; + } + + auto const* tgt = this->Target; + + for (auto const& name : tgt->GetAllFileSetNames()) { + auto const* file_set = tgt->GetFileSet(name); + if (!file_set) { + tgt->GetMakefile()->IssueMessage( + MessageType::INTERNAL_ERROR, + cmStrCat("Target \"", tgt->GetName(), + "\" is tracked to have file set \"", name, + "\", but it was not found.")); + continue; + } + + auto fileEntries = file_set->CompileFileEntries(); + auto directoryEntries = file_set->CompileDirectoryEntries(); + auto directories = file_set->EvaluateDirectoryEntries( + directoryEntries, this->LocalGenerator, config, this); + + std::map> files; + for (auto const& entry : fileEntries) { + file_set->EvaluateFileEntry(directories, files, entry, + this->LocalGenerator, config, this); + } + + for (auto const& it : files) { + for (auto const& filename : it.second) { + per_config.FileSetCache[filename] = file_set; + } + } + } + + per_config.BuiltFileSetCache = true; +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 858be36..96eda2c 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -26,6 +26,7 @@ enum class cmBuildStep; class cmComputeLinkInformation; class cmCustomCommand; +class cmFileSet; class cmGlobalGenerator; class cmLocalGenerator; class cmMakefile; @@ -1233,4 +1234,17 @@ public: bool NeedCxxModuleSupport(std::string const& lang, std::string const& config) const; bool NeedDyndep(std::string const& lang, std::string const& config) const; + cmFileSet const* GetFileSetForSource(std::string const& config, + cmSourceFile const* sf) const; + bool NeedDyndepForSource(std::string const& lang, std::string const& config, + cmSourceFile const* sf) const; + +private: + void BuildFileSetInfoCache(std::string const& config) const; + struct InfoByConfig + { + bool BuiltFileSetCache = false; + std::map FileSetCache; + }; + mutable std::map Configs; }; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 68757b8..095bf40 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -157,90 +157,6 @@ std::string cmNinjaTargetGenerator::LanguageDyndepRule( '_', config); } -void cmNinjaTargetGenerator::BuildFileSetInfoCache(std::string const& config) -{ - auto& per_config = this->Configs[config]; - - if (per_config.BuiltFileSetCache) { - return; - } - - auto const* tgt = this->GeneratorTarget->Target; - - for (auto const& name : tgt->GetAllFileSetNames()) { - auto const* file_set = tgt->GetFileSet(name); - if (!file_set) { - this->GetMakefile()->IssueMessage( - MessageType::INTERNAL_ERROR, - cmStrCat("Target \"", tgt->GetName(), - "\" is tracked to have file set \"", name, - "\", but it was not found.")); - continue; - } - - auto fileEntries = file_set->CompileFileEntries(); - auto directoryEntries = file_set->CompileDirectoryEntries(); - auto directories = file_set->EvaluateDirectoryEntries( - directoryEntries, this->LocalGenerator, config, this->GeneratorTarget); - - std::map> files; - for (auto const& entry : fileEntries) { - file_set->EvaluateFileEntry(directories, files, entry, - this->LocalGenerator, config, - this->GeneratorTarget); - } - - for (auto const& it : files) { - for (auto const& filename : it.second) { - per_config.FileSetCache[filename] = file_set; - } - } - } - - per_config.BuiltFileSetCache = true; -} - -cmFileSet const* cmNinjaTargetGenerator::GetFileSetForSource( - std::string const& config, cmSourceFile const* sf) -{ - this->BuildFileSetInfoCache(config); - - auto const& path = sf->GetFullPath(); - auto const& per_config = this->Configs[config]; - - auto const fsit = per_config.FileSetCache.find(path); - if (fsit == per_config.FileSetCache.end()) { - return nullptr; - } - return fsit->second; -} - -bool cmNinjaTargetGenerator::NeedDyndepForSource(std::string const& lang, - std::string const& config, - cmSourceFile const* sf) -{ - bool const needDyndep = this->GetGeneratorTarget()->NeedDyndep(lang, config); - if (!needDyndep) { - return false; - } - auto const* fs = this->GetFileSetForSource(config, sf); - if (fs && - (fs->GetType() == "CXX_MODULES"_s || - fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) { - return true; - } - auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES"); - if (sfProp.IsSet()) { - return sfProp.IsOn(); - } - auto const tgtProp = - this->GeneratorTarget->GetProperty("CXX_SCAN_FOR_MODULES"); - if (tgtProp.IsSet()) { - return tgtProp.IsOn(); - } - return true; -} - std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget( const std::string& config) { @@ -324,7 +240,7 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject( flags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS)); } - auto const* fs = this->GetFileSetForSource(config, source); + auto const* fs = this->GeneratorTarget->GetFileSetForSource(config, source); if (fs && (fs->GetType() == "CXX_MODULES"_s || fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) { @@ -1370,7 +1286,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( !(language == "RC" || (language == "CUDA" && !flag)); int const commandLineLengthLimit = ((lang_supports_response && this->ForceResponseFile())) ? -1 : 0; - bool const needDyndep = this->NeedDyndepForSource(language, config, source); + bool const needDyndep = + this->GeneratorTarget->NeedDyndepForSource(language, config, source); cmNinjaBuild objBuild(this->LanguageCompilerRule( language, config, needDyndep ? WithScanning::Yes : WithScanning::No)); diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 04d6bd7..b5abb36 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -19,7 +19,6 @@ #include "cmOSXBundleGenerator.h" class cmCustomCommand; -class cmFileSet; class cmGeneratedFileStream; class cmGeneratorTarget; class cmLocalNinjaGenerator; @@ -64,10 +63,6 @@ protected: cmMakefile* GetMakefile() const { return this->Makefile; } - void BuildFileSetInfoCache(std::string const& config); - cmFileSet const* GetFileSetForSource(std::string const& config, - cmSourceFile const* sf); - enum class WithScanning { No, @@ -82,8 +77,6 @@ protected: const std::string& config) const; std::string LanguageDyndepRule(std::string const& lang, const std::string& config) const; - bool NeedDyndepForSource(std::string const& lang, std::string const& config, - cmSourceFile const* sf); bool NeedExplicitPreprocessing(std::string const& lang) const; bool CompileWithDefines(std::string const& lang) const; @@ -235,8 +228,6 @@ private: std::vector CustomCommands; cmNinjaDeps ExtraFiles; std::unique_ptr MacOSXContentGenerator; - bool BuiltFileSetCache = false; - std::map FileSetCache; }; std::map Configs; -- cgit v0.12