1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDyndepCollation.h"
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cm/memory>
#include <cm/string_view>
#include <cmext/string_view>
#include <cm3p/json/value.h>
#include "cmExportBuildFileGenerator.h"
#include "cmExportSet.h"
#include "cmFileSet.h"
#include "cmGeneratorExpression.h" // IWYU pragma: keep
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmInstallCxxModuleBmiGenerator.h"
#include "cmInstallExportGenerator.h"
#include "cmInstallFileSetGenerator.h"
#include "cmInstallGenerator.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmSourceFile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetExport.h"
namespace {
Json::Value CollationInformationCxxModules(
cmGeneratorTarget const* gt, std::string const& config,
cmDyndepGeneratorCallbacks const& cb)
{
cmTarget const* tgt = gt->Target;
auto all_file_sets = tgt->GetAllFileSetNames();
Json::Value tdi_cxx_module_info = Json::objectValue;
for (auto const& file_set_name : all_file_sets) {
auto const* file_set = tgt->GetFileSet(file_set_name);
if (!file_set) {
gt->Makefile->IssueMessage(MessageType::INTERNAL_ERROR,
cmStrCat("Target \"", tgt->GetName(),
"\" is tracked to have file set \"",
file_set_name,
"\", but it was not found."));
continue;
}
auto fs_type = file_set->GetType();
// We only care about C++ module sources here.
if (fs_type != "CXX_MODULES"_s) {
continue;
}
auto fileEntries = file_set->CompileFileEntries();
auto directoryEntries = file_set->CompileDirectoryEntries();
auto directories = file_set->EvaluateDirectoryEntries(
directoryEntries, gt->LocalGenerator, config, gt);
std::map<std::string, std::vector<std::string>> files_per_dirs;
for (auto const& entry : fileEntries) {
file_set->EvaluateFileEntry(directories, files_per_dirs, entry,
gt->LocalGenerator, config, gt);
}
std::map<std::string, cmSourceFile const*> sf_map;
{
std::vector<cmSourceFile const*> objectSources;
gt->GetObjectSources(objectSources, config);
for (auto const* sf : objectSources) {
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."));
continue;
}
sf_map[full_path] = sf;
}
}
Json::Value fs_dest = Json::nullValue;
for (auto const& ig : gt->Makefile->GetInstallGenerators()) {
if (auto const* fsg =
dynamic_cast<cmInstallFileSetGenerator const*>(ig.get())) {
if (fsg->GetTarget() == gt && fsg->GetFileSet() == file_set) {
fs_dest = fsg->GetDestination(config);
continue;
}
}
}
for (auto const& files_per_dir : files_per_dirs) {
for (auto const& file : files_per_dir.second) {
auto lookup = sf_map.find(file);
if (lookup == sf_map.end()) {
gt->Makefile->IssueMessage(
MessageType::INTERNAL_ERROR,
cmStrCat("Target \"", tgt->GetName(), "\" has source file \"",
file,
R"(" which is not in any of its "FILE_SET BASE_DIRS".)"));
continue;
}
auto const* sf = lookup->second;
if (!sf) {
gt->Makefile->IssueMessage(
MessageType::INTERNAL_ERROR,
cmStrCat("Target \"", tgt->GetName(), "\" has source file \"",
file, "\" which has not been tracked properly."));
continue;
}
auto obj_path = cb.ObjectFilePath(sf, config);
Json::Value& tdi_module_info = tdi_cxx_module_info[obj_path] =
Json::objectValue;
tdi_module_info["source"] = file;
tdi_module_info["relative-directory"] = files_per_dir.first;
tdi_module_info["name"] = file_set->GetName();
tdi_module_info["type"] = file_set->GetType();
tdi_module_info["visibility"] =
std::string(cmFileSetVisibilityToName(file_set->GetVisibility()));
tdi_module_info["destination"] = fs_dest;
}
}
}
return tdi_cxx_module_info;
}
Json::Value CollationInformationBmiInstallation(cmGeneratorTarget const* gt,
std::string const& config)
{
cmInstallCxxModuleBmiGenerator const* bmi_gen = nullptr;
for (auto const& ig : gt->Makefile->GetInstallGenerators()) {
if (auto const* bmig =
dynamic_cast<cmInstallCxxModuleBmiGenerator const*>(ig.get())) {
if (bmig->GetTarget() == gt) {
bmi_gen = bmig;
continue;
}
}
}
if (bmi_gen) {
Json::Value tdi_bmi_info = Json::objectValue;
tdi_bmi_info["permissions"] = bmi_gen->GetFilePermissions();
tdi_bmi_info["destination"] = bmi_gen->GetDestination(config);
const char* msg_level = "";
switch (bmi_gen->GetMessageLevel()) {
case cmInstallGenerator::MessageDefault:
break;
case cmInstallGenerator::MessageAlways:
msg_level = "MESSAGE_ALWAYS";
break;
case cmInstallGenerator::MessageLazy:
msg_level = "MESSAGE_LAZY";
break;
case cmInstallGenerator::MessageNever:
msg_level = "MESSAGE_NEVER";
break;
}
tdi_bmi_info["message-level"] = msg_level;
tdi_bmi_info["script-location"] = bmi_gen->GetScriptLocation(config);
return tdi_bmi_info;
}
return Json::nullValue;
}
Json::Value CollationInformationExports(cmGeneratorTarget const* gt)
{
Json::Value tdi_exports = Json::arrayValue;
std::string export_name = gt->GetExportName();
auto const& all_install_exports = gt->GetGlobalGenerator()->GetExportSets();
for (auto const& exp : all_install_exports) {
// Ignore exports sets which are not for this target.
auto const& targets = exp.second.GetTargetExports();
auto tgt_export =
std::find_if(targets.begin(), targets.end(),
[gt](std::unique_ptr<cmTargetExport> const& te) {
return te->Target == gt;
});
if (tgt_export == targets.end()) {
continue;
}
auto const* installs = exp.second.GetInstallations();
for (auto const* install : *installs) {
Json::Value tdi_export_info = Json::objectValue;
auto const& ns = install->GetNamespace();
auto const& dest = install->GetDestination();
auto const& cxxm_dir = install->GetCxxModuleDirectory();
auto const& export_prefix = install->GetTempDir();
tdi_export_info["namespace"] = ns;
tdi_export_info["export-name"] = export_name;
tdi_export_info["destination"] = dest;
tdi_export_info["cxx-module-info-dir"] = cxxm_dir;
tdi_export_info["export-prefix"] = export_prefix;
tdi_export_info["install"] = true;
tdi_exports.append(tdi_export_info);
}
}
auto const& all_build_exports = gt->Makefile->GetExportBuildFileGenerators();
for (auto const& exp : all_build_exports) {
std::vector<std::string> targets;
exp->GetTargets(targets);
// Ignore exports sets which are not for this target.
auto const& name = gt->GetName();
bool has_current_target =
std::any_of(targets.begin(), targets.end(),
[name](std::string const& tname) { return tname == name; });
if (!has_current_target) {
continue;
}
Json::Value tdi_export_info = Json::objectValue;
auto const& ns = exp->GetNamespace();
auto const& main_fn = exp->GetMainExportFileName();
auto const& cxxm_dir = exp->GetCxxModuleDirectory();
auto dest = cmsys::SystemTools::GetParentDirectory(main_fn);
auto const& export_prefix =
cmSystemTools::GetFilenamePath(exp->GetMainExportFileName());
tdi_export_info["namespace"] = ns;
tdi_export_info["export-name"] = export_name;
tdi_export_info["destination"] = dest;
tdi_export_info["cxx-module-info-dir"] = cxxm_dir;
tdi_export_info["export-prefix"] = export_prefix;
tdi_export_info["install"] = false;
tdi_exports.append(tdi_export_info);
}
return tdi_exports;
}
}
void cmDyndepCollation::AddCollationInformation(
Json::Value& tdi, cmGeneratorTarget const* gt, std::string const& config,
cmDyndepGeneratorCallbacks const& cb)
{
tdi["cxx-modules"] = CollationInformationCxxModules(gt, config, cb);
tdi["bmi-installation"] = CollationInformationBmiInstallation(gt, config);
tdi["exports"] = CollationInformationExports(gt);
tdi["config"] = config;
}
std::unique_ptr<cmCxxModuleExportInfo> cmDyndepCollation::ParseExportInfo(
Json::Value const& tdi)
{
auto export_info = cm::make_unique<cmCxxModuleExportInfo>();
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;
}
|