~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] hare/module: update context.paths initialization

Details
Message ID
<20221224130728.22040-1-vyivel@eclair.cafe>
DKIM signature
missing
Download raw message
Patch: +27 -18
This commit utilizes strings::tokenize(), merges similar code paths, and
allows multiple dependency vendoring.

Dependencies are included in lexicographical order. Assuming the
following directory structure:

vendor/
  dependency-1/
    alice/
      mod.ha
  dependency-2/
    bob/
      mod.ha
  dependency-3/
    bob/
      mod.ha
    carol/
      mod.ha

The following imports will work:

use alice;
use bob;
use carol;

Where bob will refer to the dependency-3's module.

Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
---
 hare/module/context.ha | 45 +++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/hare/module/context.ha b/hare/module/context.ha
index d4a15b66..f28f1a01 100644
--- a/hare/module/context.ha
+++ b/hare/module/context.ha
@@ -5,6 +5,7 @@
use dirs;
use fmt;
use fs;
use glob;
use hare::ast;
use os;
use path;
@@ -35,26 +36,34 @@ export fn context_init(tags: []tag, defs: []str, harepath: str) context = {
		fs = os::cwd,
		tags = tags,
		defines = defs,
		paths = match (os::getenv("HAREPATH")) {
		case void =>
			// TODO: Use strings::tokenize here
			let sl = strings::split(harepath, ":");
			defer free(sl);
			let path: []str = alloc([], len(sl) + 1);
			for (let i = 0z; i < len(sl); i += 1) {
				append(path, strings::dup(sl[i]));
		paths = {
			let harepath = match (os::getenv("HAREPATH")) {
			case void =>
				yield harepath;
			case let s: str =>
				yield s;
			};
			append(path, strings::dup("vendor"));
			append(path, strings::dup("."));
			yield path;
		case let s: str =>
			let sl = strings::split(s, ":");
			defer free(sl);
			let path: []str = alloc([], len(sl) + 1);
			for (let i = 0z; i < len(sl); i += 1) {
				append(path, strings::dup(sl[i]));

			let path: []str = [];
			let tok = strings::tokenize(harepath, ":");
			for (true) match (strings::next_token(&tok)) {
			case void =>
				break;
			case let s: str =>
				append(path, strings::dup(s));
			};

			let vendor = glob::glob("vendor/*");
			defer glob::finish(&vendor);
			for (true) match (glob::next(&vendor)) {
			case void =>
				break;
			case glob::failure =>
				void; // XXX: Anything else?
			case let s: str =>
				append(path, strings::dup(s));
			};
			append(path, strings::dup("vendor"));

			append(path, strings::dup("."));
			yield path;
		},
-- 
2.39.0

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CPA2LZJ99I9E.2T3F3BVUVTFWW@cirno2>
In-Reply-To
<20221224130728.22040-1-vyivel@eclair.cafe> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m32s

[hare/module: update context.paths initialization][0] from [Kirill Primak][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/37744
[1]: vyivel@eclair.cafe

✓ #910945 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/910945
✓ #910946 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/910946
Details
Message ID
<CPTNV62AE28G.F58OGQ4SH9W1@taiga>
In-Reply-To
<20221224130728.22040-1-vyivel@eclair.cafe> (view parent)
DKIM signature
missing
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   3c5b4260..713488b1  master -> master
Reply to thread Export thread (mbox)