Get rid of :when for now
This commit is contained in:
parent
6087b94d32
commit
45109685e1
2 changed files with 37 additions and 18 deletions
|
|
@ -54,6 +54,11 @@
|
|||
m [target-name deps]]
|
||||
(into {} (cons m (map #(depends-map tasks %) deps)))))
|
||||
|
||||
#_(defn wrap-when [expr when-expr]
|
||||
(if when-expr
|
||||
(format "(when %s %s)" (second when-expr) expr)
|
||||
expr))
|
||||
|
||||
(defn assemble-task-1
|
||||
"Assembles task, does not process :depends."
|
||||
[task]
|
||||
|
|
@ -68,16 +73,13 @@
|
|||
(assemble-task-1 task))
|
||||
:else task))
|
||||
|
||||
(defn format-task [init when-expr prog]
|
||||
(defn format-task [init prog]
|
||||
(format "
|
||||
(require '[babashka.tasks :refer [shell clojure]])
|
||||
%s
|
||||
%s"
|
||||
(str init)
|
||||
(if when-expr
|
||||
(format "(when %s %s)"
|
||||
when-expr prog)
|
||||
prog)))
|
||||
prog))
|
||||
|
||||
(defn target-order
|
||||
([tasks task-name] (target-order tasks task-name (volatile! #{})))
|
||||
|
|
@ -97,9 +99,9 @@
|
|||
tasks (get @bb-edn :tasks)
|
||||
task (get tasks task-name)]
|
||||
(if task
|
||||
(let [init (get tasks :init)
|
||||
when-expr (get task :when)
|
||||
prog (if (:depends task)
|
||||
(let [m? (map? task)
|
||||
init (and m? (get tasks :init))
|
||||
prog (if (and m? (:depends task))
|
||||
(let [targets (target-order tasks task-name)]
|
||||
(loop [prog ""
|
||||
targets (seq targets)]
|
||||
|
|
@ -109,8 +111,8 @@
|
|||
(next targets))
|
||||
[(binding [*out* *err*]
|
||||
(println "No such task:" task-name)) 1])
|
||||
[[(format-task init when-expr prog)] nil])))
|
||||
[[(format-task init when-expr (assemble-task-1 task))] nil])]
|
||||
[[(format-task init prog)] nil])))
|
||||
[[(format-task init (assemble-task-1 task))] nil])]
|
||||
prog)
|
||||
[(binding [*out* *err*]
|
||||
(println "No such task:" task-name)) 1])))
|
||||
|
|
|
|||
|
|
@ -43,19 +43,36 @@
|
|||
"echo hello")}}
|
||||
(bb "foo")
|
||||
(is (= "hello\n" (slurp out)))))
|
||||
(fs/delete out)
|
||||
(testing "clojure test"
|
||||
(test-utils/with-config {:tasks {'foo (list 'clojure {:out out}
|
||||
"-M -e" "(println :yolo)")}}
|
||||
(bb "foo")
|
||||
(is (= ":yolo\n" (slurp out)))))
|
||||
(test-utils/with-config {:tasks {'quux (list 'spit out "quux\n")
|
||||
'baz (list 'spit out "baz\n" :append true)
|
||||
'bar {:depends ['baz]
|
||||
:task (list 'spit out "bar\n" :append true)}
|
||||
'foo {:depends ['quux 'bar 'baz]
|
||||
:task (list 'spit out "foo\n" :append true)}}}
|
||||
(bb "foo")
|
||||
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out))))))
|
||||
(fs/delete out)
|
||||
(testing "depends"
|
||||
(test-utils/with-config {:tasks {'quux (list 'spit out "quux\n")
|
||||
'baz (list 'spit out "baz\n" :append true)
|
||||
'bar {:depends ['baz]
|
||||
:task (list 'spit out "bar\n" :append true)}
|
||||
'foo {:depends ['quux 'bar 'baz]
|
||||
:task (list 'spit out "foo\n" :append true)}}}
|
||||
(bb "foo")
|
||||
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out)))))
|
||||
(fs/delete out)
|
||||
;; Note: this behavior with :when was complex, since the place where :when
|
||||
;; is inserted isn't very intuitive here
|
||||
;; This is why we don't support :when for now
|
||||
#_(testing "depends with :when"
|
||||
(test-utils/with-config {:tasks {'quux (list 'spit out "quux\n")
|
||||
'baz (list 'spit out "baz\n" :append true)
|
||||
'bar {:when false
|
||||
:depends ['baz]
|
||||
:task (list 'spit out "bar\n" :append true)}
|
||||
'foo {:depends ['quux 'bar]
|
||||
:task (list 'spit out "foo\n" :append true)}}}
|
||||
(bb "foo")
|
||||
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out)))))))
|
||||
|
||||
(deftest list-tasks-test
|
||||
(test-utils/with-config {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue