feat(daemon,registry): list lowered actions and expose binary variant detail
This commit is contained in:
1 parent
69d1a8d274
commit
34fe148eb4
10 files changed
+252
-3
No files matched your search
+104
-1
@@ -68,6 +68,8 @@ constexpr std::size_t kMaxCompdbArguments = 256U;
|
||||
constexpr std::size_t kMaxCompdbArgumentBytes = 1024U;
|
||||
constexpr std::size_t kMaxCompdbEntries = 500U;
|
||||
constexpr std::size_t kMaxCompdbGenerations = 128U;
|
||||
constexpr std::size_t kMaxActionOutputs = 8U;
|
||||
constexpr std::size_t kMaxActionLimit = 1000U;
|
||||
constexpr std::size_t kMaxPendingChanges = 4096U;
|
||||
constexpr std::int64_t kMaxWatchWaitMs = 5000;
|
||||
constexpr std::int64_t kDefaultWatchWaitMs = 2000;
|
||||
@@ -1177,6 +1179,83 @@ std::string target_info_project(const DaemonOptions &options, std::string_view p
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
std::string_view action_kind_label(Graph::ActionKind kind) noexcept {
|
||||
switch (kind) {
|
||||
case Graph::ActionKind::Compile:
|
||||
return "compile";
|
||||
case Graph::ActionKind::PrecompiledHeader:
|
||||
return "pch";
|
||||
case Graph::ActionKind::HeaderUnit:
|
||||
return "header_unit";
|
||||
case Graph::ActionKind::ModuleScan:
|
||||
return "module_scan";
|
||||
case Graph::ActionKind::ModuleBmi:
|
||||
return "module_bmi";
|
||||
case Graph::ActionKind::Archive:
|
||||
return "archive";
|
||||
case Graph::ActionKind::Link:
|
||||
return "link";
|
||||
case Graph::ActionKind::Custom:
|
||||
return "custom";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
// Lists the lowered graph's actions (bounded) for editor extensions and diagnostics.
|
||||
std::string actions_project(const DaemonOptions &options, std::string_view profile_name,
|
||||
std::optional<CompilerFamily> compiler_override,
|
||||
std::string_view target_filter, std::size_t limit,
|
||||
std::string_view member) {
|
||||
auto effective_result = resolve_member_options(options, member);
|
||||
if (!effective_result) {
|
||||
return error_response(std::format("actions: {}", effective_result.error()));
|
||||
}
|
||||
auto evaluated =
|
||||
evaluate_project_graph(*effective_result, profile_name, compiler_override, "actions");
|
||||
if (!evaluated) {
|
||||
return error_response(evaluated.error());
|
||||
}
|
||||
auto graph = lower_graph(*effective_result, *evaluated, {}, "actions");
|
||||
if (!graph) {
|
||||
return error_response(graph.error());
|
||||
}
|
||||
|
||||
JsonValue::Array actions;
|
||||
std::size_t total = 0;
|
||||
for (const auto &action : graph->actions) {
|
||||
if (!target_filter.empty() && action.target_name != target_filter) {
|
||||
continue;
|
||||
}
|
||||
++total;
|
||||
if (actions.size() >= limit) {
|
||||
continue;
|
||||
}
|
||||
JsonValue::Object entry;
|
||||
entry.emplace("id", JsonValue{action.id});
|
||||
entry.emplace("kind", JsonValue{std::string{action_kind_label(action.kind)}});
|
||||
entry.emplace("target", JsonValue{action.target_name});
|
||||
entry.emplace("cacheable", JsonValue{action.cacheable});
|
||||
JsonValue::Array outputs;
|
||||
for (const auto &output : action.declared_outputs) {
|
||||
if (outputs.size() >= kMaxActionOutputs) {
|
||||
break;
|
||||
}
|
||||
outputs.emplace_back(output.string());
|
||||
}
|
||||
entry.emplace("outputs", JsonValue{std::move(outputs)});
|
||||
actions.emplace_back(std::move(entry));
|
||||
}
|
||||
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"actions"}});
|
||||
object.emplace("profile", JsonValue{evaluated->context.name});
|
||||
object.emplace("total", JsonValue{static_cast<std::int64_t>(total)});
|
||||
object.emplace("returned", JsonValue{static_cast<std::int64_t>(actions.size())});
|
||||
object.emplace("actions", JsonValue{std::move(actions)});
|
||||
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 {
|
||||
@@ -1880,7 +1959,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 == "target_info") {
|
||||
*name == "deps" || *name == "target_info" || *name == "actions") {
|
||||
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);
|
||||
@@ -1927,6 +2006,30 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "deps") {
|
||||
return {deps_project(options, profile_name, compiler_override, member), false};
|
||||
}
|
||||
if (*name == "actions") {
|
||||
std::string target_filter;
|
||||
if (const auto entry = object->find("target"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
if (value == nullptr || value->size() > kMaxDescribeTargetNameBytes) {
|
||||
return {error_response("\"target\" must be a bounded string"), false};
|
||||
}
|
||||
target_filter = *value;
|
||||
}
|
||||
std::size_t limit = 100;
|
||||
if (const auto entry = object->find("limit"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::int64_t>(&entry->second.value);
|
||||
if (value == nullptr || *value < 0 ||
|
||||
*value > static_cast<std::int64_t>(kMaxActionLimit)) {
|
||||
return {error_response(std::format("\"limit\" must be an integer in [0, {}]",
|
||||
kMaxActionLimit)),
|
||||
false};
|
||||
}
|
||||
limit = static_cast<std::size_t>(*value);
|
||||
}
|
||||
return {actions_project(options, profile_name, compiler_override, target_filter, limit,
|
||||
member),
|
||||
false};
|
||||
}
|
||||
if (*name == "target_info") {
|
||||
const auto entry = object->find("target");
|
||||
if (entry == object->end()) {
|
||||
|
||||
@@ -1567,6 +1567,9 @@ 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 == "actions") {
|
||||
request_json = std::format(R"({{"op":"actions","profile":{},"limit":{}}})",
|
||||
Util::json_quote(opts.profile_arg), opts.limit_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";
|
||||
@@ -2736,6 +2739,13 @@ int main(int argc, char **argv) {
|
||||
auto &daemon_workspace_members_cmd =
|
||||
daemon_workspace_cmd.subcommand("members", "List declared workspace members");
|
||||
configure_daemon_common(daemon_workspace_members_cmd);
|
||||
auto &daemon_actions_cmd =
|
||||
daemon_cmd.subcommand("actions", "List lowered build actions via the daemon");
|
||||
configure_daemon_common(daemon_actions_cmd);
|
||||
daemon_actions_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
||||
.option_default("--limit", "", "Maximum actions returned (0-1000)", daemon_opts.limit_arg,
|
||||
"100");
|
||||
auto &daemon_graph_cmd =
|
||||
daemon_cmd.subcommand("graph", "Export the target dependency graph via the daemon");
|
||||
configure_daemon_common(daemon_graph_cmd);
|
||||
|
||||
Reference in new issue
Block a user