Add the quickbin command to jpm.

This is useful for making one off executable scripts
without needing to set up a project.janet file.
This commit is contained in:
Calvin Rose 2019-10-29 20:33:18 -05:00
parent 03824dd9f7
commit cf19cd5292
5 changed files with 27 additions and 6 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased ## Unreleased
- Add the `quickbin` command to jpm.
- Create shell.c when making the amlagamated source. This can be compiled with - Create shell.c when making the amlagamated source. This can be compiled with
janet.c to make the janet interpreter. janet.c to make the janet interpreter.
- Add `cli-main` function to the core, which invokes Janet's CLI interface. - Add `cli-main` function to the core, which invokes Janet's CLI interface.

View File

@ -346,6 +346,8 @@ test-install:
&& jpm --verbose build \ && jpm --verbose build \
&& jpm --verbose test \ && jpm --verbose test \
&& build/testexec \ && build/testexec \
&& jpm --verbose quickbin testexec.janet build/testexec2 \
&& build/testexec2 \
&& jpm --verbose --modpath=. install https://github.com/janet-lang/json.git && jpm --verbose --modpath=. install https://github.com/janet-lang/json.git
build/embed_janet.o: build/janet.c $(JANET_HEADERS) build/embed_janet.o: build/janet.c $(JANET_HEADERS)

View File

@ -464,17 +464,17 @@ int main(int argc, const char **argv) {
} }
/* Create enviornment */ /* Create enviornment */
JanetTable *runtimeEnv = janet_table(0); temptab = janet_table(0);
runtimeEnv->proto = env; temptab = env;
janet_table_put(runtimeEnv, janet_ckeywordv("args"), janet_wrap_array(args)); janet_table_put(temptab, janet_ckeywordv("args"), janet_wrap_array(args));
janet_gcroot(janet_wrap_table(runtimeEnv)); janet_gcroot(janet_wrap_table(temptab));
/* Unlock GC */ /* Unlock GC */
janet_gcunlock(handle); janet_gcunlock(handle);
/* Run everything */ /* Run everything */
JanetFiber *fiber = janet_fiber(janet_unwrap_function(marsh_out), 64, argc, args->data); JanetFiber *fiber = janet_fiber(janet_unwrap_function(marsh_out), 64, argc, args->data);
fiber->env = runtimeEnv; fiber->env = temptab;
Janet out; Janet out;
JanetSignal result = janet_continue(fiber, janet_wrap_nil(), &out); JanetSignal result = janet_continue(fiber, janet_wrap_nil(), &out);
if (result) { if (result) {
@ -843,6 +843,7 @@ Subcommands are:
or (rule "ouput.file" [deps...] ...). or (rule "ouput.file" [deps...] ...).
rules : list rules available with run. rules : list rules available with run.
update-pkgs : Update the current package listing from the remote git repository selected. 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.
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)
@ -900,6 +901,11 @@ Flags are:
[] []
(install-git (dyn :pkglist default-pkglist))) (install-git (dyn :pkglist default-pkglist)))
(defn- quickbin
[input output]
(create-executable @{} input output)
(do-rule output))
(def- subcommands (def- subcommands
{"build" build {"build" build
"clean" clean "clean" clean
@ -912,7 +918,8 @@ Flags are:
"run" local-rule "run" local-rule
"rules" list-rules "rules" list-rules
"update-pkgs" update-pkgs "update-pkgs" update-pkgs
"uninstall" uninstall-cmd}) "uninstall" uninstall-cmd
"quickbin" quickbin})
(def- args (tuple/slice (dyn :args) 1)) (def- args (tuple/slice (dyn :args) 1))
(def- len (length args)) (def- len (length args))

View File

@ -179,6 +179,10 @@ call jpm --verbose --modpath=. install https://github.com/janet-lang/json.git
@if errorlevel 1 goto :TESTFAIL @if errorlevel 1 goto :TESTFAIL
call build\testexec call build\testexec
@if errorlevel 1 goto :TESTFAIL @if errorlevel 1 goto :TESTFAIL
call jpm --verbose quickbin testexec.janet build\testexec2
@if errorlevel 1 goto :TESTFAIL
call build\testexec2
@if errorlevel 1 goto :TESTFAIL
popd popd
exit /b 0 exit /b 0

7
jpm.1
View File

@ -138,6 +138,13 @@ List all rules that can be run via run. This is useful for exploring rules in th
.BR update-pkgs .BR update-pkgs
Update the package listing by installing the 'pkgs' package. Same as jpm install pkgs Update the package listing by installing the 'pkgs' package. Same as jpm install pkgs
.TP
.BR quickbin [\fBentry\fR] [\fBexecutable\fR]
Create a standalone, statically linked executable from a Janet source file that contains a main function.
The main function is the entry point of the program and will receive command line arguments
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.
.SH ENVIRONMENT .SH ENVIRONMENT
.B JANET_PATH .B JANET_PATH