1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-18 03:09:56 +00:00

Add jpm rule-tree.

Useful for debugging jpm project.janet files.
This tree printing logic can also be reused for
showing dependency information in the future.
This commit is contained in:
Calvin Rose 2020-04-20 18:32:25 -05:00
parent 63812c9f80
commit d8617514f8
3 changed files with 43 additions and 0 deletions

View File

@ -859,6 +859,25 @@ int main(int argc, const char **argv) {
(add-body "install"
(spit newname bat))))
(def- tree-l " └─")
(def- tree-t " ├─")
(def- tree-i " │ ")
(def- tree-s " ")
(defn- print-rule-tree
"Show dependencies for a given rule recursively in a nice tree."
[root depth prefix prefix-part]
(printf "%s%s" prefix root)
(def rules (getrules))
(when-let [[root-deps] (rules root)]
(def l (-> root-deps length dec))
(when (pos? depth)
(eachp [i d] (sorted root-deps)
(def is-last (= i l))
(print-rule-tree
d (dec depth)
(string prefix-part (if is-last tree-l tree-t))
(string prefix-part (if is-last tree-s tree-i)))))))
(defn declare-archive
"Build a janet archive. This is a file that bundles together many janet
scripts into a janet image. This file can the be moved to any machine with
@ -973,6 +992,10 @@ Subcommands are:
run rule : run a rule. Can also run custom rules added via (phony "task" [deps...] ...)
or (rule "ouput.file" [deps...] ...).
rules : list rules available with run.
rule-tree (root rule) (depth) : Print a nice tree to see what rules depend on other rules.
Optinally provide a root rule to start printing from, and a
max depth to print. Without these options, all rules will print
their full dependency tree.
update-pkgs : Update the current package listing from the remote git repository selected.
quickbin entry executable : Create an executable from a janet script with a main function.
make-lockfile (lockfile) : Create a lockfile based on repositories in the cache. The
@ -1041,6 +1064,15 @@ Flags are:
[]
(local-rule "install-deps" true))
(defn show-rule-tree
[&opt root depth]
(import-rules "./project.janet" true)
(def max-depth (if depth (scan-number depth) math/inf))
(if root
(print-rule-tree root max-depth "" "")
(let [ks (sort (seq [k :keys (dyn :rules)] k))]
(each k ks (print-rule-tree k max-depth "" "")))))
(defn list-rules
[&opt ctx]
(import-rules "./project.janet" true)
@ -1086,6 +1118,7 @@ Flags are:
"help" help
"deps" deps
"repl" jpm-repl
"rule-tree" show-rule-tree
"show-paths" show-paths
"clear-cache" clear-cache
"run" local-rule

6
jpm.1
View File

@ -143,6 +143,12 @@ like make. run will run a single rule or build a single file.
.BR rules
List all rules that can be run via run. This is useful for exploring rules in the project.
.TP
.BR rule-tree\ [\fBroot\fR] [\fdepth\fR]
Show rule dependency tree in a pretty format. Optionally provide a rule to use as the tree
root, as well as a max depth to print. By default, prints the full tree for all rules. This
can be quite long, so it is recommended to give a root rule.
.TP
.BR show-paths
Show all of the paths used when installing and building artifacts.

View File

@ -45,6 +45,10 @@
/* #define JANET_NO_DOCSTRINGS */
/* #define JANET_NO_SOURCEMAPS */
/* #define JANET_REDUCED_OS */
/* #define JANET_OS_NO_EXECUTE */
/* #define JANET_OS_NO_TIME */
/* #define JANET_OS_NO_FS */
/* #define JANET_OS_NO_ENV */
/* Other settings */
/* #define JANET_NO_ASSEMBLER */