~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH hare] cmd/hare: fix not erroring on unsupported target

Details
Message ID
<20220616170517.2115-1-noah@noahloomans.com>
DKIM signature
missing
Download raw message
Patch: +29 -23
The variable 'target' has been renamed to 'build_target' to avoid it
shadowing the type 'target'.

Signed-off-by: Noah Loomans <noah@noahloomans.com>
---
 cmd/hare/subcmds.ha | 39 ++++++++++++++++++---------------------
 cmd/hare/target.ha  | 13 +++++++++++--
 2 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha
index 57190a13..813652ec 100644
--- a/cmd/hare/subcmds.ha
+++ b/cmd/hare/subcmds.ha
@@ -77,8 +77,8 @@ fn build(args: []str) void = {
	const cmd = getopt::parse(args, help...);
	defer getopt::finish(&cmd);

	let target = default_target();
	let tags = module::tags_dup(target.tags);
	let build_target = default_target();
	let tags = module::tags_dup(build_target.tags);
	defer module::tags_free(tags);

	let verbose = false;
@@ -104,16 +104,13 @@ fn build(args: []str) void = {
		case 'o' =>
			output = opt.1;
		case 't' =>
			for (let i = 0z; i < len(targets); i += 1) {
				if (targets[i].name == opt.1) {
					target = &targets[i];
					module::tags_free(tags);
					tags = module::tags_dup(targets[i].tags);
					break;
				};
			};
			if (target == null) {
				fmt::fatal("Unsupported target '{}'", opt.1);
			match (get_target(opt.1)) {
			case void =>
				fmt::fatalf("Unsupported target '{}'", opt.1);
			case let t: *target =>
				build_target = t;
				module::tags_free(tags);
				tags = module::tags_dup(t.tags);
			};
		case 'T' =>
			tags = match (addtags(tags, opt.1)) {
@@ -154,7 +151,7 @@ fn build(args: []str) void = {
	const ctx = module::context_init(tags, defines, HAREPATH);
	defer module::context_finish(&ctx);

	const plan = mkplan(&ctx, libs, target);
	const plan = mkplan(&ctx, libs, build_target);
	defer plan_finish(&plan);

	const ver = match (module::scan(&ctx, input)) {
@@ -287,8 +284,8 @@ fn run(args: []str) void = {
	const cmd = getopt::parse(args, help...);
	defer getopt::finish(&cmd);

	const target = default_target();
	let tags = module::tags_dup(target.tags);
	const build_target = default_target();
	let tags = module::tags_dup(build_target.tags);
	defer module::tags_free(tags);

	let verbose = false;
@@ -347,7 +344,7 @@ fn run(args: []str) void = {
	const ctx = module::context_init(tags, defines, HAREPATH);
	defer module::context_finish(&ctx);

	const plan = mkplan(&ctx, libs, target);
	const plan = mkplan(&ctx, libs, build_target);
	defer plan_finish(&plan);

	const ver = match (module::scan(&ctx, input)) {
@@ -398,8 +395,8 @@ fn test(args: []str) void = {
	const cmd = getopt::parse(args, help...);
	defer getopt::finish(&cmd);

	const target = default_target();
	let tags = module::tags_dup(target.tags);
	const build_target = default_target();
	let tags = module::tags_dup(build_target.tags);
	append(tags, module::tag {
		name = strings::dup("test"),
		mode = module::tag_mode::INCLUSIVE,
@@ -464,7 +461,7 @@ fn test(args: []str) void = {
	const ctx = module::context_init(tags, defines, HAREPATH);
	defer module::context_finish(&ctx);

	const plan = mkplan(&ctx, libs, target);
	const plan = mkplan(&ctx, libs, build_target);
	defer plan_finish(&plan);

	let depends: []*task = [];
@@ -536,8 +533,8 @@ fn version(args: []str) void = {
	if (verbose) {
		fmt::errorln()!;
		fmt::printf("Build tags\t")!;
		const target = default_target();
		const tags = target.tags;
		const build_target = default_target();
		const tags = build_target.tags;
		for (let i = 0z; i < len(tags); i += 1) {
			const tag = tags[i];
			const inclusive = (tag.mode & module::tag_mode::INCLUSIVE) == 0;
diff --git a/cmd/hare/target.ha b/cmd/hare/target.ha
index 30005c46..58d8cef1 100644
--- a/cmd/hare/target.ha
+++ b/cmd/hare/target.ha
@@ -12,12 +12,21 @@ type target = struct {
};

fn default_target() *target = {
	let default = get_target(ARCH);
	match (default) {
	case void =>
		abort("Build configuration error - unknown default target");
	case let t: *target =>
		return t;
	};
};

fn get_target(name: str) (*target | void) = {
	for (let i = 0z; i < len(targets); i += 1) {
		if (targets[i].tags[0].name == ARCH) {
		if (targets[i].name == name) {
			return &targets[i];
		};
	};
	abort("Build configuration error - unknown default target");
};

// TODO:
-- 
2.36.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CKRQ2LPYSMSL.33VFKB43WY4G4@cirno>
In-Reply-To
<20220616170517.2115-1-noah@noahloomans.com> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 2m5s

[cmd/hare: fix not erroring on unsupported target][0] from [Noah Loomans][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/33050
[1]: noah@noahloomans.com

✓ #781851 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/781851
✓ #781852 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/781852
Details
Message ID
<CKSD4XDW5R81.MFK1E9KMRX89@megumin>
In-Reply-To
<20220616170517.2115-1-noah@noahloomans.com> (view parent)
DKIM signature
missing
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   250d9c83..b5c9a1f9  master -> master
Reply to thread Export thread (mbox)