feat(daemon): build all workspace members in order
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 43s

This commit is contained in:
faumaray committed 2026-12-03 21:36:15 +03:00
1 parent 359783d2ad
commit 1a884fd931
6 files changed
+135 -39

No files matched your search

+109 -34
View File
@@ -611,34 +611,38 @@ Void::Result::Result<std::size_t, std::string> materialize_project_dependencies(
// Bounded build-serving request: resolves dependencies, lowers the project graph, and executes it
// in-process against the daemon's warm StateStore.
std::string build_project(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs,
std::string_view selected_member) {
auto effective_result = resolve_member_options(options, selected_member);
if (!effective_result) {
return error_response(std::format("build: {}", effective_result.error()));
}
const DaemonOptions &effective = *effective_result;
const std::string member_name = Config::is_workspace_root(options.project_root)
? std::string{selected_member}
: std::string{};
struct BuildOutcome {
std::string profile;
std::size_t targets{0};
std::size_t actions{0};
std::size_t dependencies{0};
std::size_t executed{0};
std::size_t cached{0};
std::size_t failed{0};
bool succeeded{false};
std::string diagnostic;
JsonValue::Array failed_actions;
};
auto evaluated = evaluate_project_graph(effective, profile_name, compiler_override, "build");
Void::Result::Result<BuildOutcome, std::string>
execute_project_build(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "build");
if (!evaluated) {
return error_response(evaluated.error());
return std::unexpected{evaluated.error()};
}
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
auto materialized =
materialize_project_dependencies(effective, state, *evaluated, jobs, imported_targets);
materialize_project_dependencies(options, state, *evaluated, jobs, imported_targets);
if (!materialized) {
return error_response(materialized.error());
return std::unexpected{materialized.error()};
}
auto graph = lower_graph(effective, *evaluated, std::move(imported_targets), "build");
auto graph = lower_graph(options, *evaluated, std::move(imported_targets), "build");
if (!graph) {
return error_response(graph.error());
return std::unexpected{graph.error()};
}
Execution::ExecutionOptions exec_options;
@@ -646,34 +650,105 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
exec_options.selected_targets = selected_targets;
auto report = Execution::execute_graph(*graph, state, exec_options);
if (!report) {
return error_response(std::format("build: {}", report.error().format()));
return std::unexpected{std::format("build: {}", report.error().format())};
}
JsonValue::Array failed_actions;
BuildOutcome outcome;
outcome.profile = evaluated->context.name;
outcome.targets = graph->targets.size();
outcome.actions = graph->actions.size();
outcome.dependencies = *materialized;
outcome.executed = report->executed_count;
outcome.cached = report->cached_count;
outcome.failed = report->failed_count;
outcome.succeeded = report->succeeded;
outcome.diagnostic = report->diagnostic;
for (const auto &result : report->results) {
if (!result.succeeded) {
JsonValue::Object failure;
failure.emplace("action", JsonValue{result.action_id});
failure.emplace("target", JsonValue{result.target_name});
failure.emplace("error", JsonValue{result.error_message});
failed_actions.emplace_back(std::move(failure));
outcome.failed_actions.emplace_back(std::move(failure));
}
}
return outcome;
}
JsonValue::Object build_outcome_json(const BuildOutcome &outcome) {
JsonValue::Object object;
object.emplace("ok", JsonValue{report->succeeded});
object.emplace("profile", JsonValue{outcome.profile});
object.emplace("targets", JsonValue{static_cast<std::int64_t>(outcome.targets)});
object.emplace("actions", JsonValue{static_cast<std::int64_t>(outcome.actions)});
object.emplace("dependencies", JsonValue{static_cast<std::int64_t>(outcome.dependencies)});
object.emplace("executed", JsonValue{static_cast<std::int64_t>(outcome.executed)});
object.emplace("cached", JsonValue{static_cast<std::int64_t>(outcome.cached)});
object.emplace("failed", JsonValue{static_cast<std::int64_t>(outcome.failed)});
object.emplace("diagnostic", JsonValue{outcome.diagnostic});
object.emplace("failed_actions", JsonValue{outcome.failed_actions});
return object;
}
std::string build_project(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs,
std::string_view selected_member) {
const bool workspace = Config::is_workspace_root(options.project_root);
// Workspace-wide build: every member in declared order, sharing the root lock and CAS.
if (workspace && selected_member.empty()) {
auto members = evaluate_workspace_members(options);
if (!members) {
return error_response(members.error());
}
JsonValue::Array member_array;
std::size_t executed = 0;
std::size_t cached = 0;
std::size_t failed = 0;
bool all_ok = true;
for (const auto &member : *members) {
const auto member_opts = member_options(options, member.path);
auto outcome = execute_project_build(member_opts, state, profile_name,
compiler_override, selected_targets, jobs);
if (!outcome) {
return error_response(
std::format("build: member '{}': {}", member.name, outcome.error()));
}
JsonValue::Object entry = build_outcome_json(*outcome);
entry.emplace("name", JsonValue{member.name});
entry.emplace("ok", JsonValue{outcome->succeeded});
member_array.emplace_back(std::move(entry));
executed += outcome->executed;
cached += outcome->cached;
failed += outcome->failed;
all_ok = all_ok && outcome->succeeded;
}
JsonValue::Object object;
object.emplace("ok", JsonValue{all_ok});
object.emplace("op", JsonValue{std::string{"build"}});
object.emplace("workspace", JsonValue{true});
object.emplace("members", JsonValue{std::move(member_array)});
object.emplace("executed", JsonValue{static_cast<std::int64_t>(executed)});
object.emplace("cached", JsonValue{static_cast<std::int64_t>(cached)});
object.emplace("failed", JsonValue{static_cast<std::int64_t>(failed)});
return serialize_response(JsonValue{std::move(object)});
}
auto effective_result = resolve_member_options(options, selected_member);
if (!effective_result) {
return error_response(std::format("build: {}", effective_result.error()));
}
auto outcome = execute_project_build(*effective_result, state, profile_name, compiler_override,
selected_targets, jobs);
if (!outcome) {
return error_response(outcome.error());
}
JsonValue::Object object = build_outcome_json(*outcome);
object.emplace("ok", JsonValue{outcome->succeeded});
object.emplace("op", JsonValue{std::string{"build"}});
object.emplace("profile", JsonValue{evaluated->context.name});
object.emplace("targets", JsonValue{static_cast<std::int64_t>(graph->targets.size())});
object.emplace("actions", JsonValue{static_cast<std::int64_t>(graph->actions.size())});
object.emplace("dependencies", JsonValue{static_cast<std::int64_t>(*materialized)});
object.emplace("executed", JsonValue{static_cast<std::int64_t>(report->executed_count)});
object.emplace("cached", JsonValue{static_cast<std::int64_t>(report->cached_count)});
object.emplace("failed", JsonValue{static_cast<std::int64_t>(report->failed_count)});
object.emplace("diagnostic", JsonValue{report->diagnostic});
object.emplace("failed_actions", JsonValue{std::move(failed_actions)});
if (!member_name.empty()) {
object.emplace("member", JsonValue{member_name});
if (workspace) {
object.emplace("member", JsonValue{std::string{selected_member}});
}
return serialize_response(JsonValue{std::move(object)});
}