hare

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

commit 81dcc25188e70c3310c70876d20fd4666e24ec4b
parent 4e1599e031729e479f2f071e015ee0dc0ed2e43e
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Sun,  6 Jun 2021 22:51:14 +0000

cmd/hare: test: implement module discovery

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Mcmd/hare/subcmds.ha | 54++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 48 insertions(+), 6 deletions(-)

diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -1,5 +1,9 @@ +use ascii; +use encoding::utf8; use fmt; +use fs; use getopt; +use hare::ast; use hare::module; use os; use os::exec; @@ -245,6 +249,48 @@ fn run(args: []str) void = { exec::exec(&cmd); }; +fn sched_walk(plan: *plan, ident: ast::ident, link: *[]*task) void = { + const path = module::identpath(ident); + let it = os::iter(path)?; + free(path); + :loop for (true) match (fs::next(it)) { + ent: fs::dirent => { + if (ent.name == "." || ent.name == "..") { + continue; + }; + if (ent.ftype & fs::mode::DIR != fs::mode::DIR) { + continue; + }; + let d = utf8::decode(ent.name); + match (utf8::next(&d)) { + void => break, + (utf8::more | utf8::invalid) => continue :loop, + r: rune => if (!ascii::isalpha(r) && r != '_') { + continue :loop; + }, + }; + for (true) match (utf8::next(&d)) { + void => break, + (utf8::more | utf8::invalid) => continue :loop, + r: rune => if (!ascii::isalnum(r) && r != '_') { + continue :loop; + }, + }; + let new = ast::ident_dup(ident); + append(new, strings::dup(ent.name)); + sched_walk(plan, new, link); + + match (module::lookup(plan.context, new)) { + ver: module::version => + if (len(ver.inputs) == 0) continue, + module::error => continue, + }; + sched_module(plan, new, link); + }, + void => break, + }; +}; + fn test(args: []str) void = { let help: []getopt::help = [ "compiles and runs tests for Hare programs", @@ -313,14 +359,10 @@ fn test(args: []str) void = { let depends: []*task = []; sched_module(&plan, ["rt"], &depends); - - for (let i = 0z; i < len(ver.depends); i += 1z) { - const dep = ver.depends[i]; - sched_module(&plan, dep, &depends); - }; + sched_walk(&plan, [], &depends); let output = mkfile(&plan, "out"); - sched_hare_exe(&plan, ver, output, depends...); + sched_hare_exe(&plan, ver, strings::dup(output), depends...); plan_execute(&plan, verbose); let cmd = match (exec::cmd(output, runargs...)) { err: exec::error => fmt::fatal("exec: {}", exec::strerror(err)),