diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2022-06-13 20:38:55 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2022-07-06 15:37:51 (GMT) |
commit | f899563ae45972a3894c78a447d0767e86056b81 (patch) | |
tree | f2308b5504611981c4a17511397c0debb8c1a169 /Source/cmGlobalNinjaGenerator.cxx | |
parent | 9ecd3e771b0dbdbfcfa035f5d2b0383a5b739014 (diff) | |
download | CMake-f899563ae45972a3894c78a447d0767e86056b81.zip CMake-f899563ae45972a3894c78a447d0767e86056b81.tar.gz CMake-f899563ae45972a3894c78a447d0767e86056b81.tar.bz2 |
cmGlobalNinjaGenerator: verify that private sources stay private
Private source files are not installed or made available, so they must
not be required by public module interface units at all.
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index f55e58f..b4d5746 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -2726,6 +2726,10 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( cmStrCat("${_IMPORT_PREFIX}/", cmEscape(dest))); }; + // public/private requirement tracking. + std::set<std::string> private_modules; + std::map<std::string, std::set<std::string>> public_source_requires; + for (cmScanDepInfo const& object : objects) { // Convert to forward slashes. auto output_path = object.PrimaryOutput; @@ -2811,9 +2815,20 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( if (!cmFileSetVisibilityIsForInterface(file_set.Visibility)) { // Nothing needs to be conveyed about non-`PUBLIC` modules. + for (auto const& p : object.Provides) { + private_modules.insert(p.LogicalName); + } continue; } + // The module is public. Record what it directly requires. + { + auto& reqs = public_source_requires[file_set.SourcePath]; + for (auto const& r : object.Requires) { + reqs.insert(r.LogicalName); + } + } + // Write out properties and install rules for any exports. for (auto const& p : object.Provides) { bool bmi_dest_is_abs = false; @@ -2921,6 +2936,18 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( for (auto const& exp : exports) { *exp.first << ")\n"; } + + // Check that public sources only require public modules. + for (auto const& pub_reqs : public_source_requires) { + for (auto const& req : pub_reqs.second) { + if (private_modules.count(req)) { + cmSystemTools::Error(cmStrCat( + "Public C++ module source `", pub_reqs.first, "` requires the `", + req, "` C++ module which is provided by a private source")); + result = false; + } + } + } } return result; |