feat(daemon): report per-target metadata on request
This commit is contained in:
1 parent
cf06b427b7
commit
3a3376c331
8 files changed
+154
-3
No files matched your search
+61
-1
@@ -1128,6 +1128,54 @@ std::string compdb_generations_project(const DaemonOptions &options,
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
// Reports one target's metadata (kind, sources, outputs, runtime libraries) from the lowered graph.
|
||||
std::string target_info_project(const DaemonOptions &options, std::string_view profile_name,
|
||||
std::optional<CompilerFamily> compiler_override,
|
||||
std::string_view target_name, std::string_view member) {
|
||||
auto effective_result = resolve_member_options(options, member);
|
||||
if (!effective_result) {
|
||||
return error_response(std::format("target_info: {}", effective_result.error()));
|
||||
}
|
||||
auto evaluated =
|
||||
evaluate_project_graph(*effective_result, profile_name, compiler_override, "target_info");
|
||||
if (!evaluated) {
|
||||
return error_response(evaluated.error());
|
||||
}
|
||||
auto graph = lower_graph(*effective_result, *evaluated, {}, "target_info");
|
||||
if (!graph) {
|
||||
return error_response(graph.error());
|
||||
}
|
||||
|
||||
const auto target =
|
||||
std::ranges::find_if(graph->targets, [&](const Graph::ResolvedTargetSummary &node) {
|
||||
return node.name == target_name;
|
||||
});
|
||||
if (target == graph->targets.end()) {
|
||||
return error_response(std::format("target_info: unknown target '{}'", target_name));
|
||||
}
|
||||
|
||||
const auto path_array = [](const std::vector<std::filesystem::path> &paths) {
|
||||
JsonValue::Array array;
|
||||
array.reserve(paths.size());
|
||||
for (const auto &path : paths) {
|
||||
array.emplace_back(path.string());
|
||||
}
|
||||
return array;
|
||||
};
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"target_info"}});
|
||||
object.emplace("profile", JsonValue{evaluated->context.name});
|
||||
object.emplace("name", JsonValue{target->name});
|
||||
object.emplace("kind", JsonValue{std::string{target_kind_name(target->kind)}});
|
||||
object.emplace("enabled", JsonValue{target->enabled});
|
||||
object.emplace("sources", JsonValue{path_array(target->expanded_sources)});
|
||||
object.emplace("primary_outputs", JsonValue{path_array(target->primary_outputs)});
|
||||
object.emplace("runtime_shared_libraries",
|
||||
JsonValue{path_array(target->runtime_shared_libraries)});
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
// Reports which editor configuration files are present for the project.
|
||||
std::string ide_configs_project(const DaemonOptions &options) {
|
||||
struct ConfigEntry {
|
||||
@@ -1803,7 +1851,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
}
|
||||
if (*name == "describe" || *name == "build" || *name == "test" || *name == "ide_query" ||
|
||||
*name == "ide_generate" || *name == "compdb_export" || *name == "graph" ||
|
||||
*name == "deps") {
|
||||
*name == "deps" || *name == "target_info") {
|
||||
std::string profile_name{"debug"};
|
||||
if (const auto entry = object->find("profile"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
@@ -1850,6 +1898,18 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "deps") {
|
||||
return {deps_project(options, profile_name, compiler_override, member), false};
|
||||
}
|
||||
if (*name == "target_info") {
|
||||
const auto entry = object->find("target");
|
||||
if (entry == object->end()) {
|
||||
return {error_response("target_info requires \"target\""), false};
|
||||
}
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
if (value == nullptr || value->empty() || value->size() > kMaxDescribeTargetNameBytes) {
|
||||
return {error_response("\"target\" must be a bounded non-empty string"), false};
|
||||
}
|
||||
return {target_info_project(options, profile_name, compiler_override, *value, member),
|
||||
false};
|
||||
}
|
||||
if (*name == "graph") {
|
||||
std::string graph_format{"dot"};
|
||||
if (const auto entry = object->find("format"); entry != object->end()) {
|
||||
|
||||
Reference in new issue
Block a user