feat(daemon): report per-unit compile arguments; deepen registry search tests
This commit is contained in:
1 parent
2b18a0331a
commit
624016d904
9 files changed
+335
-27
No files matched your search
+115
-26
@@ -1194,6 +1194,102 @@ std::string compdb_generations_project(const DaemonOptions &options,
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
// Reports the bounded compile arguments of one target's compilation units.
|
||||
std::string target_flags_project(const DaemonOptions &options, std::string_view profile_name,
|
||||
std::optional<CompilerFamily> compiler_override,
|
||||
std::string_view target_name, std::string_view file_filter,
|
||||
std::string_view member) {
|
||||
auto effective_result = resolve_member_options(options, member);
|
||||
if (!effective_result) {
|
||||
return error_response(std::format("target_flags: {}", effective_result.error()));
|
||||
}
|
||||
auto evaluated =
|
||||
evaluate_project_graph(*effective_result, profile_name, compiler_override, "target_flags");
|
||||
if (!evaluated) {
|
||||
return error_response(evaluated.error());
|
||||
}
|
||||
auto graph = lower_graph(*effective_result, *evaluated, {}, "target_flags");
|
||||
if (!graph) {
|
||||
return error_response(graph.error());
|
||||
}
|
||||
if (std::ranges::none_of(
|
||||
graph->targets,
|
||||
[&](const Graph::ResolvedTargetSummary &node) { return node.name == target_name; })) {
|
||||
return error_response(std::format("target_flags: unknown target '{}'", target_name));
|
||||
}
|
||||
|
||||
const auto bounded_strings = [](const std::vector<std::string> &values) {
|
||||
JsonValue::Array array;
|
||||
for (const auto &value : values) {
|
||||
if (array.size() >= kMaxCompdbArguments) {
|
||||
break;
|
||||
}
|
||||
array.emplace_back(value.size() > kMaxCompdbArgumentBytes
|
||||
? value.substr(0, kMaxCompdbArgumentBytes)
|
||||
: value);
|
||||
}
|
||||
return array;
|
||||
};
|
||||
|
||||
JsonValue::Array units;
|
||||
for (const auto &action : graph->actions) {
|
||||
if (action.kind != Graph::ActionKind::Compile &&
|
||||
action.kind != Graph::ActionKind::PrecompiledHeader &&
|
||||
action.kind != Graph::ActionKind::HeaderUnit) {
|
||||
continue;
|
||||
}
|
||||
if (action.target_name != target_name) {
|
||||
continue;
|
||||
}
|
||||
const std::string source = action.logical_source_file.string();
|
||||
if (!file_filter.empty() && !std::string_view{source}.ends_with(file_filter)) {
|
||||
continue;
|
||||
}
|
||||
if (units.size() >= kMaxActionLimit) {
|
||||
break;
|
||||
}
|
||||
JsonValue::Object unit;
|
||||
unit.emplace("source", JsonValue{source});
|
||||
unit.emplace("kind", JsonValue{std::string{action_kind_label(action.kind)}});
|
||||
unit.emplace("is_c_source", JsonValue{action.is_c_source});
|
||||
unit.emplace("arguments", JsonValue{bounded_strings(action.arguments)});
|
||||
unit.emplace("defines", JsonValue{bounded_strings(action.defines)});
|
||||
unit.emplace("compile_options", JsonValue{bounded_strings(action.compile_options)});
|
||||
units.emplace_back(std::move(unit));
|
||||
}
|
||||
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"target_flags"}});
|
||||
object.emplace("profile", JsonValue{evaluated->context.name});
|
||||
object.emplace("target", JsonValue{std::string{target_name}});
|
||||
object.emplace("units", JsonValue{std::move(units)});
|
||||
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,
|
||||
@@ -1242,28 +1338,6 @@ 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,
|
||||
@@ -2182,7 +2256,8 @@ 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 == "actions" || *name == "install") {
|
||||
*name == "deps" || *name == "target_info" || *name == "target_flags" ||
|
||||
*name == "actions" || *name == "install") {
|
||||
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);
|
||||
@@ -2312,16 +2387,30 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
member),
|
||||
false};
|
||||
}
|
||||
if (*name == "target_info") {
|
||||
if (*name == "target_info" || *name == "target_flags") {
|
||||
const auto entry = object->find("target");
|
||||
if (entry == object->end()) {
|
||||
return {error_response("target_info requires \"target\""), false};
|
||||
return {error_response("\"target\" is required"), 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),
|
||||
if (*name == "target_info") {
|
||||
return {target_info_project(options, profile_name, compiler_override, *value,
|
||||
member),
|
||||
false};
|
||||
}
|
||||
std::string file_filter;
|
||||
if (const auto file_entry = object->find("file"); file_entry != object->end()) {
|
||||
const auto *file_value = std::get_if<std::string>(&file_entry->second.value);
|
||||
if (file_value == nullptr || file_value->size() > 4096) {
|
||||
return {error_response("\"file\" must be a bounded string"), false};
|
||||
}
|
||||
file_filter = *file_value;
|
||||
}
|
||||
return {target_flags_project(options, profile_name, compiler_override, *value,
|
||||
file_filter, member),
|
||||
false};
|
||||
}
|
||||
if (*name == "graph") {
|
||||
|
||||
@@ -1636,6 +1636,17 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
} 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_flags") {
|
||||
if (!opts.target_arg || opts.target_arg->empty()) {
|
||||
std::cerr << "vbs daemon target flags: --name must not be empty\n";
|
||||
return 2;
|
||||
}
|
||||
request_json = std::format(
|
||||
R"({{"op":"target_flags","profile":{},"target":{}{}}})",
|
||||
Util::json_quote(opts.profile_arg), Util::json_quote(*opts.target_arg),
|
||||
opts.file_filter_arg
|
||||
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
|
||||
: std::string{});
|
||||
} else if (sub == "target_info") {
|
||||
if (!opts.target_arg || opts.target_arg->empty()) {
|
||||
std::cerr << "vbs daemon target: --name must not be empty\n";
|
||||
@@ -2764,6 +2775,15 @@ int main(int argc, char **argv) {
|
||||
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_target_flags_cmd = daemon_target_cmd.subcommand(
|
||||
"flags", "Report one target's bounded compile arguments per unit");
|
||||
configure_daemon_common(daemon_target_flags_cmd);
|
||||
daemon_target_flags_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg,
|
||||
"debug")
|
||||
.option("--name", "-n", "Target name", daemon_opts.target_arg)
|
||||
.option("--file", "", "Only units whose source path ends with this value",
|
||||
daemon_opts.file_filter_arg);
|
||||
auto &daemon_workspace_cmd =
|
||||
daemon_cmd.subcommand("workspace", "Workspace metadata served by the daemon");
|
||||
auto &daemon_workspace_members_cmd =
|
||||
@@ -2953,6 +2973,9 @@ int main(int argc, char **argv) {
|
||||
} else if (daemon_sub == "target" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "info") {
|
||||
daemon_sub = "target_info";
|
||||
} else if (daemon_sub == "target" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "flags") {
|
||||
daemon_sub = "target_flags";
|
||||
}
|
||||
return execute_daemon_command(daemon_sub, daemon_opts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user