Skip to content

Instantly share code, notes, and snippets.

@micha
Last active January 6, 2017 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micha/f8e15235a2e447259b3384eeb4b37427 to your computer and use it in GitHub Desktop.
Save micha/f8e15235a2e447259b3384eeb4b37427 to your computer and use it in GitHub Desktop.
(require '[clojure.java.io :as io])
(deftask demo []
(let [tmp (tmp-dir!) ; Anonymous, boot-managed temp directory.
prev-fs (atom nil)] ; Atom where the previous fileset is stored.
(with-pre-wrap [fs]
(let [diff (fileset-diff @prev-fs (reset! prev-fs fs)) ; Fileset containing only changed files.
inputs (->> (input-files diff) ; Sequence of [String, java.io.File]
(by-ext [".c"]) ; pairs, the classpath path and File
(map (juxt tmp-path tmp-file)))] ; for files with given extensions.
(doseq [[inpath infile] inputs]
(let [outpath (.replaceAll inpath "\\.c$" ".o") ; The output file classpath path.
outfile (doto (io/file tmp outpath) io/make-parents)] ; The output File (in the temp dir).
(cc infile outfile))) ; The cc fn is assumed to be defined elsewhere.
(-> fs (add-resource tmp) (commit!)))))) ; Add temp dir to fileset, and commit changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment