2019-05-27 20:50:57 +00:00
|
|
|
#!/usr/bin/env janet
|
|
|
|
|
2019-05-28 02:14:24 +00:00
|
|
|
# CLI tool for building janet projects. Wraps cook.
|
2019-05-27 20:50:57 +00:00
|
|
|
|
2019-05-29 15:04:38 +00:00
|
|
|
(import cook)
|
2019-05-27 20:50:57 +00:00
|
|
|
|
2019-05-28 02:14:24 +00:00
|
|
|
(def- argpeg
|
|
|
|
(peg/compile
|
|
|
|
'(* "--" '(some (if-not "=" 1)) "=" '(any 1))))
|
|
|
|
|
2019-07-05 16:00:46 +00:00
|
|
|
(defn- local-rule
|
|
|
|
[rule]
|
|
|
|
(cook/import-rules "./project.janet")
|
|
|
|
(cook/do-rule rule))
|
|
|
|
|
2019-05-28 02:14:24 +00:00
|
|
|
(defn- help
|
2019-05-27 20:50:57 +00:00
|
|
|
[]
|
2019-05-28 02:14:24 +00:00
|
|
|
(print `
|
2019-07-05 16:00:46 +00:00
|
|
|
usage: jpm --key=value ... [subcommand] [args]...
|
|
|
|
|
|
|
|
Subcommands are:
|
|
|
|
build : build all artifacts
|
|
|
|
install (repo) : install artifacts. If a repo is given, install the contents of that
|
|
|
|
git repository, assuming that the repository is a jpm project. If not, build
|
|
|
|
and install the current project.
|
|
|
|
uninstall (module) : uninstall a module. If no module is given, uninstall the module
|
|
|
|
defined by the current directory.
|
|
|
|
clean : remove any generated files or artifacts
|
|
|
|
test : run tests
|
|
|
|
deps : install dependencies.
|
|
|
|
clear-cache : clear the git cache. Useful for updating dependencies.
|
2019-05-28 02:14:24 +00:00
|
|
|
|
|
|
|
Keys are:
|
2019-06-19 04:48:57 +00:00
|
|
|
--modpath : The directory to install modules to. Defaults to $JANET_MODPATH or (dyn :syspath)
|
|
|
|
--headerpath : The directory containing janet headers. Defaults to $JANET_HEADERPATH or (dyn :headerpath)
|
2019-05-29 15:04:38 +00:00
|
|
|
--binpath : The directory to install binaries and scripts. Defaults to $JANET_BINPATH.
|
2019-05-28 02:14:24 +00:00
|
|
|
--optimize : Optimization level for natives. Defaults to $OPTIMIZE or 2.
|
2019-06-01 14:38:28 +00:00
|
|
|
--compiler : C compiler to use for natives. Defaults to $COMPILER or cc.
|
2019-05-28 02:14:24 +00:00
|
|
|
--linker : C linker to use for linking natives. Defaults to $LINKER or cc.
|
|
|
|
--cflags : Extra compiler flags for native modules. Defaults to $CFLAGS if set.
|
|
|
|
--lflags : Extra linker flags for native modules. Defaults to $LFLAGS if set.
|
|
|
|
`))
|
|
|
|
|
2019-07-05 16:00:46 +00:00
|
|
|
(defn build
|
|
|
|
[]
|
|
|
|
(local-rule "build"))
|
|
|
|
|
|
|
|
(defn clean
|
|
|
|
[]
|
|
|
|
(local-rule "clean"))
|
|
|
|
|
|
|
|
(defn install
|
|
|
|
[&opt repo]
|
|
|
|
(if repo
|
|
|
|
(cook/install-git repo)
|
|
|
|
(local-rule "install")))
|
|
|
|
|
|
|
|
(defn test
|
|
|
|
[]
|
|
|
|
(local-rule "test"))
|
|
|
|
|
|
|
|
(defn uninstall
|
|
|
|
[&opt what]
|
|
|
|
(if what
|
|
|
|
(cook/uninstall what)
|
|
|
|
(local-rule "uninstall")))
|
|
|
|
|
|
|
|
(defn deps
|
|
|
|
[]
|
|
|
|
(local-rule "install-deps"))
|
|
|
|
|
|
|
|
(def subcommands
|
|
|
|
{"build" build
|
|
|
|
"clean" clean
|
|
|
|
"install" install
|
|
|
|
"test" test
|
|
|
|
"help" help
|
|
|
|
"deps" deps
|
|
|
|
"clear-cache" cook/clear-cache
|
|
|
|
"uninstall" uninstall})
|
|
|
|
|
2019-07-20 21:57:07 +00:00
|
|
|
(def args (tuple/slice (dyn :args) 2))
|
2019-07-05 16:00:46 +00:00
|
|
|
(def len (length args))
|
|
|
|
(var i 0)
|
|
|
|
|
|
|
|
# Get flags
|
|
|
|
(while (< i len)
|
|
|
|
(def arg (args i))
|
|
|
|
(unless (string/has-prefix? "--" arg) (break))
|
|
|
|
(if-let [m (peg/match argpeg arg)]
|
|
|
|
(let [[key value] m]
|
|
|
|
(setdyn (keyword key) value))
|
|
|
|
(print "invalid argument " arg))
|
|
|
|
(++ i))
|
|
|
|
|
|
|
|
# Run subcommand
|
|
|
|
(if (= i len)
|
|
|
|
(help)
|
|
|
|
(do
|
|
|
|
(if-let [com (subcommands (args i))]
|
|
|
|
(com ;(tuple/slice args (+ i 1)))
|
|
|
|
(do
|
|
|
|
(print "invalid command " (args i))
|
|
|
|
(help)))))
|