diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-05-14 21:24:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-05-18 12:34:31 (GMT) |
commit | 18f87c87f86473dd2106b6d8ab7acc9def99b9b1 (patch) | |
tree | aab3ae4f9f7487eabccd2ffaa679e8ff18669c8f /Source/cmGlobalNinjaGenerator.cxx | |
parent | 56f7d6f827290dd7d4d5c6edf0fe12568d4a819e (diff) | |
download | CMake-18f87c87f86473dd2106b6d8ab7acc9def99b9b1.zip CMake-18f87c87f86473dd2106b6d8ab7acc9def99b9b1.tar.gz CMake-18f87c87f86473dd2106b6d8ab7acc9def99b9b1.tar.bz2 |
cmCxxModuleMapper: track whether modules are private or not
This allows collation to give a useful error message when it finds usage
of a private module rather than collation just not informing the
compilation and the compiler erroring out about not being able to import
unknown modules (which exists, but it was not told about due to
visibility).
Fixes: #24652
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 7626fa3..21d1e6d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -2526,7 +2526,12 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( CxxModuleUsage usages; // Map from module name to module file path, if known. - std::map<std::string, std::string> mod_files; + struct AvailableModuleInfo + { + std::string BmiPath; + bool IsPrivate; + }; + std::map<std::string, AvailableModuleInfo> mod_files; // Populate the module map with those provided by linked targets first. for (std::string const& linked_target_dir : linked_target_dirs) { @@ -2550,7 +2555,15 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( Json::Value const& target_modules = ltm["modules"]; if (target_modules.isObject()) { for (auto i = target_modules.begin(); i != target_modules.end(); ++i) { - mod_files[i.key().asString()] = i->asString(); + Json::Value const& visible_module = *i; + if (visible_module.isObject()) { + Json::Value const& bmi_path = visible_module["bmi"]; + Json::Value const& is_private = visible_module["is-private"]; + mod_files[i.key().asString()] = AvailableModuleInfo{ + bmi_path.asString(), + is_private.asBool(), + }; + } } } Json::Value const& target_modules_references = ltm["references"]; @@ -2631,8 +2644,15 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( cmSystemTools::ReplaceString(safe_logical_name, ":", "-"); mod = cmStrCat(module_dir, safe_logical_name, module_ext); } - mod_files[p.LogicalName] = mod; - target_modules[p.LogicalName] = mod; + mod_files[p.LogicalName] = AvailableModuleInfo{ + mod, + false, // Always visible within our own target. + }; + Json::Value& module_info = target_modules[p.LogicalName] = + Json::objectValue; + module_info["bmi"] = mod; + module_info["is-private"] = + cmDyndepCollation::IsObjectPrivate(object.PrimaryOutput, export_info); } } @@ -2652,12 +2672,15 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( return path; }; locs.BmiLocationForModule = - [&mod_files](std::string const& logical) -> cm::optional<std::string> { + [&mod_files](std::string const& logical) -> CxxBmiLocation { auto m = mod_files.find(logical); if (m != mod_files.end()) { - return m->second; + if (m->second.IsPrivate) { + return CxxBmiLocation::Private(); + } + return CxxBmiLocation::Known(m->second.BmiPath); } - return {}; + return CxxBmiLocation::Unknown(); }; // Insert information about the current target's modules. @@ -2679,13 +2702,14 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( build.ImplicitOuts.clear(); for (auto const& p : object.Provides) { build.ImplicitOuts.push_back( - this->ConvertToNinjaPath(mod_files[p.LogicalName])); + this->ConvertToNinjaPath(mod_files[p.LogicalName].BmiPath)); } build.ImplicitDeps.clear(); for (auto const& r : object.Requires) { auto mit = mod_files.find(r.LogicalName); if (mit != mod_files.end()) { - build.ImplicitDeps.push_back(this->ConvertToNinjaPath(mit->second)); + build.ImplicitDeps.push_back( + this->ConvertToNinjaPath(mit->second.BmiPath)); } } build.Variables.clear(); @@ -2751,7 +2775,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( [mod_files](std::string const& name) -> cm::optional<std::string> { auto m = mod_files.find(name); if (m != mod_files.end()) { - return m->second; + return m->second.BmiPath; } return {}; }; |