commit 84799dba8f7ca2a644a582df898647ee20ad6990
parent eed09f5e277b79b3a024714e2f6f6146405f18a0
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 8 Jan 2022 14:48:01 +0100
cmd/hare/plan.ha: use path::buffer
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha
@@ -55,20 +55,20 @@ fn mkplan(ctx: *module::context, libs: []str) plan = {
yield ver.basedir;
};
- let script = ("", 0z);
-
+ // Look up the most appropriate hare.sc file
+ let ntag = 0z;
+ const buf = path::init();
const iter = os::iter(rtdir)!;
for (true) match (fs::next(iter)) {
case let d: fs::dirent =>
const p = module::parse_name(d.name);
- defer module::tags_free(p.2);
-
- if (len(p.2) >= script.1
- && p.0 == "hare" && p.1 == ".sc"
- && module::tagcompat(ctx.tags, p.2)) {
- free(script.0);
- script.0 = path::join(rtdir, d.name);
- script.1 = len(p.2);
+ const name = p.0, ext = p.1, tags = p.2;
+ defer module::tags_free(tags);
+
+ if (len(tags) >= ntag && name == "hare" && ext == ".sc"
+ && module::tagcompat(ctx.tags, tags)) {
+ ntag = len(tags);
+ path::set(&buf, rtdir, d.name)!;
};
case void =>
break;
@@ -77,7 +77,7 @@ fn mkplan(ctx: *module::context, libs: []str) plan = {
return plan {
context = ctx,
workdir = temp::dir(),
- script = script.0,
+ script = path::allocate(&buf),
environ = alloc([
(strings::dup("HARECACHE"), strings::dup(ctx.cache)),
]),
diff --git a/path/buffer.ha b/path/buffer.ha
@@ -63,6 +63,12 @@ export fn string(buf: *buffer) str = {
return value;
};
+// Like [[string]] but the return value is copied to the heap and must be freed
+// by the caller.
+export fn allocate(buf: *buffer) str = {
+ return strings::dup(string(buf));
+};
+
const dot: []u8 = ['.': u8];
const dotdot: []u8 = ['.': u8, '.': u8];
const dotdotslash: []u8 = ['.': u8, '.': u8, PATHSEP];