Created
August 4, 2015 00:55
-
-
Save JacobNinja/85c8b958c121dcc8952a to your computer and use it in GitHub Desktop.
Scan namespace declarations for potential AOT targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Add the resulting vector to `:aot` on your dev profile | |
(def directory ".") | |
(defn- read-file [file] | |
(binding [*read-eval* false] | |
(read-string (slurp file)))) | |
(defn- require-form? [form] | |
(and (seq? form) | |
(= (first form) :require))) | |
(defn- get-ns-require-form [form] | |
(rest (first (filter require-form? form)))) | |
(defn- get-required-ns [form] | |
(if (or (vector? form) (seq? form)) | |
(first form) | |
form)) | |
(defn find-namespaces | |
"Find unique namespaces in project" | |
[form] | |
(when-let [requires (get-ns-require-form form)] | |
(map get-required-ns requires))) | |
(defn -main [] | |
(let [files (eduction (comp (map #(.toString %)) | |
(filter #(.endsWith % ".clj"))) | |
(file-seq (clojure.java.io/file directory)))] | |
(prn (vec (sort (into #{} (mapcat (comp find-namespaces read-file) files))))))) | |
(comment "Example output from compojure" | |
[clojure.java.io clojure.test clojure.tools.macro clout.core compojure.coercions compojure.core compojure.response compojure.route medley.core ring.mock.request ring.util.codec ring.util.mime-type ring.util.response] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment