mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Add jpm repl subcommand and post-deps macro for jpm.
This will allow more flexibility in writing jpm project files.
This commit is contained in:
		| @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. | |||||||
| - Add os/umask | - Add os/umask | ||||||
| - Add os/perm-int | - Add os/perm-int | ||||||
| - Add os/perm-string | - Add os/perm-string | ||||||
|  | - Add :octal-permissions option for os/stat. | ||||||
|  | - Add `jpm repl` subcommand, as well as `post-deps` macro in project.janet files. | ||||||
|  |  | ||||||
| ## 1.8.1 - 2020-03-31 | ## 1.8.1 - 2020-03-31 | ||||||
| - Fix bugs for big endian systems | - Fix bugs for big endian systems | ||||||
|   | |||||||
							
								
								
									
										73
									
								
								auxbin/jpm
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								auxbin/jpm
									
									
									
									
									
								
							| @@ -181,11 +181,12 @@ | |||||||
|       (put into k (x k)))) |       (put into k (x k)))) | ||||||
|   into) |   into) | ||||||
|  |  | ||||||
| (defn import-rules | (defn require-jpm | ||||||
|   "Import another file that defines more rules. This ruleset |   "Require a jpm file project file. This is different from a normal require | ||||||
|   is merged into the current ruleset." |   in that code is loaded in the jpm environment." | ||||||
|   [path] |   [path &opt no-deps] | ||||||
|   (def env (make-env)) |   (def env (make-env)) | ||||||
|  |   (put env :jpm-no-deps no-deps) | ||||||
|   (unless (os/stat path :mode) |   (unless (os/stat path :mode) | ||||||
|     (error (string "cannot open " path))) |     (error (string "cannot open " path))) | ||||||
|   (loop [k :keys _env :when (symbol? k)] |   (loop [k :keys _env :when (symbol? k)] | ||||||
| @@ -194,9 +195,24 @@ | |||||||
|   (loop [k :keys currenv :when (keyword? k)] |   (loop [k :keys currenv :when (keyword? k)] | ||||||
|     (put env k (currenv k))) |     (put env k (currenv k))) | ||||||
|   (dofile path :env env :exit true) |   (dofile path :env env :exit true) | ||||||
|  |   env) | ||||||
|  |  | ||||||
|  | (defn import-rules | ||||||
|  |   "Import another file that defines more rules. This ruleset | ||||||
|  |   is merged into the current ruleset." | ||||||
|  |   [path &opt no-deps] | ||||||
|  |   (def env (require-jpm path no-deps)) | ||||||
|   (when-let [rules (env :rules)] (merge-into (getrules) rules)) |   (when-let [rules (env :rules)] (merge-into (getrules) rules)) | ||||||
|   env) |   env) | ||||||
|  |  | ||||||
|  | (defmacro post-deps | ||||||
|  |   "Run code at the top level if jpm dependencies are installed. Build | ||||||
|  |   code that imports dependencies should be wrapped with this macro, as project.janet | ||||||
|  |   needs to be able to run successfully even without dependencies installed." | ||||||
|  |   [& body] | ||||||
|  |   (unless (dyn :jpm-no-deps) | ||||||
|  |     ~',(reduce |(eval $1) nil body))) | ||||||
|  |  | ||||||
| # | # | ||||||
| # OS and shell helpers | # OS and shell helpers | ||||||
| # | # | ||||||
| @@ -914,8 +930,8 @@ int main(int argc, const char **argv) { | |||||||
|     '(* "--" '(some (if-not "=" 1)) (+ (* "=" '(any 1)) -1)))) |     '(* "--" '(some (if-not "=" 1)) (+ (* "=" '(any 1)) -1)))) | ||||||
|  |  | ||||||
| (defn- local-rule | (defn- local-rule | ||||||
|   [rule] |   [rule &opt no-deps] | ||||||
|   (import-rules "./project.janet") |   (import-rules "./project.janet" no-deps) | ||||||
|   (do-rule rule)) |   (do-rule rule)) | ||||||
|  |  | ||||||
| (defn- help | (defn- help | ||||||
| @@ -950,6 +966,8 @@ Subcommands are: | |||||||
|             name is lockfile.janet. |             name is lockfile.janet. | ||||||
|   load-lockfile (lockfile) : Install modules from a lockfile in a reproducible way. The |   load-lockfile (lockfile) : Install modules from a lockfile in a reproducible way. The | ||||||
|                              default lockfile name is lockfile.janet. |                              default lockfile name is lockfile.janet. | ||||||
|  |   repl : Run a repl in the context of the current project.janet file. This lets you run rules and | ||||||
|  |          otherwise debug the current project.janet file. | ||||||
|  |  | ||||||
| Keys are: | Keys are: | ||||||
|   --modpath : The directory to install modules to. Defaults to $JANET_MODPATH, $JANET_PATH, or (dyn :syspath) |   --modpath : The directory to install modules to. Defaults to $JANET_MODPATH, $JANET_PATH, or (dyn :syspath) | ||||||
| @@ -963,15 +981,16 @@ Keys are: | |||||||
|   --pkglist : URL of git repository for package listing. Defaults to $JANET_PKGLIST or https://github.com/janet-lang/pkgs.git |   --pkglist : URL of git repository for package listing. Defaults to $JANET_PKGLIST or https://github.com/janet-lang/pkgs.git | ||||||
|  |  | ||||||
| Flags are: | Flags are: | ||||||
|  |   --nocolor : Disable color in the jpm repl. | ||||||
|   --verbose : Print shell commands as they are executed. |   --verbose : Print shell commands as they are executed. | ||||||
|   --test : If passed to jpm install, runs tests before installing. Will run tests recursively on dependencies. |   --test : If passed to jpm install, runs tests before installing. Will run tests recursively on dependencies. | ||||||
|     `)) |     `)) | ||||||
|  |  | ||||||
| (defn- show-help | (defn show-help | ||||||
|   [] |   [] | ||||||
|   (print help)) |   (print help)) | ||||||
|  |  | ||||||
| (defn- show-paths | (defn show-paths | ||||||
|   [] |   [] | ||||||
|   (print "binpath:    " (dyn :binpath JANET_BINPATH)) |   (print "binpath:    " (dyn :binpath JANET_BINPATH)) | ||||||
|   (print "modpath:    " (dyn :modpath JANET_MODPATH)) |   (print "modpath:    " (dyn :modpath JANET_MODPATH)) | ||||||
| @@ -979,21 +998,21 @@ Flags are: | |||||||
|   (print "headerpath: " (dyn :headerpath JANET_HEADERPATH)) |   (print "headerpath: " (dyn :headerpath JANET_HEADERPATH)) | ||||||
|   (print "syspath:    " (dyn :syspath))) |   (print "syspath:    " (dyn :syspath))) | ||||||
|  |  | ||||||
| (defn- build | (defn build | ||||||
|   [] |   [] | ||||||
|   (local-rule "build")) |   (local-rule "build")) | ||||||
|  |  | ||||||
| (defn- clean | (defn clean | ||||||
|   [] |   [] | ||||||
|   (local-rule "clean")) |   (local-rule "clean")) | ||||||
|  |  | ||||||
| (defn- install | (defn install | ||||||
|   [&opt repo] |   [&opt repo] | ||||||
|   (if repo |   (if repo | ||||||
|     (install-git repo) |     (install-git repo) | ||||||
|     (local-rule "install"))) |     (local-rule "install"))) | ||||||
|  |  | ||||||
| (defn- test | (defn test | ||||||
|   [] |   [] | ||||||
|   (local-rule "test")) |   (local-rule "test")) | ||||||
|  |  | ||||||
| @@ -1003,25 +1022,40 @@ Flags are: | |||||||
|     (uninstall what) |     (uninstall what) | ||||||
|     (local-rule "uninstall"))) |     (local-rule "uninstall"))) | ||||||
|  |  | ||||||
| (defn- deps | (defn deps | ||||||
|   [] |   [] | ||||||
|   (local-rule "install-deps")) |   (local-rule "install-deps" true)) | ||||||
|  |  | ||||||
| (defn- list-rules | (defn list-rules | ||||||
|   [] |   [&opt ctx] | ||||||
|   (import-rules "./project.janet") |   (import-rules "./project.janet" true) | ||||||
|   (def ks (sort (seq [k :keys (dyn :rules)] k))) |   (def ks (sort (seq [k :keys (dyn :rules)] k))) | ||||||
|   (each k ks (print k))) |   (each k ks (print k))) | ||||||
|  |  | ||||||
| (defn- update-pkgs | (defn update-pkgs | ||||||
|   [] |   [] | ||||||
|   (install-git (dyn :pkglist default-pkglist))) |   (install-git (dyn :pkglist default-pkglist))) | ||||||
|  |  | ||||||
| (defn- quickbin | (defn quickbin | ||||||
|   [input output] |   [input output] | ||||||
|   (create-executable @{} input output) |   (create-executable @{} input output) | ||||||
|   (do-rule output)) |   (do-rule output)) | ||||||
|  |  | ||||||
|  | (defn jpm-repl | ||||||
|  |   [] | ||||||
|  |   (def env (require-jpm "./project.janet")) | ||||||
|  |   (def p (env :project)) | ||||||
|  |   (def name (p :name)) | ||||||
|  |   (setdyn :pretty-format (if-not (dyn :nocolor) "%.20Q" "%.20q")) | ||||||
|  |   (setdyn :err-color (if-not (dyn :nocolor) true)) | ||||||
|  |   (print "Project:     " name) | ||||||
|  |   (print "Repository:  " (p :repo)) | ||||||
|  |   (print "Author:      " (p :author)) | ||||||
|  |   (defn getchunk [buf p] | ||||||
|  |     (def [line] (parser/where p)) | ||||||
|  |     (getline (string "jpm[" name "]:" line ":" (parser/state p :delimiters) "> ") buf env)) | ||||||
|  |   (repl getchunk nil env)) | ||||||
|  |  | ||||||
| (def- subcommands | (def- subcommands | ||||||
|   {"build" build |   {"build" build | ||||||
|    "clean" clean |    "clean" clean | ||||||
| @@ -1030,6 +1064,7 @@ Flags are: | |||||||
|    "test" test |    "test" test | ||||||
|    "help" help |    "help" help | ||||||
|    "deps" deps |    "deps" deps | ||||||
|  |    "repl" jpm-repl | ||||||
|    "show-paths" show-paths |    "show-paths" show-paths | ||||||
|    "clear-cache" clear-cache |    "clear-cache" clear-cache | ||||||
|    "run" local-rule |    "run" local-rule | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								jpm.1
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								jpm.1
									
									
									
									
									
								
							| @@ -24,6 +24,10 @@ More interesting are the local commands. For more information on jpm usage, see | |||||||
|  |  | ||||||
| .SH FLAGS | .SH FLAGS | ||||||
|  |  | ||||||
|  | .TP | ||||||
|  | .BR \-\-nocolor | ||||||
|  | Disable color in the jpm repl. | ||||||
|  |  | ||||||
| .TP | .TP | ||||||
| .BR \-\-verbose | .BR \-\-verbose | ||||||
| Print detailed messages of what jpm is doing, including compilation commands and other shell commands. | Print detailed messages of what jpm is doing, including compilation commands and other shell commands. | ||||||
| @@ -154,6 +158,11 @@ The main function is the entry point of the program and will receive command lin | |||||||
| as function arguments. The entry file can import other modules, including native C modules, and | as function arguments. The entry file can import other modules, including native C modules, and | ||||||
| jpm will attempt to include the dependencies into the generated executable. | jpm will attempt to include the dependencies into the generated executable. | ||||||
|  |  | ||||||
|  | .TP | ||||||
|  | .BR repl | ||||||
|  | Load the current project.janet file and start a repl in it's environment. This lets a user better | ||||||
|  | debug the project file, as well as run rules manually. | ||||||
|  |  | ||||||
| .SH ENVIRONMENT | .SH ENVIRONMENT | ||||||
|  |  | ||||||
| .B JANET_PATH | .B JANET_PATH | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose