commit bb4ef4f3180dcd8408b9ade0552ad3e11af97970
parent 2424c0e23ae800edd1322332dd5d4a138b52bf5e
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 2 Mar 2021 09:42:52 -0500
Initial riggings for build driver
Diffstat:
5 files changed, 87 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
@@ -18,6 +18,7 @@ hare:
include mk/stdlib.mk
hare_srcs=\
+ plan.ha \
main.ha
$(HARECACHE)/hare.ssa: $(hare_srcs) $(hare_stdlib_deps)
diff --git a/gen-stdlib b/gen-stdlib
@@ -333,8 +333,11 @@ os_exec() {
printf '# os::exec\n'
gen_srcs os::exec \
'$(PLATFORM).ha' \
+ types.ha \
+ 'process$(PLATFORM).ha' \
+ 'cmd$(PLATFORM).ha' \
cmd.ha
- gen_ssa os::exec os strings
+ gen_ssa os::exec os strings fmt
}
path() {
diff --git a/main.ha b/main.ha
@@ -1,6 +1,7 @@
-use encoding::hex;
use fmt;
use hare::module;
+use io;
+use os::exec;
use os;
export fn main() void = {
@@ -15,23 +16,62 @@ export fn main() void = {
module::errstr(err)),
};
- let hash = hex::encode(ver.hash);
- fmt::printfln("{}: {}", hash, os::args[1]);
- fmt::println(len(ver.inputs), "inputs");
+ let plan = plan { ... };
+
+ let harec = alloc(task {
+ status = status::SCHEDULED,
+ inputs = ver.inputs,
+ output = "hare.ssa",
+ cmd = alloc(["harec"]),
+ ...
+ });
+
for (let i = 0z; i < len(ver.inputs); i += 1) {
- let hash = hex::encode(ver.inputs[i].hash);
- defer free(hash);
- fmt::printfln("\t{} {}", hash, ver.inputs[i].path as str);
+ let path = ver.inputs[i].path as str;
+ append(harec.cmd, path);
};
- fmt::println(len(ver.depends), "dependencies");
- for (let i = 0z; i < len(ver.depends); i += 1) {
- let ident = ver.depends[i];
- fmt::print("\t");
- for (let j = 0z; j < len(ident); j += 1) {
- fmt::printf("{}{}", ident[j],
- if (j + 1 < len(ident)) "::"
- else "\n");
+ append(plan.scheduled, harec);
+
+ for (len(plan.scheduled) != 0) {
+ let next: nullable *task = null;
+ let i = 0z;
+ for (i < len(plan.scheduled); i += 1) {
+ // TODO: Check dependencies and pick the next eligible
+ // task instead
+ next = plan.scheduled[i];
+ break;
};
+ // TODO: This can be a type assertion
+ let task = match (next) {
+ null => abort(),
+ t: *task => t,
+ };
+
+ let cmd = match (exec::cmd(task.cmd[0], task.cmd[1..]...)) {
+ cmd: exec::command => cmd,
+ err: exec::error => fmt::fatal("Error: exec {}: {}",
+ task.cmd[0], exec::errstr(err)),
+ };
+ let proc = match (exec::start(&cmd)) {
+ err: exec::error => fmt::fatal("Error: start {}: {}",
+ task.cmd[0], exec::errstr(err)),
+ proc: exec::process => proc,
+ };
+ match (exec::wait(&proc)) {
+ err: exec::error => fmt::fatal("Error: wait {}: {}",
+ task.cmd[0], exec::errstr(err)),
+ st: exec::status => match (exec::check(&st)) {
+ err: exec::exit_status! => {
+ fmt::fatal("Error: {}: {}", task.cmd[0],
+ exec::exitstr(err));
+ },
+ void => void,
+ },
+ };
+
+ task.status = status::COMPLETE;
+ delete(plan.scheduled[i]);
+ append(plan.complete, task);
};
};
diff --git a/mk/stdlib.mk b/mk/stdlib.mk
@@ -383,9 +383,12 @@ $(HARECACHE)/os/os.ssa: $(stdlib_os_srcs) $(stdlib_rt) $(stdlib_io) $(stdlib_str
# os::exec
stdlib_os_exec_srcs= \
$(STDLIB)/os/exec/$(PLATFORM).ha \
+ $(STDLIB)/os/exec/types.ha \
+ $(STDLIB)/os/exec/process$(PLATFORM).ha \
+ $(STDLIB)/os/exec/cmd$(PLATFORM).ha \
$(STDLIB)/os/exec/cmd.ha
-$(HARECACHE)/os/exec/os.exec.ssa: $(stdlib_os_exec_srcs) $(stdlib_rt) $(stdlib_os) $(stdlib_strings)
+$(HARECACHE)/os/exec/os.exec.ssa: $(stdlib_os_exec_srcs) $(stdlib_rt) $(stdlib_os) $(stdlib_strings) $(stdlib_fmt)
@printf 'HAREC \t$@\n'
@mkdir -p $(HARECACHE)/os/exec
@HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos::exec \
@@ -874,9 +877,12 @@ $(TESTCACHE)/os/os.ssa: $(testlib_os_srcs) $(testlib_rt) $(testlib_io) $(testlib
# os::exec
testlib_os_exec_srcs= \
$(STDLIB)/os/exec/$(PLATFORM).ha \
+ $(STDLIB)/os/exec/types.ha \
+ $(STDLIB)/os/exec/process$(PLATFORM).ha \
+ $(STDLIB)/os/exec/cmd$(PLATFORM).ha \
$(STDLIB)/os/exec/cmd.ha
-$(TESTCACHE)/os/exec/os.exec.ssa: $(testlib_os_exec_srcs) $(testlib_rt) $(testlib_os) $(testlib_strings)
+$(TESTCACHE)/os/exec/os.exec.ssa: $(testlib_os_exec_srcs) $(testlib_rt) $(testlib_os) $(testlib_strings) $(testlib_fmt)
@printf 'HAREC \t$@\n'
@mkdir -p $(TESTCACHE)/os/exec
@HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos::exec \
diff --git a/plan.ha b/plan.ha
@@ -0,0 +1,19 @@
+use hare::module;
+
+type status = enum {
+ SCHEDULED,
+ COMPLETE,
+};
+
+type task = struct {
+ status: status,
+ inputs: []module::input,
+ depend: []*task,
+ output: str,
+ cmd: []str,
+};
+
+type plan = struct {
+ scheduled: []*task,
+ complete: []*task,
+};