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") {
|
||||
|
||||
Reference in new issue
Block a user