Skip to content

Instantly share code, notes, and snippets.

@lancepantz
Created September 30, 2010 21:05
Show Gist options
  • Save lancepantz/605325 to your computer and use it in GitHub Desktop.
Save lancepantz/605325 to your computer and use it in GitHub Desktop.
(defmacro defile
"Define a file task. Uses the same syntax as deftask, however the task name
is a string representing the name of the file to be generated by the body.
Source files may be specified in the dependencies set, in which case
the file task will only be ran if the source is newer than the destination.
(defile \"main.o\" #{\"main.c\"}
(sh \"cc\" \"-c\" \"-o\" \"main.o\" \"main.c\"))"
[name & forms]
(let [{:keys [deps body doc]} (parse-task-opts forms)
{:keys [destruct pred actions]} (parse-body body)
{file-deps true task-deps false} (group-by string? deps)]
`(swap! tasks update '~name update-task '~deps '~doc
(fn [~destruct]
(let [f# (file ~name)]
(when (and (or (not (.exists f#))
(seq (filter (partial mtime< f#)
(into ~file-deps
(map #(file ".cake" "run" (name %))
'~task-deps)))))
~pred)
~@actions))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment