cmDyndepCollation: write out scanned source information too

This is required to fill in the `requires` field for sources using
modules that do not provide them.
This commit is contained in:
Ben Boeckel
2024-03-25 07:30:04 -04:00
parent 48faa19c19
commit 9c0491a3e4
9 changed files with 137 additions and 47 deletions

View File

@@ -39,13 +39,55 @@
namespace {
Json::Value CollationInformationCxxModules(
cmGeneratorTarget const* gt, std::string const& config,
cmDyndepGeneratorCallbacks const& cb)
struct TdiSourceInfo
{
Json::Value Sources;
Json::Value CxxModules;
};
TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt,
std::string const& config,
cmDyndepGeneratorCallbacks const& cb)
{
TdiSourceInfo info;
cmTarget const* tgt = gt->Target;
auto all_file_sets = tgt->GetAllFileSetNames();
Json::Value tdi_cxx_module_info = Json::objectValue;
Json::Value& tdi_sources = info.Sources = Json::objectValue;
Json::Value& tdi_cxx_module_info = info.CxxModules = Json::objectValue;
enum class CompileType
{
ObjectAndBmi,
BmiOnly,
};
std::map<std::string, std::pair<cmSourceFile const*, CompileType>> sf_map;
{
auto fill_sf_map = [gt, tgt, &sf_map](cmSourceFile const* sf,
CompileType type) {
auto full_path = sf->GetFullPath();
if (full_path.empty()) {
gt->Makefile->IssueMessage(
MessageType::INTERNAL_ERROR,
cmStrCat("Target \"", tgt->GetName(),
"\" has a full path-less source file."));
return;
}
sf_map[full_path] = std::make_pair(sf, type);
};
std::vector<cmSourceFile const*> objectSources;
gt->GetObjectSources(objectSources, config);
for (auto const* sf : objectSources) {
fill_sf_map(sf, CompileType::ObjectAndBmi);
}
std::vector<cmSourceFile const*> cxxModuleSources;
gt->GetCxxModuleSources(cxxModuleSources, config);
for (auto const* sf : cxxModuleSources) {
fill_sf_map(sf, CompileType::BmiOnly);
}
}
for (auto const& file_set_name : all_file_sets) {
auto const* file_set = tgt->GetFileSet(file_set_name);
if (!file_set) {
@@ -73,39 +115,6 @@ Json::Value CollationInformationCxxModules(
gt->LocalGenerator, config, gt);
}
enum class CompileType
{
ObjectAndBmi,
BmiOnly,
};
std::map<std::string, std::pair<cmSourceFile const*, CompileType>> sf_map;
{
auto fill_sf_map = [gt, tgt, &sf_map](cmSourceFile const* sf,
CompileType type) {
auto full_path = sf->GetFullPath();
if (full_path.empty()) {
gt->Makefile->IssueMessage(
MessageType::INTERNAL_ERROR,
cmStrCat("Target \"", tgt->GetName(),
"\" has a full path-less source file."));
return;
}
sf_map[full_path] = std::make_pair(sf, type);
};
std::vector<cmSourceFile const*> objectSources;
gt->GetObjectSources(objectSources, config);
for (auto const* sf : objectSources) {
fill_sf_map(sf, CompileType::ObjectAndBmi);
}
std::vector<cmSourceFile const*> cxxModuleSources;
gt->GetCxxModuleSources(cxxModuleSources, config);
for (auto const* sf : cxxModuleSources) {
fill_sf_map(sf, CompileType::BmiOnly);
}
}
Json::Value fs_dest = Json::nullValue;
for (auto const& ig : gt->Makefile->GetInstallGenerators()) {
if (auto const* fsg =
@@ -134,6 +143,8 @@ Json::Value CollationInformationCxxModules(
auto const* sf = lookup->second.first;
CompileType const ct = lookup->second.second;
sf_map.erase(lookup);
if (!sf) {
gt->Makefile->IssueMessage(
MessageType::INTERNAL_ERROR,
@@ -160,7 +171,26 @@ Json::Value CollationInformationCxxModules(
}
}
return tdi_cxx_module_info;
for (auto const& sf_entry : sf_map) {
CompileType const ct = sf_entry.second.second;
if (ct == CompileType::BmiOnly) {
continue;
}
auto const* sf = sf_entry.second.first;
if (!gt->NeedDyndepForSource(sf->GetLanguage(), config, sf)) {
continue;
}
auto full_file = cmSystemTools::CollapseFullPath(sf->GetFullPath());
auto obj_path = cb.ObjectFilePath(sf, config);
Json::Value& tdi_source_info = tdi_sources[obj_path] = Json::objectValue;
tdi_source_info["source"] = full_file;
tdi_source_info["language"] = sf->GetLanguage();
}
return info;
}
Json::Value CollationInformationBmiInstallation(cmGeneratorTarget const* gt,
@@ -289,12 +319,20 @@ void cmDyndepCollation::AddCollationInformation(
Json::Value& tdi, cmGeneratorTarget const* gt, std::string const& config,
cmDyndepGeneratorCallbacks const& cb)
{
tdi["cxx-modules"] = CollationInformationCxxModules(gt, config, cb);
auto sourcesInfo = CollationInformationSources(gt, config, cb);
tdi["sources"] = sourcesInfo.Sources;
tdi["cxx-modules"] = sourcesInfo.CxxModules;
tdi["bmi-installation"] = CollationInformationBmiInstallation(gt, config);
tdi["exports"] = CollationInformationExports(gt);
tdi["config"] = config;
}
struct SourceInfo
{
std::string SourcePath;
std::string Language;
};
struct CxxModuleFileSet
{
std::string Name;
@@ -330,6 +368,7 @@ struct CxxModuleExport
struct cmCxxModuleExportInfo
{
std::map<std::string, SourceInfo> ObjectToSource;
std::map<std::string, CxxModuleFileSet> ObjectToFileSet;
cm::optional<CxxModuleBmiInstall> BmiInstallation;
std::vector<CxxModuleExport> Exports;
@@ -405,6 +444,15 @@ cmDyndepCollation::ParseExportInfo(Json::Value const& tdi)
}
}
}
Json::Value const& tdi_sources = tdi["sources"];
if (tdi_sources.isObject()) {
for (auto i = tdi_sources.begin(); i != tdi_sources.end(); ++i) {
SourceInfo& si = export_info->ObjectToSource[i.key().asString()];
auto const& tdi_source = *i;
si.SourcePath = tdi_source["source"].asString();
si.Language = tdi_source["language"].asString();
}
}
return export_info;
}

View File

@@ -47,5 +47,6 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-bmi-install-private.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-bmi-install-private.dir<CONFIG_DIR>",
"sources": {}
}

View File

@@ -47,5 +47,6 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-bmi-install-public.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-bmi-install-public.dir<CONFIG_DIR>",
"sources": {}
}

View File

@@ -79,5 +79,6 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-private.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-private.dir<CONFIG_DIR>",
"sources": {}
}

View File

@@ -79,5 +79,6 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-public.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-public.dir<CONFIG_DIR>",
"sources": {}
}

View File

@@ -79,5 +79,6 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-private.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-private.dir<CONFIG_DIR>",
"sources": {}
}

View File

@@ -79,5 +79,6 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-public.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-exports-public.dir<CONFIG_DIR>",
"sources": {}
}

View File

@@ -42,5 +42,23 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-file-sets-private.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-file-sets-private.dir<CONFIG_DIR>",
"sources": {
"CMakeFiles/ninja-file-sets-private.dir/sources/module-impl.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-impl.cxx"
},
"CMakeFiles/ninja-file-sets-private.dir/sources/module-internal-part-impl.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-internal-part-impl.cxx"
},
"CMakeFiles/ninja-file-sets-private.dir/sources/module-part-impl.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-part-impl.cxx"
},
"CMakeFiles/ninja-file-sets-private.dir/sources/module-use.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-use.cxx"
}
}
}

View File

@@ -42,5 +42,23 @@
"language": "CXX",
"forward-modules-from-target-dirs": [],
"linked-target-dirs": [],
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-file-sets-public.dir<CONFIG_DIR>"
"module-dir": "<BINARY_DIR>/CMakeFiles/ninja-file-sets-public.dir<CONFIG_DIR>",
"sources": {
"CMakeFiles/ninja-file-sets-public.dir/sources/module-impl.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-impl.cxx"
},
"CMakeFiles/ninja-file-sets-public.dir/sources/module-internal-part-impl.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-internal-part-impl.cxx"
},
"CMakeFiles/ninja-file-sets-public.dir/sources/module-part-impl.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-part-impl.cxx"
},
"CMakeFiles/ninja-file-sets-public.dir/sources/module-use.cxx<OBJEXT>" : {
"language" : "CXX",
"source" : "<SOURCE_DIR>/sources/module-use.cxx"
}
}
}