commit 84db2f82bd07b9f9ebc551f6b107d0783ea453ba
parent 239bfa753226fb12e0d5f038249b692a1cb0ebf6
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 20 Mar 2021 12:59:23 -0400
cmd/hare: implement -D option
Diffstat:
4 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha
@@ -148,6 +148,11 @@ fn sched_hare_object(
os::tryenv("HAREC", "harec"), "-o", ssa,
]),
});
+
+ for (let i = 0z; i < len(plan.context.defines); i += 1) {
+ append(harec.cmd, "-D", plan.context.defines[i]);
+ };
+
let output = if (len(namespace) != 0) {
// TODO: consult/update cache manifest
let version = hex::encode(ver.hash);
diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha
@@ -42,12 +42,13 @@ fn build(args: []str) void = {
let verbose = false;
let output = "";
let goal = goal::EXE;
+ let defines: []str = [];
for (let i = 0z; i < len(cmd.opts); i += 1) {
let opt = cmd.opts[i];
switch (opt.0) {
'c' => goal = goal::OBJ,
'v' => verbose = true,
- 'D' => abort(), // TODO
+ 'D' => append(defines, opt.1),
'j' => abort(), // TODO
'l' => abort(), // TODO
'o' => output = opt.1,
@@ -71,7 +72,7 @@ fn build(args: []str) void = {
let tags = default_tags();
defer free(tags);
- let ctx = module::context_init(tags, HAREPATH);
+ let ctx = module::context_init(tags, defines, HAREPATH);
defer module::context_finish(&ctx);
let plan = mkplan(&ctx);
@@ -144,11 +145,12 @@ fn run(args: []str) void = {
defer getopt::finish(&cmd);
let verbose = false;
+ let defines: []str = [];
for (let i = 0z; i < len(cmd.opts); i += 1) {
let opt = cmd.opts[i];
switch (opt.0) {
'v' => verbose = true,
- 'D' => abort(), // TODO
+ 'D' => append(defines, opt.1),
'j' => abort(), // TODO
'l' => abort(), // TODO
't' => abort(), // TODO
@@ -170,7 +172,7 @@ fn run(args: []str) void = {
let tags = default_tags();
defer free(tags);
- let ctx = module::context_init(tags, HAREPATH);
+ let ctx = module::context_init(tags, defines, HAREPATH);
defer module::context_finish(&ctx);
let plan = mkplan(&ctx);
diff --git a/hare/module/context.ha b/hare/module/context.ha
@@ -18,15 +18,19 @@ export type context = struct {
cache: str,
// Build tags to apply to this context.
tags: []tag,
+ // List of -D arguments passed to harec
+ defines: []str,
};
// Initializes a new context with the system default configuration. The tag list
-// is borrowed from the caller. The harepath parameter is not borrowed, but it
-// is ignored if HAREPATH is set in the process environment.
-export fn context_init(tags: []tag, harepath: str) context = {
+// and list of defines (arguments passed with harec -D) is borrowed from the
+// caller. The harepath parameter is not borrowed, but it is ignored if HAREPATH
+// is set in the process environment.
+export fn context_init(tags: []tag, defs: []str, harepath: str) context = {
let ctx = context {
fs = os::cwd,
tags = tags,
+ defines = defs,
paths: []str = match (os::getenv("HAREPATH")) {
void => {
let path: []str = alloc([
diff --git a/hare/module/scan.ha b/hare/module/scan.ha
@@ -16,6 +16,7 @@ use strio;
// Scans the files in a directory for eligible build inputs and returns a
// [version] which includes all applicable files and their dependencies.
export fn scan(ctx: *context, path: str) (version | error) = {
+ // TODO: Incorporate defines into the hash
let sha = sha256::sha256();
//defer! hash::close(sha);
let iter = match (fs::iter(ctx.fs, path)) {