From 2f93a272d08e44a66249b0c22fed8ff472dda73c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 30 Nov 2022 09:10:10 -0500 Subject: cmDyndepCollation: factor out parsing dyndep information --- Source/cmDyndepCollation.cxx | 62 ++++++++++++++++++++++++- Source/cmDyndepCollation.h | 49 ++++++++++++++++++++ Source/cmGlobalNinjaGenerator.cxx | 97 ++------------------------------------- Source/cmGlobalNinjaGenerator.h | 4 +- 4 files changed, 116 insertions(+), 96 deletions(-) diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index 92ad697..f933e2a 100644 --- a/Source/cmDyndepCollation.cxx +++ b/Source/cmDyndepCollation.cxx @@ -5,10 +5,10 @@ #include #include -#include #include #include +#include #include #include @@ -260,3 +260,63 @@ void cmDyndepCollation::AddCollationInformation( tdi["exports"] = CollationInformationExports(gt); tdi["config"] = config; } + +std::unique_ptr cmDyndepCollation::ParseExportInfo( + Json::Value const& tdi) +{ + auto export_info = cm::make_unique(); + + export_info->Config = tdi["config"].asString(); + if (export_info->Config.empty()) { + export_info->Config = "noconfig"; + } + Json::Value const& tdi_exports = tdi["exports"]; + if (tdi_exports.isArray()) { + for (auto const& tdi_export : tdi_exports) { + CxxModuleExport exp; + exp.Install = tdi_export["install"].asBool(); + exp.Name = tdi_export["export-name"].asString(); + exp.Destination = tdi_export["destination"].asString(); + exp.Prefix = tdi_export["export-prefix"].asString(); + exp.CxxModuleInfoDir = tdi_export["cxx-module-info-dir"].asString(); + exp.Namespace = tdi_export["namespace"].asString(); + + export_info->Exports.push_back(exp); + } + } + auto const& bmi_installation = tdi["bmi-installation"]; + if (bmi_installation.isObject()) { + CxxModuleBmiInstall bmi_install; + + bmi_install.Component = bmi_installation["component"].asString(); + bmi_install.Destination = bmi_installation["destination"].asString(); + bmi_install.ExcludeFromAll = bmi_installation["exclude-from-all"].asBool(); + bmi_install.Optional = bmi_installation["optional"].asBool(); + bmi_install.Permissions = bmi_installation["permissions"].asString(); + bmi_install.MessageLevel = bmi_installation["message-level"].asString(); + bmi_install.ScriptLocation = + bmi_installation["script-location"].asString(); + + export_info->BmiInstallation = bmi_install; + } + Json::Value const& tdi_cxx_modules = tdi["cxx-modules"]; + if (tdi_cxx_modules.isObject()) { + for (auto i = tdi_cxx_modules.begin(); i != tdi_cxx_modules.end(); ++i) { + CxxModuleFileSet& fsi = export_info->ObjectToFileSet[i.key().asString()]; + auto const& tdi_cxx_module_info = *i; + fsi.Name = tdi_cxx_module_info["name"].asString(); + fsi.RelativeDirectory = + tdi_cxx_module_info["relative-directory"].asString(); + fsi.SourcePath = tdi_cxx_module_info["source"].asString(); + fsi.Type = tdi_cxx_module_info["type"].asString(); + fsi.Visibility = cmFileSetVisibilityFromName( + tdi_cxx_module_info["visibility"].asString(), nullptr); + auto const& tdi_fs_dest = tdi_cxx_module_info["destination"]; + if (tdi_fs_dest.isString()) { + fsi.Destination = tdi_fs_dest.asString(); + } + } + } + + return export_info; +} diff --git a/Source/cmDyndepCollation.h b/Source/cmDyndepCollation.h index 088a3a0..5f78707 100644 --- a/Source/cmDyndepCollation.h +++ b/Source/cmDyndepCollation.h @@ -5,7 +5,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include +#include #include +#include + +#include + +#include "cmFileSet.h" class cmGeneratorTarget; class cmSourceFile; @@ -20,10 +27,52 @@ struct cmDyndepGeneratorCallbacks ObjectFilePath; }; +struct CxxModuleFileSet +{ + std::string Name; + std::string RelativeDirectory; + std::string SourcePath; + std::string Type; + cmFileSetVisibility Visibility; + cm::optional Destination; +}; + +struct CxxModuleBmiInstall +{ + std::string Component; + std::string Destination; + bool ExcludeFromAll; + bool Optional; + std::string Permissions; + std::string MessageLevel; + std::string ScriptLocation; +}; + +struct CxxModuleExport +{ + std::string Name; + std::string Destination; + std::string Prefix; + std::string CxxModuleInfoDir; + std::string Namespace; + bool Install; +}; + +struct cmCxxModuleExportInfo +{ + std::map ObjectToFileSet; + cm::optional BmiInstallation; + std::vector Exports; + std::string Config; +}; + struct cmDyndepCollation { static void AddCollationInformation(Json::Value& tdi, cmGeneratorTarget const* gt, std::string const& config, cmDyndepGeneratorCallbacks const& cb); + + static std::unique_ptr ParseExportInfo( + Json::Value const& tdi); }; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 618dfb7..cd8d9d5 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -25,6 +25,7 @@ #include "cmsys/FStream.hxx" #include "cmCxxModuleMapper.h" +#include "cmDyndepCollation.h" #include "cmFileSet.h" #include "cmFortranParser.h" #include "cmGeneratedFileStream.h" @@ -2468,45 +2469,6 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( } } -struct CxxModuleFileSet -{ - std::string Name; - std::string RelativeDirectory; - std::string SourcePath; - std::string Type; - cmFileSetVisibility Visibility; - cm::optional Destination; -}; - -struct CxxModuleBmiInstall -{ - std::string Component; - std::string Destination; - bool ExcludeFromAll; - bool Optional; - std::string Permissions; - std::string MessageLevel; - std::string ScriptLocation; -}; - -struct CxxModuleExport -{ - std::string Name; - std::string Destination; - std::string Prefix; - std::string CxxModuleInfoDir; - std::string Namespace; - bool Install; -}; - -struct cmGlobalNinjaGenerator::CxxModuleExportInfo -{ - std::map ObjectToFileSet; - cm::optional BmiInstallation; - std::vector Exports; - std::string Config; -}; - bool cmGlobalNinjaGenerator::WriteDyndepFile( std::string const& dir_top_src, std::string const& dir_top_bld, std::string const& dir_cur_src, std::string const& dir_cur_bld, @@ -2514,7 +2476,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( std::string const& module_dir, std::vector const& linked_target_dirs, std::string const& arg_lang, std::string const& arg_modmapfmt, - CxxModuleExportInfo const& export_info) + cmCxxModuleExportInfo const& export_info) { // Setup path conversions. { @@ -3095,58 +3057,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector::const_iterator argBeg, } } - cmGlobalNinjaGenerator::CxxModuleExportInfo export_info; - export_info.Config = tdi["config"].asString(); - if (export_info.Config.empty()) { - export_info.Config = "noconfig"; - } - Json::Value const& tdi_exports = tdi["exports"]; - if (tdi_exports.isArray()) { - for (auto const& tdi_export : tdi_exports) { - CxxModuleExport exp; - exp.Install = tdi_export["install"].asBool(); - exp.Name = tdi_export["export-name"].asString(); - exp.Destination = tdi_export["destination"].asString(); - exp.Prefix = tdi_export["export-prefix"].asString(); - exp.CxxModuleInfoDir = tdi_export["cxx-module-info-dir"].asString(); - exp.Namespace = tdi_export["namespace"].asString(); - - export_info.Exports.push_back(exp); - } - } - auto const& bmi_installation = tdi["bmi-installation"]; - if (bmi_installation.isObject()) { - CxxModuleBmiInstall bmi_install; - - bmi_install.Component = bmi_installation["component"].asString(); - bmi_install.Destination = bmi_installation["destination"].asString(); - bmi_install.ExcludeFromAll = bmi_installation["exclude-from-all"].asBool(); - bmi_install.Optional = bmi_installation["optional"].asBool(); - bmi_install.Permissions = bmi_installation["permissions"].asString(); - bmi_install.MessageLevel = bmi_installation["message-level"].asString(); - bmi_install.ScriptLocation = - bmi_installation["script-location"].asString(); - - export_info.BmiInstallation = bmi_install; - } - Json::Value const& tdi_cxx_modules = tdi["cxx-modules"]; - if (tdi_cxx_modules.isObject()) { - for (auto i = tdi_cxx_modules.begin(); i != tdi_cxx_modules.end(); ++i) { - CxxModuleFileSet& fsi = export_info.ObjectToFileSet[i.key().asString()]; - auto const& tdi_cxx_module_info = *i; - fsi.Name = tdi_cxx_module_info["name"].asString(); - fsi.RelativeDirectory = - tdi_cxx_module_info["relative-directory"].asString(); - fsi.SourcePath = tdi_cxx_module_info["source"].asString(); - fsi.Type = tdi_cxx_module_info["type"].asString(); - fsi.Visibility = cmFileSetVisibilityFromName( - tdi_cxx_module_info["visibility"].asString(), nullptr); - auto const& tdi_fs_dest = tdi_cxx_module_info["destination"]; - if (tdi_fs_dest.isString()) { - fsi.Destination = tdi_fs_dest.asString(); - } - } - } + auto export_info = cmDyndepCollation::ParseExportInfo(tdi); cmake cm(cmake::RoleInternal, cmState::Unknown); cm.SetHomeDirectory(dir_top_src); @@ -3156,7 +3067,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector::const_iterator argBeg, !cm::static_reference_cast(ggd).WriteDyndepFile( dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, arg_dd, arg_ddis, module_dir, linked_target_dirs, arg_lang, arg_modmapfmt, - export_info)) { + *export_info)) { return 1; } return 0; diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 6f654f6..775e792 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -35,6 +35,7 @@ class cmMakefile; class cmOutputConverter; class cmStateDirectory; class cmake; +struct cmCxxModuleExportInfo; /** * \class cmGlobalNinjaGenerator @@ -417,7 +418,6 @@ public: bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); } void StripNinjaOutputPathPrefixAsSuffix(std::string& path); - struct CxxModuleExportInfo; bool WriteDyndepFile( std::string const& dir_top_src, std::string const& dir_top_bld, std::string const& dir_cur_src, std::string const& dir_cur_bld, @@ -425,7 +425,7 @@ public: std::string const& module_dir, std::vector const& linked_target_dirs, std::string const& arg_lang, std::string const& arg_modmapfmt, - CxxModuleExportInfo const& export_info); + cmCxxModuleExportInfo const& export_info); virtual std::string BuildAlias(const std::string& alias, const std::string& /*config*/) const -- cgit v0.12