aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2026-02-20 17:53:36 -0600
committerCalvin Rose <calsrose@gmail.com>2026-02-20 17:53:36 -0600
commit1f53983beab9b30f44dad80b3bffccbb1d6e53f0 (patch)
tree95f1844903b75a7dc1c9e19e3fa2fa1298923919
parentMake sure $? works as expected with :errexit set. (diff)
Check that rules actually work as expected by statting inputs and
outputs before and after execution.
-rw-r--r--spork/build-rules.janet16
-rw-r--r--spork/declare-cc.janet2
-rw-r--r--test/suite-pm-pre-post.janet4
3 files changed, 17 insertions, 5 deletions
diff --git a/spork/build-rules.janet b/spork/build-rules.janet
index 25c9dd7..a45115e 100644
--- a/spork/build-rules.janet
+++ b/spork/build-rules.janet
@@ -39,6 +39,14 @@
(let [m (os/stat path :modified)]
(if (nil? m) false m)))))
+(defn- make-sure-exists
+ "Assert that files exist. Helps debug rules that should create files"
+ [rules msg files]
+ (each f files
+ (def f-target (get rules f {}))
+ (unless (in f-target :task) # phony dep, don't check disk
+ (assert (os/stat f :mode) (string "file or directory " f msg)))))
+
(defn- utd
"Check if a target is up to date."
[target all-targets utd-cache mtime-cache]
@@ -116,9 +124,13 @@
(each o (get rule :outputs [])
(protect (os/rm o)))
(repeat n-workers (ev/give q nil)))
+ # Check that all inputs exists
+ (make-sure-exists rules " is missing as input" (get rule :inputs []))
(if (indexed? r)
(each rr r (rr))
- (r)))
+ (r))
+ # Make sure all outputs were created
+ (make-sure-exists rules " was not created by the rule" (get rule :outputs [])))
(array/push targets-built target)
(eachk next-target dependent-set
(-- (dep-counts next-target))
@@ -161,7 +173,7 @@
(def target (first all-targets))
(def id (dyn *implicit-deps* []))
(each d [;deps ;id ;all-targets]
- (assert (string? d) "inputs and outputs must be strings"))
+ (assert (string? d) (string/format "%v: inputs and outputs must be strings" d)))
(unless (get rules target)
(def new-rule
@{:inputs @[]
diff --git a/spork/declare-cc.janet b/spork/declare-cc.janet
index 7791b76..b15bb57 100644
--- a/spork/declare-cc.janet
+++ b/spork/declare-cc.janet
@@ -330,7 +330,7 @@
(run-tests)
(postcheck))
(defn list-rules [&]
- (each k (sorted (filter string? (keys rules)))
+ (each k (sort (filter string? (keys rules)))
(print k)))
(defn rule-tree [&]
(show-rule-tree rules))
diff --git a/test/suite-pm-pre-post.janet b/test/suite-pm-pre-post.janet
index 09c5955..39302c7 100644
--- a/test/suite-pm-pre-post.janet
+++ b/test/suite-pm-pre-post.janet
@@ -47,10 +47,10 @@
err (string/split "\n" (output :err))]
(when (> (length out) 0)
(each line out
- (printf line)))
+ (print line)))
(when (> (length err) 0)
(each line err
- (printf line)))))
+ (print line)))))
(def bat (if (= (os/which) :windows) ".bat" ""))