hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit ca238f506a0d72f61de721ba612e4b7d9f7b966f
parent 2da3ed216a288efe48979a96acbafede45866ebd
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 27 Jun 2021 11:06:24 -0400

cmd/hare: bubble build errors up to subcmd

This makes sure we have a chance to run the deferred cleanup code from
the subcmd context initialization, which, among other things, ensures
that we don't litter /tmp with directories after build failures.

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mcmd/hare/plan.ha | 9++++++---
Mcmd/hare/subcmds.ha | 18+++++++++++++++---
2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -89,7 +89,7 @@ fn plan_finish(plan: *plan) void = { }; }; -fn plan_execute(plan: *plan, verbose: bool) void = { +fn plan_execute(plan: *plan, verbose: bool) (void | !exec::exit_status) = { for (len(plan.scheduled) != 0) { let next: nullable *task = null; let i = 0z; @@ -116,8 +116,11 @@ fn plan_execute(plan: *plan, verbose: bool) void = { match (execute(plan, task, verbose)) { err: exec::error => fmt::fatal("Error: {}: {}", task.cmd[0], exec::strerror(err)), - err: !exec::exit_status => fmt::fatal("Error: {}: {}", - task.cmd[0], exec::exitstr(err)), + err: !exec::exit_status => { + fmt::errorfln("Error: {}: {}", task.cmd[0], + exec::exitstr(err))!; + return err; + }, void => void, }; diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -139,7 +139,11 @@ fn build(args: []str) void = { output = path::basename(ver.basedir); }; sched_hare_exe(&plan, ver, output, depends...); - plan_execute(&plan, verbose); + match (plan_execute(&plan, verbose)) { + void => void, + !exec::exit_status => fmt::fatal("{} {}: build failed", + os::args[0], os::args[1]), + }; }; fn cache(args: []str) void = { @@ -240,7 +244,11 @@ fn run(args: []str) void = { let output = mkfile(&plan, "out"); sched_hare_exe(&plan, ver, output, depends...); - plan_execute(&plan, verbose); + match (plan_execute(&plan, verbose)) { + void => void, + !exec::exit_status => fmt::fatal("{} {}: build failed", + os::args[0], os::args[1]), + }; let cmd = match (exec::cmd(output, runargs...)) { err: exec::error => fmt::fatal("exec: {}", exec::strerror(err)), cmd: exec::command => cmd, @@ -373,7 +381,11 @@ fn test(args: []str) void = { } else { sched_hare_exe(&plan, ver, strings::dup(output), depends...); }; - plan_execute(&plan, verbose); + match (plan_execute(&plan, verbose)) { + void => void, + !exec::exit_status => fmt::fatal("{} {}: build failed", + os::args[0], os::args[1]), + }; if (have_output) { return;