commit 7e4111ff454d6a2f742e32a27b867eb1cd4e0c8e
parent a19ae84d8de177d7ba34e2729080a53a9c04846a
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 14 Dec 2022 10:21:01 +0100
hare build: accept -N flag for namespace
Useful when building modules separately as objects with hare build -c,
so that you can build dependencies manually and link them together.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha
@@ -260,6 +260,10 @@ fn sched_hare_object(
};
};
+ if (len(namespace) != 0) {
+ append(harec.cmd, ["-N", ns]...);
+ };
+
let current = false;
let output = if (output is str) {
// TODO: Should we use the cache here?
@@ -269,7 +273,6 @@ fn sched_hare_object(
let env = module::identuscore(namespace);
defer free(env);
- append(harec.cmd, ["-N", ns]...);
append(plan.environ, (
fmt::asprintf("HARE_VERSION_{}", env), version,
));
diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha
@@ -11,6 +11,7 @@ use fs;
use getopt;
use hare::ast;
use hare::module;
+use hare::parse;
use io;
use os::exec;
use os;
@@ -68,6 +69,7 @@ fn build(args: []str) void = {
('D', "ident[:type]=value", "define a constant"),
('j', "jobs", "set parallelism for build"),
('l', "name", "link with a system library"),
+ ('N', "namespace", "override namespace for module"),
('o', "path", "set output file name"),
('t', "arch", "set target architecture"),
('T', "tags...", "set build tags"),
@@ -88,6 +90,7 @@ fn build(args: []str) void = {
defer free(defines);
let libs: []str = [];
defer free(libs);
+ let namespace: ast::ident = [];
for (let i = 0z; i < len(cmd.opts); i += 1) {
let opt = cmd.opts[i];
switch (opt.0) {
@@ -101,6 +104,8 @@ fn build(args: []str) void = {
abort("-j option not implemented yet."); // TODO
case 'l' =>
append(libs, opt.1);
+ case 'N' =>
+ namespace = parse::identstr(opt.1)!;
case 'o' =>
output = opt.1;
case 't' =>
@@ -176,7 +181,8 @@ fn build(args: []str) void = {
case goal::EXE =>
sched_hare_exe(&plan, ver, output, depends...);
case goal::OBJ =>
- let task = sched_hare_object(&plan, ver, [], output, depends...);
+ let task = sched_hare_object(&plan, ver,
+ namespace, output, depends...);
append(plan.scheduled, task);
};
match (plan_execute(&plan, verbose)) {