Differentiate between no compilable namespaces and no stale namespaces.
This commit is contained in:
parent
bf2f63c942
commit
7d57e70e3f
1 changed files with 31 additions and 22 deletions
|
@ -9,22 +9,31 @@
|
||||||
java.lang.management.ManagementFactory
|
java.lang.management.ManagementFactory
|
||||||
(org.apache.tools.ant.types Environment$Variable Path)))
|
(org.apache.tools.ant.types Environment$Variable Path)))
|
||||||
|
|
||||||
(defn namespaces-to-compile
|
(defn compilable-namespaces
|
||||||
"Returns a seq of the namespaces which need compiling."
|
"Retrns a seq of the namespaces that are compilable, regardless of whether
|
||||||
|
their class files are present and up-to-date."
|
||||||
[project]
|
[project]
|
||||||
;; TODO: Compile :main ns if needed
|
;; TODO: Compile :main ns if needed
|
||||||
(for [n (cond (coll? (:namespaces project))
|
(cond
|
||||||
(:namespaces project)
|
(coll? (:namespaces project))
|
||||||
(= :all (:namespaces project))
|
(:namespaces project)
|
||||||
(find-namespaces-in-dir (file (:source-path project))))
|
(= :all (:namespaces project))
|
||||||
:let [ns-file (str (-> (name n)
|
(find-namespaces-in-dir (file (:source-path project)))))
|
||||||
(.replaceAll "\\." "/")
|
|
||||||
(.replaceAll "-" "_")))]
|
(defn stale-namespaces
|
||||||
:when (> (.lastModified (file (:source-path project)
|
"Given a seq of namespaces that are both compilable and that hav missing or
|
||||||
(str ns-file ".clj")))
|
out-of-date class files."
|
||||||
(.lastModified (file (:compile-path project)
|
[project]
|
||||||
(str ns-file "__init.class"))))]
|
(filter
|
||||||
n))
|
(fn [n]
|
||||||
|
(let [ns-file (str (-> (name n)
|
||||||
|
(.replaceAll "\\." "/")
|
||||||
|
(.replaceAll "-" "_")))]
|
||||||
|
(> (.lastModified (file (:source-path project)
|
||||||
|
(str ns-file ".clj")))
|
||||||
|
(.lastModified (file (:compile-path project)
|
||||||
|
(str ns-file "__init.class"))))))
|
||||||
|
(compilable-namespaces project)))
|
||||||
|
|
||||||
(defn find-lib-jars
|
(defn find-lib-jars
|
||||||
"Returns a seq of Files for all the jars in the project's library directory."
|
"Returns a seq of Files for all the jars in the project's library directory."
|
||||||
|
@ -130,18 +139,18 @@
|
||||||
|
|
||||||
(defn compile
|
(defn compile
|
||||||
"Ahead-of-time compile the project. Looks for all namespaces under src/
|
"Ahead-of-time compile the project. Looks for all namespaces under src/
|
||||||
unless a list of :namespaces is provided in project.clj."
|
unless a list of :namespaces is provided in project.clj."
|
||||||
[project]
|
[project]
|
||||||
;; dependencies should be resolved by explicit "lein deps",
|
;; dependencies should be resolved by explicit "lein deps",
|
||||||
;; otherwise it will be done only if :library-path is empty
|
;; otherwise it will be done only if :library-path is empty
|
||||||
(when (empty? (find-lib-jars project))
|
(when (empty? (find-lib-jars project))
|
||||||
(deps project :skip-dev))
|
(deps project :skip-dev))
|
||||||
(.mkdir (file (:compile-path project)))
|
(.mkdir (file (:compile-path project)))
|
||||||
(let [namespaces (namespaces-to-compile project)]
|
(if (compilable-namespaces project)
|
||||||
(if (seq namespaces)
|
(if-let [namespaces (seq (stale-namespaces project))]
|
||||||
(eval-in-project project
|
(eval-in-project project
|
||||||
`(doseq [namespace# '~namespaces]
|
`(doseq [namespace# '~namespaces]
|
||||||
(println "Compiling" namespace#)
|
(println "Compiling" namespace#)
|
||||||
(clojure.core/compile namespace#)))
|
(clojure.core/compile namespace#)))
|
||||||
(println "No :namespaces listed for compilation in project.clj."))))
|
(println "All :namespaces already compiled."))
|
||||||
|
(println "No :namespaces listed for compilation in project.clj.")))
|
||||||
|
|
Loading…
Reference in a new issue