/
check.clj
37 lines (36 loc) · 1.65 KB
/
check.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns leiningen.check
"Check syntax and warn on reflection."
(:require [leiningen.core.eval :as eval]
[leiningen.core.main :as main]
[bultitude.core :as b]
[clojure.java.io :as io]))
(defn check
"Check syntax and warn on reflection."
([project]
(let [source-files (map io/file (:source-paths project))
nses (sort (b/namespaces-on-classpath :classpath source-files
:ignore-unreadable? false))
action `(let [failures# (atom 0)]
(doseq [ns# '~nses]
;; load will add the .clj, so can't use ns/path-for.
(let [ns-file# (-> (str ns#)
(.replace \- \_)
(.replace \. \/))]
(binding [*out* *err*]
(println "Compiling namespace" ns#))
(try
(binding [*warn-on-reflection* true]
(load ns-file#))
(catch ExceptionInInitializerError e#
(swap! failures# inc)
(.printStackTrace e#)))))
(if-not (zero? @failures#)
(System/exit @failures#)))
project (assoc project
:aot nil
:target-path (str (:target-path project) "/check"))]
(try
(binding [eval/*pump-in* false]
(eval/eval-in-project project action))
(catch clojure.lang.ExceptionInfo e
(main/abort "Failed."))))))