Last active
March 13, 2020 22:10
-
-
Save imrekoszo/b4ee78d69e71c520b0392886a9d511b7 to your computer and use it in GitHub Desktop.
Playing around with compiling clojure namespaces
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
(require '[clojure.set :as set] | |
'[clojure.string :as str] | |
'[clojure.tools.namespace.dir :as dir] | |
'[clojure.tools.namespace.find :as find] | |
'[clojure.tools.namespace.track :as track]) | |
(defn create-tracker [] | |
(->> {:platform find/clj | |
:add-all? true} | |
(dir/scan-dirs {} repl/refresh-dirs))) | |
(defn all-namespaces-in [tracker] | |
(->> tracker | |
(::track/deps) | |
((juxt #(->> % :dependents keys) | |
#(->> % :dependents vals (apply concat)) | |
#(->> % :dependencies keys) | |
#(->> % :dependencies vals (apply concat)))) | |
(into #{} cat))) | |
(defn compilable-namespaces [problematic-ns?] | |
(let [t (create-tracker) | |
all (all-namespaces-in t)] | |
(loop [remaining all | |
problematics (into #{} (filter problematic-ns?) all) | |
dependents (get-in t [::track/deps :dependents])] | |
(let [remaining-candidate (set/difference remaining problematics)] | |
(if (= remaining remaining-candidate) | |
remaining | |
(recur remaining-candidate | |
(->> problematics | |
(select-keys dependents) | |
(vals) | |
(into problematics cat)) | |
(->> problematics | |
(vec) | |
(apply dissoc dependents)))))))) | |
(comment | |
(->> #{'user 'other.problematic-ns} | |
(compilable-namespaces) | |
(run! compile)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are still problems with this approach when attempting a tools.namespace refresh-all.