commit 7b067d2f1fe4ec0c02766ea17206d57329681120
parent aa929853fe0a7d7d790b171576a73e33c8d8a6c9
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 31 Mar 2021 15:18:34 -0400
hare::module: sort module inputs
Diffstat:
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/hare/module/scan.ha b/hare/module/scan.ha
@@ -10,6 +10,7 @@ use hash;
use io;
use path;
use slice;
+use sort;
use strings;
use strio;
@@ -82,6 +83,12 @@ fn parse_name(name: str) (str, str, []tag) = {
return (base, ext, tags);
};
+fn strcmp(a: const *void, b: const *void) int = {
+ const a = *(a: const *str);
+ const b = *(b: const *str);
+ return ascii::strcmp(a, b) as int;
+};
+
fn scan_directory(
ctx: *context,
ver: *version,
@@ -115,9 +122,10 @@ fn scan_directory(
};
};
- // TODO:
- // - sort entries (for a consistent module hash)
- // - filter out less specific tag sets for a given basename
+ sort::sort(dirs, size(str), &strcmp);
+ sort::sort(files, size(str), &strcmp);
+
+ // TODO: filter out less specific tag sets for a given basename
for (let i = 0z; i < len(dirs); i += 1) {
let name = dirs[i];
let tags = parse_name(name).2;
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -288,7 +288,7 @@ hare_module() {
gen_ssa hare::module \
hare::ast hare::lex hare::parse hare::unparse strio fs io strings hash \
crypto::sha256 dirs bytes encoding::utf8 ascii fmt time slice bufio \
- strconv os encoding::hex
+ strconv os encoding::hex sort
}
gensrcs_hare_parse() {
diff --git a/stdlib.mk b/stdlib.mk
@@ -412,7 +412,7 @@ stdlib_hare_module_srcs= \
$(STDLIB)/hare/module/scan.ha \
$(STDLIB)/hare/module/manifest.ha
-$(HARECACHE)/hare/module/hare_module.ssa: $(stdlib_hare_module_srcs) $(stdlib_rt) $(stdlib_hare_ast) $(stdlib_hare_lex) $(stdlib_hare_parse) $(stdlib_hare_unparse) $(stdlib_strio) $(stdlib_fs) $(stdlib_io) $(stdlib_strings) $(stdlib_hash) $(stdlib_crypto_sha256) $(stdlib_dirs) $(stdlib_bytes) $(stdlib_encoding_utf8) $(stdlib_ascii) $(stdlib_fmt) $(stdlib_time) $(stdlib_slice) $(stdlib_bufio) $(stdlib_strconv) $(stdlib_os) $(stdlib_encoding_hex)
+$(HARECACHE)/hare/module/hare_module.ssa: $(stdlib_hare_module_srcs) $(stdlib_rt) $(stdlib_hare_ast) $(stdlib_hare_lex) $(stdlib_hare_parse) $(stdlib_hare_unparse) $(stdlib_strio) $(stdlib_fs) $(stdlib_io) $(stdlib_strings) $(stdlib_hash) $(stdlib_crypto_sha256) $(stdlib_dirs) $(stdlib_bytes) $(stdlib_encoding_utf8) $(stdlib_ascii) $(stdlib_fmt) $(stdlib_time) $(stdlib_slice) $(stdlib_bufio) $(stdlib_strconv) $(stdlib_os) $(stdlib_encoding_hex) $(stdlib_sort)
@printf 'HAREC \t$@\n'
@mkdir -p $(HARECACHE)/hare/module
@HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nhare::module \
@@ -1150,7 +1150,7 @@ testlib_hare_module_srcs= \
$(STDLIB)/hare/module/scan.ha \
$(STDLIB)/hare/module/manifest.ha
-$(TESTCACHE)/hare/module/hare_module.ssa: $(testlib_hare_module_srcs) $(testlib_rt) $(testlib_hare_ast) $(testlib_hare_lex) $(testlib_hare_parse) $(testlib_hare_unparse) $(testlib_strio) $(testlib_fs) $(testlib_io) $(testlib_strings) $(testlib_hash) $(testlib_crypto_sha256) $(testlib_dirs) $(testlib_bytes) $(testlib_encoding_utf8) $(testlib_ascii) $(testlib_fmt) $(testlib_time) $(testlib_slice) $(testlib_bufio) $(testlib_strconv) $(testlib_os) $(testlib_encoding_hex)
+$(TESTCACHE)/hare/module/hare_module.ssa: $(testlib_hare_module_srcs) $(testlib_rt) $(testlib_hare_ast) $(testlib_hare_lex) $(testlib_hare_parse) $(testlib_hare_unparse) $(testlib_strio) $(testlib_fs) $(testlib_io) $(testlib_strings) $(testlib_hash) $(testlib_crypto_sha256) $(testlib_dirs) $(testlib_bytes) $(testlib_encoding_utf8) $(testlib_ascii) $(testlib_fmt) $(testlib_time) $(testlib_slice) $(testlib_bufio) $(testlib_strconv) $(testlib_os) $(testlib_encoding_hex) $(testlib_sort)
@printf 'HAREC \t$@\n'
@mkdir -p $(TESTCACHE)/hare/module
@HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nhare::module \