1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 00:10:27 +00:00

Update cook tool to use os/stat for file age.

This commit is contained in:
Calvin Rose 2019-03-31 21:35:44 -04:00
parent e50e77e5f9
commit 429dc70374

View File

@ -17,13 +17,6 @@
(print "Error executing command: " ;args) (print "Error executing command: " ;args)
(os/exit res))) (os/exit res)))
(defn- mkdir
"Make a directory. Not safe for user code."
[path]
(if is-win
(shell "mkdir " path)
(shell "mkdir -p " path)))
(defn- rm (defn- rm
"Remove a directory. Not safe for user code." "Remove a directory. Not safe for user code."
[path] [path]
@ -31,15 +24,19 @@
(shell "rmdir " path " /s") (shell "rmdir " path " /s")
(shell "rm -rf " path))) (shell "rm -rf " path)))
(defn- older-than (defn- needs-build
[f1 f2] [dest src]
"Check if f1 is newer than f2. Used for checking if a file should be updated." "Check if dest is older than src. Used for checking if a file should be updated."
(if is-win true (def f (file/open dest))
(not (zero? (os/shell (string "[ " f1 " -nt " f2 " ]")))))) (if (not f) (break true))
(file/close f)
(let [mod-dest ((os/stat dest) :modified)
mod-src ((os/stat src) :modified)]
(< mod-dest mod-src)))
(defn- older-than-some (defn- needs-build-some
[f others] [f others]
(some (partial older-than f) others)) (some (partial needs-build f) others))
(defn- embed-name (defn- embed-name
"Rename a janet symbol for embedding." "Rename a janet symbol for embedding."
@ -94,10 +91,10 @@
# Defaults # Defaults
(def OPTIMIZE 2) (def OPTIMIZE 2)
(def CC (if is-win "cl" "cc")) (def CC (if is-win "cl" "cc"))
(def LD (if is-win (def LD (if is-win
"link" "link"
(string CC (string CC
" -shared" " -shared"
(if is-mac " -undefined dynamic_lookup" "")))) (if is-mac " -undefined dynamic_lookup" ""))))
(def CFLAGS (string (def CFLAGS (string
(if is-win "/I" "-I") (if is-win "/I" "-I")
@ -111,7 +108,7 @@
(def cc (or (opts :compiler) CC)) (def cc (or (opts :compiler) CC))
(def cflags (or (opts :cflags) CFLAGS)) (def cflags (or (opts :cflags) CFLAGS))
(def defines (interpose " " (make-defines (or (opts :defines) {})))) (def defines (interpose " " (make-defines (or (opts :defines) {}))))
(if (older-than dest src) (if (needs-build dest src)
(if is-win (if is-win
(shell cc " " ;defines " /nologo /c " cflags " /Fo" dest " " src) (shell cc " " ;defines " /nologo /c " cflags " /Fo" dest " " src)
(shell cc " -c " src " " ;defines " " cflags " -o " dest)))) (shell cc " -c " src " " ;defines " " cflags " -o " dest))))
@ -123,7 +120,7 @@
(def cflags (or (opts :cflags) CFLAGS)) (def cflags (or (opts :cflags) CFLAGS))
(def lflags (or (opts :lflags) "")) (def lflags (or (opts :lflags) ""))
(def olist (string/join objects " ")) (def olist (string/join objects " "))
(if (older-than-some target objects) (if (needs-build-some target objects)
(if is-win (if is-win
(shell ld " /DLL /OUT:" target " " olist " %JANET_PATH%\\janet.lib") (shell ld " /DLL /OUT:" target " " olist " %JANET_PATH%\\janet.lib")
(shell ld " " cflags " -o " target " " olist " " lflags)))) (shell ld " " cflags " -o " target " " olist " " lflags))))
@ -131,7 +128,7 @@
(defn- create-buffer-c (defn- create-buffer-c
"Inline raw byte file as a c file." "Inline raw byte file as a c file."
[source dest name] [source dest name]
(when (older-than dest source) (when (needs-build dest source)
(def f (file/open source :r)) (def f (file/open source :r))
(if (not f) (error (string "file " f " not found"))) (if (not f) (error (string "file " f " not found")))
(def out (file/open dest :w)) (def out (file/open dest :w))
@ -153,7 +150,7 @@
dynamically by a janet runtime." dynamically by a janet runtime."
[& opts] [& opts]
(def opt-table (table ;opts)) (def opt-table (table ;opts))
(mkdir "build") (os/mkdir "build")
(def sources (opt-table :source)) (def sources (opt-table :source))
(def name (opt-table :name)) (def name (opt-table :name))
(loop [src :in sources] (loop [src :in sources]