commit 5764d11c89789a93bf654058ec96c9ce9116e4ca
parent ca9c0e5c4e713002534cdc134c361e3d002fd551
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sat, 17 Apr 2021 21:21:43 -0400
cmd/hare: implement -T and -X
Diffstat:
M | cmd/hare/subcmds.ha | | | 92 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- |
1 file changed, 72 insertions(+), 20 deletions(-)
diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha
@@ -4,17 +4,50 @@ use hare::module;
use os;
use os::exec;
use path;
+use strings;
fn default_tags() []module::tag = {
return alloc([module::tag {
- name = os::machine(),
+ name = strings::dup(os::machine()),
mode = module::tag_mode::INCLUSIVE,
}, module::tag {
- name = PLATFORM,
+ name = strings::dup(PLATFORM),
mode = module::tag_mode::INCLUSIVE,
}]);
};
+fn addtags(tags: []module::tag, in: str) ([]module::tag | void) = {
+ let in = match (module::parsetags(in)) {
+ void => return void,
+ t: []module::tag => t,
+ };
+ defer free(in);
+ append(tags, in...);
+ return tags;
+};
+
+fn deltags(tags: []module::tag, in: str) ([]module::tag | void) = {
+ if (in == "^") {
+ module::tags_free(tags);
+ return [];
+ };
+ let in = match (module::parsetags(in)) {
+ void => return void,
+ t: []module::tag => t,
+ };
+ defer free(in);
+ for (let i = 0z; i < len(tags); i += 1) {
+ for (let j = 0z; j < len(in); j += 1) {
+ if (tags[i].name == in[j].name
+ && tags[i].mode == in[j].mode) {
+ delete(tags[i]);
+ i -= 1;
+ };
+ };
+ };
+ return tags;
+};
+
type goal = enum {
OBJ,
EXE,
@@ -37,6 +70,9 @@ fn build(args: []str) void = {
let cmd = getopt::parse(args, help...);
defer getopt::finish(&cmd);
+ let tags = default_tags();
+ defer module::tags_free(tags);
+
let verbose = false;
let output = "";
let goal = goal::EXE;
@@ -51,8 +87,14 @@ fn build(args: []str) void = {
'l' => abort(), // TODO
'o' => output = opt.1,
't' => abort(), // TODO
- 'T' => abort(), // TODO
- 'X' => abort(), // TODO
+ 'T' => tags = match (addtags(tags, opt.1)) {
+ void => fmt::fatal("Error parsing tags"),
+ t: []module::tag => t,
+ },
+ 'X' => tags = match (deltags(tags, opt.1)) {
+ void => fmt::fatal("Error parsing tags"),
+ t: []module::tag => t,
+ },
* => abort(),
};
};
@@ -67,9 +109,6 @@ fn build(args: []str) void = {
os::exit(1);
};
- let tags = default_tags();
- defer free(tags);
-
let ctx = module::context_init(tags, defines, HAREPATH);
defer module::context_finish(&ctx);
@@ -140,6 +179,9 @@ fn run(args: []str) void = {
let cmd = getopt::parse(args, help...);
defer getopt::finish(&cmd);
+ let tags = default_tags();
+ defer module::tags_free(tags);
+
let verbose = false;
let defines: []str = [];
for (let i = 0z; i < len(cmd.opts); i += 1) {
@@ -150,8 +192,14 @@ fn run(args: []str) void = {
'j' => abort(), // TODO
'l' => abort(), // TODO
't' => abort(), // TODO
- 'T' => abort(), // TODO
- 'X' => abort(), // TODO
+ 'T' => tags = match (addtags(tags, opt.1)) {
+ void => fmt::fatal("Error parsing tags"),
+ t: []module::tag => t,
+ },
+ 'X' => tags = match (deltags(tags, opt.1)) {
+ void => fmt::fatal("Error parsing tags"),
+ t: []module::tag => t,
+ },
* => abort(),
};
};
@@ -165,9 +213,6 @@ fn run(args: []str) void = {
runargs = cmd.args[1..];
};
- let tags = default_tags();
- defer free(tags);
-
let ctx = module::context_init(tags, defines, HAREPATH);
defer module::context_finish(&ctx);
@@ -214,6 +259,13 @@ fn test(args: []str) void = {
let cmd = getopt::parse(args, help...);
defer getopt::finish(&cmd);
+ let tags = default_tags();
+ defer module::tags_free(tags);
+ append(tags, module::tag {
+ name = strings::dup("test"),
+ mode = module::tag_mode::INCLUSIVE,
+ });
+
let verbose = false;
let defines: []str = [];
for (let i = 0z; i < len(cmd.opts); i += 1) {
@@ -224,8 +276,14 @@ fn test(args: []str) void = {
'j' => abort(), // TODO
'l' => abort(), // TODO
't' => abort(), // TODO
- 'T' => abort(), // TODO
- 'X' => abort(), // TODO
+ 'T' => tags = match (addtags(tags, opt.1)) {
+ void => fmt::fatal("Error parsing tags"),
+ t: []module::tag => t,
+ },
+ 'X' => tags = match (deltags(tags, opt.1)) {
+ void => fmt::fatal("Error parsing tags"),
+ t: []module::tag => t,
+ },
* => abort(),
};
};
@@ -239,12 +297,6 @@ fn test(args: []str) void = {
runargs = cmd.args[1..];
};
- let tags = default_tags();
- defer free(tags);
- append(tags, module::tag {
- name = "test",
- mode = module::tag_mode::INCLUSIVE,
- });
let ctx = module::context_init(tags, defines, HAREPATH);
defer module::context_finish(&ctx);