mirror of
https://github.com/janet-lang/janet
synced 2024-11-19 07:04:48 +00:00
Update cook and add an install test.
This commit is contained in:
parent
529b34d84e
commit
0d3986abbb
@ -91,23 +91,6 @@
|
|||||||
(thunk))
|
(thunk))
|
||||||
(unless phony target))
|
(unless phony target))
|
||||||
|
|
||||||
(def- _env (fiber/getenv (fiber/current)))
|
|
||||||
|
|
||||||
(defn import-rules
|
|
||||||
"Import another file that defines more cook rules. This ruleset
|
|
||||||
is merged into the current ruleset."
|
|
||||||
[path]
|
|
||||||
(def env (make-env))
|
|
||||||
(unless (os/stat path :mode)
|
|
||||||
(error (string "cannot open " path)))
|
|
||||||
(loop [k :keys _env :when (symbol? k)]
|
|
||||||
(unless ((_env k) :private) (put env k (_env k))))
|
|
||||||
(def currenv (fiber/getenv (fiber/current)))
|
|
||||||
(loop [k :keys currenv :when (keyword? k)]
|
|
||||||
(put env k (currenv k)))
|
|
||||||
(dofile path :env env)
|
|
||||||
(when-let [rules (env :rules)] (merge-into (getrules) rules)))
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Configuration
|
# Configuration
|
||||||
#
|
#
|
||||||
@ -115,7 +98,7 @@
|
|||||||
# Installation settings
|
# Installation settings
|
||||||
(def JANET_MODPATH (or (os/getenv "JANET_MODPATH") (dyn :syspath)))
|
(def JANET_MODPATH (or (os/getenv "JANET_MODPATH") (dyn :syspath)))
|
||||||
(def JANET_HEADERPATH (os/getenv "JANET_HEADERPATH"))
|
(def JANET_HEADERPATH (os/getenv "JANET_HEADERPATH"))
|
||||||
(def JANET_BINPATH (or (os/getenv "JANET_BINPATH") (unless is-win "/usr/local/bin")))
|
(def JANET_BINPATH (os/getenv "JANET_BINPATH"))
|
||||||
|
|
||||||
# Compilation settings
|
# Compilation settings
|
||||||
(def- OPTIMIZE (or (os/getenv "OPTIMIZE") 2))
|
(def- OPTIMIZE (or (os/getenv "OPTIMIZE") 2))
|
||||||
@ -150,6 +133,35 @@
|
|||||||
(error (string "option :" key " not set")))
|
(error (string "option :" key " not set")))
|
||||||
ret)
|
ret)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Importing a file
|
||||||
|
#
|
||||||
|
|
||||||
|
(def- _env (fiber/getenv (fiber/current)))
|
||||||
|
|
||||||
|
(defn- proto-flatten
|
||||||
|
[into x]
|
||||||
|
(when x
|
||||||
|
(proto-flatten into (table/getproto x))
|
||||||
|
(loop [k :keys x]
|
||||||
|
(put into k (x k))))
|
||||||
|
into)
|
||||||
|
|
||||||
|
(defn import-rules
|
||||||
|
"Import another file that defines more cook rules. This ruleset
|
||||||
|
is merged into the current ruleset."
|
||||||
|
[path]
|
||||||
|
(def env (make-env))
|
||||||
|
(unless (os/stat path :mode)
|
||||||
|
(error (string "cannot open " path)))
|
||||||
|
(loop [k :keys _env :when (symbol? k)]
|
||||||
|
(unless ((_env k) :private) (put env k (_env k))))
|
||||||
|
(def currenv (proto-flatten @{} (fiber/getenv (fiber/current))))
|
||||||
|
(loop [k :keys currenv :when (keyword? k)]
|
||||||
|
(put env k (currenv k)))
|
||||||
|
(dofile path :env env)
|
||||||
|
(when-let [rules (env :rules)] (merge-into (getrules) rules)))
|
||||||
|
|
||||||
#
|
#
|
||||||
# OS and shell helpers
|
# OS and shell helpers
|
||||||
#
|
#
|
||||||
@ -237,7 +249,7 @@
|
|||||||
"Generate the c flags from the input options."
|
"Generate the c flags from the input options."
|
||||||
[opts]
|
[opts]
|
||||||
@[;(opt opts :cflags CFLAGS)
|
@[;(opt opts :cflags CFLAGS)
|
||||||
(string (if is-win "/I" "-I") (opt opts :headerpath JANET_HEADERPATH))
|
(string (if is-win "/I" "-I") (dyn :headerpath JANET_HEADERPATH))
|
||||||
(string (if is-win "/O" "-O") (opt opts :optimize OPTIMIZE))])
|
(string (if is-win "/O" "-O") (opt opts :optimize OPTIMIZE))])
|
||||||
|
|
||||||
(defn- compile-c
|
(defn- compile-c
|
||||||
@ -262,7 +274,7 @@
|
|||||||
(rule target objects
|
(rule target objects
|
||||||
(print "linking " target "...")
|
(print "linking " target "...")
|
||||||
(if is-win
|
(if is-win
|
||||||
(shell ld ;lflags (string "/OUT:" target) ;objects (string (opt opts :headerpath JANET_HEADERPATH) `\\janet.lib`))
|
(shell ld ;lflags (string "/OUT:" target) ;objects (string (dyn :headerpath JANET_HEADERPATH) `\\janet.lib`))
|
||||||
(shell ld ;cflags `-o` target ;objects ;lflags))))
|
(shell ld ;cflags `-o` target ;objects ;lflags))))
|
||||||
|
|
||||||
(defn- create-buffer-c
|
(defn- create-buffer-c
|
||||||
@ -298,7 +310,7 @@
|
|||||||
|
|
||||||
(def- filepath-replacer
|
(def- filepath-replacer
|
||||||
"Convert url with potential bad characters into a file path element."
|
"Convert url with potential bad characters into a file path element."
|
||||||
(peg/compile ~(% (* (+ (/ '(set "<>:\"/\\|?*") "_") '2)))))
|
(peg/compile ~(% (any (+ (/ '(set "<>:\"/\\|?*") "_") '1)))))
|
||||||
|
|
||||||
(defn repo-id
|
(defn repo-id
|
||||||
"Convert a repo url into a path component that serves as its id."
|
"Convert a repo url into a path component that serves as its id."
|
||||||
@ -308,24 +320,24 @@
|
|||||||
(defn find-manifest-dir
|
(defn find-manifest-dir
|
||||||
"Get the path to the directory containing manifests for installed
|
"Get the path to the directory containing manifests for installed
|
||||||
packages."
|
packages."
|
||||||
[&opt opts]
|
[]
|
||||||
(string (opt (or opts @{}) :modpath JANET_MODPATH) sep ".manifests"))
|
(string (dyn :modpath JANET_MODPATH) sep ".manifests"))
|
||||||
|
|
||||||
(defn find-manifest
|
(defn find-manifest
|
||||||
"Get the full path of a manifest file given a package name."
|
"Get the full path of a manifest file given a package name."
|
||||||
[name &opt opts]
|
[name]
|
||||||
(string (find-manifest-dir opts) sep name ".txt"))
|
(string (find-manifest-dir) sep name ".txt"))
|
||||||
|
|
||||||
(defn find-cache
|
(defn find-cache
|
||||||
"Return the path to the global cache."
|
"Return the path to the global cache."
|
||||||
[&opt opts]
|
[]
|
||||||
(def path (opt (or opts @{}) :modpath JANET_MODPATH))
|
(def path (dyn :modpath JANET_MODPATH))
|
||||||
(string path sep ".cache"))
|
(string path sep ".cache"))
|
||||||
|
|
||||||
(defn uninstall
|
(defn uninstall
|
||||||
"Uninstall bundle named name"
|
"Uninstall bundle named name"
|
||||||
[name &opt opts]
|
[name]
|
||||||
(def manifest (find-manifest name opts))
|
(def manifest (find-manifest name))
|
||||||
(def f (file/open manifest :r))
|
(def f (file/open manifest :r))
|
||||||
(unless f (print manifest " does not exist") (break))
|
(unless f (print manifest " does not exist") (break))
|
||||||
(loop [line :iterate (:read f :line)]
|
(loop [line :iterate (:read f :line)]
|
||||||
@ -341,14 +353,14 @@
|
|||||||
|
|
||||||
(defn clear-cache
|
(defn clear-cache
|
||||||
"Clear the global git cache."
|
"Clear the global git cache."
|
||||||
[&opt opts]
|
[]
|
||||||
(rm (find-cache opts)))
|
(rm (find-cache)))
|
||||||
|
|
||||||
(defn install-git
|
(defn install-git
|
||||||
"Install a bundle from git. If the bundle is already installed, the bundle
|
"Install a bundle from git. If the bundle is already installed, the bundle
|
||||||
is reinistalled (but not rebuilt if artifacts are cached)."
|
is reinistalled (but not rebuilt if artifacts are cached)."
|
||||||
[repo &opt opts]
|
[repo]
|
||||||
(def cache (find-cache opts))
|
(def cache (find-cache))
|
||||||
(os/mkdir cache)
|
(os/mkdir cache)
|
||||||
(def id (repo-id repo))
|
(def id (repo-id repo))
|
||||||
(def module-dir (string cache sep id))
|
(def module-dir (string cache sep id))
|
||||||
@ -400,31 +412,30 @@
|
|||||||
(compile-c opts c-src o-src)))
|
(compile-c opts c-src o-src)))
|
||||||
(link-c opts lname ;objects)
|
(link-c opts lname ;objects)
|
||||||
(add-dep "build" lname)
|
(add-dep "build" lname)
|
||||||
(def path (opt opts :modpath JANET_MODPATH))
|
(def path (dyn :modpath JANET_MODPATH))
|
||||||
(install-rule lname path))
|
(install-rule lname path))
|
||||||
|
|
||||||
(defn declare-source
|
(defn declare-source
|
||||||
"Create a Janet modules. This does not actually build the module(s),
|
"Create a Janet modules. This does not actually build the module(s),
|
||||||
but registers it for packaging and installation."
|
but registers it for packaging and installation."
|
||||||
[&keys opts]
|
[&keys {:source sources}]
|
||||||
(def sources (opts :source))
|
(def path (dyn :modpath JANET_MODPATH))
|
||||||
(def path (opt opts :modpath JANET_MODPATH))
|
(if (bytes? sources)
|
||||||
(each s sources
|
(install-rule sources path)
|
||||||
(install-rule s path)))
|
(each s sources
|
||||||
|
(install-rule s path))))
|
||||||
|
|
||||||
(defn declare-bin
|
(defn declare-bin
|
||||||
"Declare a generic file to be installed as an executable."
|
"Declare a generic file to be installed as an executable."
|
||||||
[&keys opts]
|
[&keys {:main main}]
|
||||||
(def main (opts :main))
|
(install-rule main (dyn :binpath JANET_BINPATH)))
|
||||||
(def binpath (opt opts :binpath JANET_BINPATH))
|
|
||||||
(install-rule main binpath))
|
|
||||||
|
|
||||||
(defn declare-binscript
|
(defn declare-binscript
|
||||||
"Declare a janet file to be installed as an executable script. Creates
|
"Declare a janet file to be installed as an executable script. Creates
|
||||||
a shim on windows."
|
a shim on windows."
|
||||||
[&keys opts]
|
[&keys opts]
|
||||||
(def main (opts :main))
|
(def main (opts :main))
|
||||||
(def binpath (opt opts :binpath JANET_BINPATH))
|
(def binpath (dyn :binpath JANET_BINPATH))
|
||||||
(install-rule main binpath)
|
(install-rule main binpath)
|
||||||
# Create a dud batch file when on windows.
|
# Create a dud batch file when on windows.
|
||||||
(when is-win
|
(when is-win
|
||||||
@ -446,7 +457,7 @@
|
|||||||
(def iname (string "build" sep name ".jimage"))
|
(def iname (string "build" sep name ".jimage"))
|
||||||
(rule iname (or (opts :deps) [])
|
(rule iname (or (opts :deps) [])
|
||||||
(spit iname (make-image (require entry))))
|
(spit iname (make-image (require entry))))
|
||||||
(def path (opt opts :modpath JANET_MODPATH))
|
(def path (dyn :modpath JANET_MODPATH))
|
||||||
(install-rule iname path))
|
(install-rule iname path))
|
||||||
|
|
||||||
(defn declare-project
|
(defn declare-project
|
||||||
|
@ -1782,6 +1782,12 @@
|
|||||||
args))
|
args))
|
||||||
(tuple import* (string path) ;argm))
|
(tuple import* (string path) ;argm))
|
||||||
|
|
||||||
|
(defmacro use
|
||||||
|
"Similar to import, but imported bindings are not prefixed with a namespace
|
||||||
|
identifier. Can also import multiple modules in one shot."
|
||||||
|
[& modules]
|
||||||
|
~(do ,;(map (fn [x] ~(,import* ,(string x) :prefix "")) modules)))
|
||||||
|
|
||||||
(defn repl
|
(defn repl
|
||||||
"Run a repl. The first parameter is an optional function to call to
|
"Run a repl. The first parameter is an optional function to call to
|
||||||
get a chunk of source code that should return nil for end of file.
|
get a chunk of source code that should return nil for end of file.
|
||||||
|
1
test/install/.gitignore
vendored
1
test/install/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/build
|
/build
|
||||||
|
.cache
|
||||||
|
1
test/install/.manifests/json.txt
Normal file
1
test/install/.manifests/json.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
/home/calvin/code/janet/test/install/json.so
|
@ -1,3 +1,8 @@
|
|||||||
(import build/testmod :as testmod)
|
(import build/testmod :as testmod)
|
||||||
|
|
||||||
(if (not= 5 (testmod/get5)) (error "testmod/get5 failed"))
|
(if (not= 5 (testmod/get5)) (error "testmod/get5 failed"))
|
||||||
|
|
||||||
|
(import cook)
|
||||||
|
|
||||||
|
(with-dyns [:modpath (os/cwd)]
|
||||||
|
(cook/install-git "https://github.com/janet-lang/json.git"))
|
||||||
|
Loading…
Reference in New Issue
Block a user