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()) {
|
||||
|
||||
@@ -1478,6 +1478,7 @@ struct DaemonCmdOptions {
|
||||
std::string editor_arg{"all"};
|
||||
std::optional<std::string> member_arg;
|
||||
std::string graph_format_arg{"dot"};
|
||||
std::optional<std::string> target_arg;
|
||||
std::optional<std::string> file_filter_arg;
|
||||
std::string limit_arg{"50"};
|
||||
std::string timeout_ms_arg{"2000"};
|
||||
@@ -1565,6 +1566,14 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
request_json = std::format(R"({{"op":"graph","profile":{},"format":{}}})",
|
||||
Util::json_quote(opts.profile_arg),
|
||||
Util::json_quote(opts.graph_format_arg));
|
||||
} else if (sub == "target_info") {
|
||||
if (!opts.target_arg || opts.target_arg->empty()) {
|
||||
std::cerr << "vbs daemon target: --name must not be empty\n";
|
||||
return 2;
|
||||
}
|
||||
request_json =
|
||||
std::format(R"({{"op":"target_info","profile":{},"target":{}}})",
|
||||
Util::json_quote(opts.profile_arg), Util::json_quote(*opts.target_arg));
|
||||
} else if (sub == "info") {
|
||||
request_json = R"({"op":"info"})";
|
||||
} else if (sub == "clean") {
|
||||
@@ -2704,6 +2713,14 @@ int main(int argc, char **argv) {
|
||||
.option_default("--profile", "-p", "Profile to resolve", daemon_opts.profile_arg, "debug")
|
||||
.option("--member", "", "Workspace member (required for workspace roots)",
|
||||
daemon_opts.member_arg);
|
||||
auto &daemon_target_cmd =
|
||||
daemon_cmd.subcommand("target", "Target metadata served by the daemon");
|
||||
auto &daemon_target_info_cmd = daemon_target_cmd.subcommand(
|
||||
"info", "Report one target's kind, sources, outputs, and runtime libraries");
|
||||
configure_daemon_common(daemon_target_info_cmd);
|
||||
daemon_target_info_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
||||
.option("--name", "-n", "Target name", daemon_opts.target_arg);
|
||||
auto &daemon_workspace_cmd =
|
||||
daemon_cmd.subcommand("workspace", "Workspace metadata served by the daemon");
|
||||
auto &daemon_workspace_members_cmd =
|
||||
@@ -2880,6 +2897,9 @@ int main(int argc, char **argv) {
|
||||
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "generations") {
|
||||
daemon_sub = "compdb_generations";
|
||||
} else if (daemon_sub == "target" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "info") {
|
||||
daemon_sub = "target_info";
|
||||
}
|
||||
return execute_daemon_command(daemon_sub, daemon_opts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user