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:
parent
7569930b0c
commit
09ab391d13
@ -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")))
|
||||
|
Loading…
Reference in New Issue
Block a user