hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 43f098bf0d7a4281e65be7967dc5175fafcf9497
parent d30d92c80786c9ea82bf1b23cb2f788680b3d198
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date:   Tue,  1 Oct 2024 18:03:27 +0200

cmd/hare: New options for hare deps recursivity

Recursive meaning either transitive dependencies that are considered by
default without the new -D option or submodules that are omitted unless
the new -s option is used.

Signed-off-by: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>

Diffstat:
Mcmd/hare/deps.ha | 23+++++++++++++++++++++--
Mcmd/hare/main.ha | 2++
Mdocs/hare-deps.1.scd | 9+++++++++
3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/cmd/hare/deps.ha b/cmd/hare/deps.ha @@ -28,13 +28,19 @@ fn deps(name: str, cmd: *getopt::command) (void | error) = { let build_dir: str = ""; let goal = deps_fmt::TERM; + let recursive = true; + let submodules = false; for (let opt .. cmd.opts) { switch (opt.0) { + case 'D' => + recursive = false; case 'd' => goal = deps_fmt::DOT; case 'T' => merge_tags(&tags, opt.1)?; + case 's' => + submodules = true; case => abort(); }; @@ -53,6 +59,7 @@ fn deps(name: str, cmd: *getopt::command) (void | error) = { tags = tags, }; let mods: []module::module = []; + defer module::free_slice(mods); let mod = match (parse::identstr(input)) { case let id: ast::ident => @@ -62,8 +69,20 @@ fn deps(name: str, cmd: *getopt::command) (void | error) = { path::set(&buf, os::realpath(input)?)?; yield &buf; }; - module::gather(&ctx, &mods, mod)?; - defer module::free_slice(mods); + + if (submodules) { + module::gather_submodules(&ctx, &mods, mod, recursive)?; + }; + + match (module::gather(&ctx, &mods, mod, recursive)) { + case let err: module::error => + if (!(module::unwrap_error(err) is module::not_found) || + len(mods) == 0) { + return err; + }; + case => + void; + }; switch (goal) { case deps_fmt::TERM => diff --git a/cmd/hare/main.ha b/cmd/hare/main.ha @@ -45,7 +45,9 @@ const help: []getopt::help = [ ]: []getopt::help), ("deps", [ "prints dependency information for a Hare program", + ('D', "only print direct dependencies"), ('d', "print dot syntax for use with graphviz"), + ('s', "recursively collect submodules"), ('T', "tagset", "set/unset build tags"), "[path|module]", ]: []getopt::help), diff --git a/docs/hare-deps.1.scd b/docs/hare-deps.1.scd @@ -24,9 +24,18 @@ characters. *-h* Print the help text. +*-D* + Print only the direct dependencies of the module, and its submodules + with the *-s* option. + *-d* Print the dependency tree as a dot file for use with *graphviz*(1). +*-s* + Recursively collect submodules below the specified path or module's + directory. A path should be a source directory to reliably collect + dependencies. + *-T* _tagset_ Set or unset build tags. See *BUILD TAGS* in *hare-module*(5).