1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 14:44:48 +00:00

Add import-rules to cook.

First steps to recursive rules. Just needs normalized paths
relative to the directory of the imported file.
This commit is contained in:
Calvin Rose 2019-05-28 09:49:10 -04:00
parent 7569930b0c
commit 09ab391d13
2 changed files with 28 additions and 8 deletions

View File

@ -5,6 +5,17 @@
###
### Copyright 2019 © Calvin Rose
#
# Basic Path Settings
#
# Windows is the OS outlier
(def- is-win (= (os/which) :windows))
(def- is-mac (= (os/which) :macos))
(def- sep (if is-win "\\" "/"))
(def- objext (if is-win ".obj" ".o"))
(def- modext (if is-win ".dll" ".so"))
#
# Rule Engine
#
@ -80,17 +91,26 @@
(thunk))
(unless phony target))
(def- _env (fiber/getenv (fiber/current)))
(defn- import-rules*
[path & args]
(def [realpath] (module/find path))
(def env (make-env))
(loop [k :keys _env :when (symbol? k)]
(unless ((_env k) :private) (put env k (_env k))))
(require path :env env ;args)
(when-let [rules (env :rules)] (merge-into (getrules) rules)))
(defmacro import-rules
"Import another file that defines more cook rules. This ruleset
is merged into the current ruleset."
[path & args]
~(,import-rules* ,(string path) ,;args))
#
# Configuration
#
# Windows is the OS outlier
(def- is-win (= (os/which) :windows))
(def- is-mac (= (os/which) :macos))
(def- sep (if is-win "\\" "/"))
(def- objext (if is-win ".obj" ".o"))
(def- modext (if is-win ".dll" ".so"))
# Get default paths and options from environment
(def PREFIX (or (os/getenv "PREFIX")
(if is-win "C:\\Janet" "/usr/local")))

View File

@ -4,7 +4,7 @@
(import cook :prefix "")
(dofile "./project.janet" :env (fiber/getenv (fiber/current)))
(import-rules "./project.janet")
(def- argpeg
(peg/compile