~sircmpwn/hare-dev

hare: Don't abort() on empty modules v1 REJECTED

Enno Tensing: 3
 hare::module: Add empty_module error
 hare::module: Expose that module only contains a readme
 cmd/hare: Error out on empty modules

 3 files changed, 19 insertions(+), 0 deletions(-)
#1140434 alpine.yml success
#1140435 freebsd.yml success
#1140436 openbsd.yml success
hare/patches: SUCCESS in 1m13s

[Don't abort() on empty modules][0] from [Enno Tensing][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/49044
[1]: mailto:tenno@suij.in

✓ #1140436 SUCCESS hare/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1140436
✓ #1140435 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1140435
✓ #1140434 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1140434
i figured out what was causing the error in the first place, see
https://lists.sr.ht/~sircmpwn/hare-dev/patches/49205
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/49044/mbox | git am -3
Learn more about email & git

[PATCH hare 1/3] hare::module: Add empty_module error Export this patch

Add an error that indicates that a module provides no sources, either
because it is faulty or only provides submodules (like encoding does).

Signed-off-by: Enno Tensing <tenno@suij.in>
---
 hare/module/types.ha | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hare/module/types.ha b/hare/module/types.ha
index 8a146f58..96469b72 100644
--- a/hare/module/types.ha
+++ b/hare/module/types.ha
@@ -31,6 +31,9 @@ export type file_conflict = ![]str;
// Context for another error.
export type errcontext = !(str, *error);

// An empty module
export type empty_module = !str;

// Tagged union of all possible error types. Must be freed with [[finish_error]]
// unless it's passed to [[strerror]].
export type error = !(
@@ -45,6 +48,7 @@ export type error = !(
	tag_has_dot |
	tag_bad_format |
	errcontext |
	empty_module |
);

// A container struct for context, used by [[gather]].
@@ -127,6 +131,9 @@ fn _strerror(e: error, buf: *memio::stream) void = {
		memio::concat(buf, ctx.0, ": ")!;
		_strerror(*ctx.1, buf);
		return;
	case let s: empty_module =>
		memio::join(buf, " ", s, "contains no source. It either is invalid or only provides submodules")!;
		return;
	};
	memio::concat(buf, s)!;
};
-- 
2.43.0

[PATCH hare 2/3] hare::module: Expose that module only contains a readme Export this patch

Add new bool-field 'only_readme' to srcset, which is set to true if a
module only contains a readme.

Signed-off-by: Enno Tensing <tenno@suij.in>
---
 hare/module/srcs.ha | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hare/module/srcs.ha b/hare/module/srcs.ha
index 6ac3f855..7e5e3dff 100644
--- a/hare/module/srcs.ha
+++ b/hare/module/srcs.ha
@@ -38,6 +38,8 @@ export type srcset = struct {
	o: []str,
	// linker scripts (.sc)
	sc: []str,
	// module contains only readme
	only_readme: bool,
};

// Frees the resources associated with a [[srcset]].
@@ -135,6 +137,8 @@ fn path_find(ctx: *context, buf: *path::buffer) (srcset | error) = {
			finish_srcset(&res);
			return not_found;
		};

		res.only_readme = true;
	};

	sort::sort(res.dirs, size(str), &cmp::strs);
@@ -142,6 +146,7 @@ fn path_find(ctx: *context, buf: *path::buffer) (srcset | error) = {
	sort::sort(res.s, size(str), &cmp::strs);
	sort::sort(res.o, size(str), &cmp::strs);
	sort::sort(res.sc, size(str), &cmp::strs);

	return res;
};

-- 
2.43.0

[PATCH hare 3/3] cmd/hare: Error out on empty modules Export this patch

If mod.srcs.only_readme is set, the current module is empty and hare
should not continue with the compilation. However with only that check
is present 'make check' fails, with the message 'module hare is empty'.

To prevent this, don't check for empty modules if ctx.test is true.

Signed-off-by: Enno Tensing <tenno@suij.in>
---
 cmd/hare/build/queue.ha | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/cmd/hare/build/queue.ha b/cmd/hare/build/queue.ha
index 56696672..c2a6ec0c 100644
--- a/cmd/hare/build/queue.ha
+++ b/cmd/hare/build/queue.ha
@@ -119,6 +119,13 @@ fn run_task(ctx: *context, jobs: *[]job, t: *task) (bool | error) = {
		return false;
	};
	let mod = ctx.mods[t.idx];

	// Don't check for empty modules if running tests. At least hare's tests
	// fail if run with out this extra condition.
	if (!ctx.test && mod.srcs.only_readme) {
		return strings::dup(mod.name): module::empty_module;
	};

	let deps = get_deps(ctx, t);
	defer strings::freeall(deps);
	let flags = get_flags(ctx, t)?;
-- 
2.43.0
hare/patches: SUCCESS in 1m13s

[Don't abort() on empty modules][0] from [Enno Tensing][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/49044
[1]: mailto:tenno@suij.in

✓ #1140436 SUCCESS hare/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1140436
✓ #1140435 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1140435
✓ #1140434 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1140434
i figured out what was causing the error in the first place, see
https://lists.sr.ht/~sircmpwn/hare-dev/patches/49205