From b525a39a721cd24963763f75f1f8f76fb796f023 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Sun, 8 Mar 2026 23:38:14 +0800 Subject: [PATCH] optmize buildtools init, avoid global static var --- src/checker.cppm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/checker.cppm b/src/checker.cppm index 927600a..d4e03c4 100644 --- a/src/checker.cppm +++ b/src/checker.cppm @@ -14,20 +14,21 @@ namespace checker { // detect flag constexpr std::string D2X_WAIT = "D2X_WAIT"; -static auto btools = d2x::load_buildtools(); -std::pair build_with_error_handling(const std::string &target) { +std::pair build_with_error_handling(const auto& btools, const std::string &target) { auto [exit_code, output] = btools.build(target); return std::make_pair(exit_code == 0, output); } -std::pair run_with_error_handling(const std::string &target) { +std::pair run_with_error_handling(const auto& btools, const std::string &target) { auto [exit_code, output] = btools.run(target); return std::make_pair(exit_code == 0, output); } export void run(const std::string& start_target = "") { + auto btools = d2x::load_buildtools(); + btools.load_targets(); auto targets = btools.get_targets(); @@ -78,10 +79,10 @@ export void run(const std::string& start_target = "") { while (!build_success) { - std::tie(build_success, output) = build_with_error_handling(target); + std::tie(build_success, output) = build_with_error_handling(btools, target); if (build_success) { - std::tie(build_success, output) = run_with_error_handling(target); + std::tie(build_success, output) = run_with_error_handling(btools, target); } status = build_success;