Skip to content

Commit 8288de9

Browse files
authored
optmize buildtools init, avoid global static var (#22)
1 parent 10c524f commit 8288de9

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/checker.cppm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ namespace checker {
1414

1515
// detect flag
1616
constexpr std::string D2X_WAIT = "D2X_WAIT";
17-
static auto btools = d2x::load_buildtools();
1817

19-
std::pair<bool, std::string> build_with_error_handling(const std::string &target) {
18+
std::pair<bool, std::string> build_with_error_handling(const auto& btools, const std::string &target) {
2019
auto [exit_code, output] = btools.build(target);
2120
return std::make_pair(exit_code == 0, output);
2221
}
2322

24-
std::pair<bool, std::string> run_with_error_handling(const std::string &target) {
23+
std::pair<bool, std::string> run_with_error_handling(const auto& btools, const std::string &target) {
2524
auto [exit_code, output] = btools.run(target);
2625
return std::make_pair(exit_code == 0, output);
2726
}
2827

2928
export void run(const std::string& start_target = "") {
3029

30+
auto btools = d2x::load_buildtools();
31+
3132
btools.load_targets();
3233

3334
auto targets = btools.get_targets();
@@ -78,10 +79,10 @@ export void run(const std::string& start_target = "") {
7879

7980
while (!build_success) {
8081

81-
std::tie(build_success, output) = build_with_error_handling(target);
82+
std::tie(build_success, output) = build_with_error_handling(btools, target);
8283

8384
if (build_success) {
84-
std::tie(build_success, output) = run_with_error_handling(target);
85+
std::tie(build_success, output) = run_with_error_handling(btools, target);
8586
}
8687

8788
status = build_success;

0 commit comments

Comments
 (0)