aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2019-05-28 09:49:10 -0400
committerCalvin Rose <calsrose@gmail.com>2019-05-28 09:49:10 -0400
commit09ab391d13dbb0bbdb7cb3471fdacbecc6f86874 (patch)
treef07f5d7800e5b21ce9d69f73c177f74df907c565 /tools
parentMore work on cook and jpm. (diff)
Add import-rules to cook.
First steps to recursive rules. Just needs normalized paths relative to the directory of the imported file.
Diffstat (limited to 'tools')
-rw-r--r--tools/cook.janet34
-rwxr-xr-xtools/jpm2
2 files changed, 28 insertions, 8 deletions
diff --git a/tools/cook.janet b/tools/cook.janet
index 25812a78..76e514a8 100644
--- a/tools/cook.janet
+++ b/tools/cook.janet
@@ -6,6 +6,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")))
diff --git a/tools/jpm b/tools/jpm
index 12bf5b10..a612cc2a 100755
--- a/tools/jpm
+++ b/tools/jpm
@@ -4,7 +4,7 @@
(import cook :prefix "")
-(dofile "./project.janet" :env (fiber/getenv (fiber/current)))
+(import-rules "./project.janet")
(def- argpeg
(peg/compile