/
compile.clj
48 lines (44 loc) · 1.43 KB
/
compile.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
38
39
40
41
42
43
44
45
46
47
48
(ns cambada.compile
(:gen-class)
(:require [cambada.clean :as clean]
[cambada.cli :as cli]
[cambada.utils :as utils]
[clojure.java.io :as io]
[clojure.string :as string]
[clojure.tools.namespace.find :as ns.find]))
(def cli-options
(concat [["-a" "--aot NS_NAMES" "Namespaces to be AOT-compiled or `all` (default)"
:default ['all]
:default-desc "all"
:parse-fn #(as-> % $
(string/split $ #":")
(map symbol $))]]
cli/base-cli-options))
(defn ^:private aot-namespaces
[{:keys [aot deps-map] :as task}]
(if (= (first aot) 'all)
(->> (:paths deps-map)
(map io/file)
(map ns.find/find-namespaces-in-dir)
flatten)
aot))
(defn apply! [{:keys [deps-map out] :as task}]
(clean/apply! task)
(let [target (utils/compiled-classes-path out)
aot-ns (aot-namespaces task)]
(utils/mkdirs target)
(cli/info "Creating" target)
(binding [*compile-path* target]
(doseq [ns aot-ns]
(cli/info " Compiling" ns)
(compile ns)))))
(defn -main [& args]
(let [{:keys [help] :as task} (cli/args->task args cli-options)]
(cli/runner
{:help? help
:task task
:entrypoint-main
"cambada.compile"
:entrypoint-description
"Compiles the specified namespaces into a set of classfiles."
:apply-fn apply!})))