Skip to content

Commit

Permalink
Refactor the :notify-command patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
emezeske committed Mar 18, 2012
1 parent 13fab89 commit f787762
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 6 additions & 2 deletions plugin/src/leiningen/cljsbuild.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
requires)
exit-success)

(defn- parse-notify-command [build]
(assoc build :parsed-notify-command
(config/parse-shell-command (:notify-command build))))

(defn- run-compiler [project {:keys [crossover-path crossovers builds]} watch?]
(println "Compiling ClojureScript.")
; If crossover-path does not exist before eval-in-project is called,
; the files it contains won't be classloadable, for some reason.
(when (not-empty crossovers)
(fs/mkdirs crossover-path))
(let [parsed-builds (map #(update-in % [:notify-command] config/parse-shell-command) builds)]
(let [parsed-builds (map parse-notify-command builds)]
(run-local-project project crossover-path parsed-builds
'(require 'cljsbuild.compiler 'cljsbuild.crossover 'cljsbuild.util)
`(do
Expand All @@ -53,7 +57,7 @@
(:source-path opts#)
~crossover-path
(:compiler opts#)
(:notify-command opts#)
(:parsed-notify-command opts#)
~watch?))
'~parsed-builds))))))

Expand Down
31 changes: 14 additions & 17 deletions support/src/cljsbuild/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,29 @@

(def lock (Object.))

(defn- print-safe
[& args]
(defn- apply-safe [f & args]
(locking lock
(apply print args)
(apply f args)
(flush)))

(defn- println-safe
[& args]
(locking lock
(apply println args)
(flush)))
(defn- println-safe [& args]
(apply-safe println args))

(defn- elapsed [started-at]
(let [elapsed-us (- (. System (nanoTime)) started-at)]
(with-precision 2
(str (/ (double elapsed-us) 1000000000) " seconds"))))

(defn- notify-cljs [cmd msg]
(try
(if (:bell cmd)
(print-safe \u0007))
(if (first (:shell cmd))
(util/sh (assoc cmd :shell (map #(if (= % "%") msg %) (:shell cmd)))))
(catch Throwable e
(pst+ e)))
(println-safe msg))
(defn- notify-cljs [command message]
(when (:bell command)
(apply-safe print \u0007))
(when (seq (:shell command))
(try
(util/sh (assoc command :shell (map #(if (= % "%") message %) (:shell command))))
(catch Throwable e
(println-safe "Error running :notify-command:")
(pst+ e))))
(println-safe message))

(defn- compile-cljs [cljs-path compiler-options notify-command]
(let [output-file (:output-to compiler-options)
Expand Down
1 change: 0 additions & 1 deletion support/src/cljsbuild/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,3 @@ and returns a seq of the results. Launches all the threads at once."
(defn sh [command]
(let [process (process-start command)]
((:wait process))))

0 comments on commit f787762

Please sign in to comment.