|
3 | 3 | (:require [clojure.java.io :as io]
|
4 | 4 | [clojure.string :as cs]
|
5 | 5 | [clojure.tools.deps.alpha :as deps]
|
6 |
| - [clojure.tools.deps.alpha.reader :as deps.reader]) |
7 |
| - (:import (java.io File BufferedReader))) |
| 6 | + [clojure.tools.deps.alpha.reader :as deps.reader] |
| 7 | + [clojure.tools.namespace.find :refer [find-namespaces-in-dir]]) |
| 8 | + (:import (java.io BufferedReader))) |
8 | 9 |
|
9 | 10 | (defn deps->classpath
|
10 | 11 | "Returns the classpath according to deps.edn, adds *compile-path*."
|
11 | 12 | [deps-map]
|
12 |
| - (let [lib-map (deps/resolve-deps deps-map nil)] |
13 |
| - (deps/make-classpath lib-map (:paths deps-map) {:extra-paths [*compile-path*]}))) |
| 13 | + (deps/make-classpath |
| 14 | + (deps/resolve-deps deps-map nil) |
| 15 | + (:paths deps-map) |
| 16 | + {:extra-paths (conj (:extra-paths deps-map) *compile-path*)})) |
14 | 17 |
|
15 | 18 | (defn merged-deps []
|
16 | 19 | "Merges install, user, local deps.edn maps left-to-right."
|
|
46 | 49 | (apply sh bin cli-args)))
|
47 | 50 |
|
48 | 51 | (defn prep-compile-path []
|
49 |
| - (doseq [file (-> (io/file *compile-path*) (file-seq) (rest) (reverse))] |
50 |
| - (io/delete-file file)) |
51 |
| - (.mkdir (io/file *compile-path*))) |
| 52 | + (let [compile-path (io/file *compile-path*)] |
| 53 | + (doseq [file (-> compile-path (file-seq) (rest) (reverse))] |
| 54 | + (io/delete-file file)) |
| 55 | + (.mkdir compile-path))) |
52 | 56 |
|
53 | 57 | (defn native-image-bin-path []
|
54 | 58 | (-> (io/file (System/getenv "GRAALVM_HOME") "bin/native-image")
|
|
66 | 70 | (binding [*out* *err*] (println "Main namespace required e.g. \"script\" if main file is ./script.clj"))
|
67 | 71 | (System/exit 1))
|
68 | 72 |
|
69 |
| - (println "Loading" main-ns) |
70 |
| - (load (-> main-ns |
71 |
| - (cs/replace "." File/separator) |
72 |
| - (munge-class-name))) |
| 73 | + (let [deps-map (merged-deps) |
| 74 | + namespaces (mapcat (comp find-namespaces-in-dir io/file) (:paths deps-map))] |
| 75 | + (prep-compile-path) |
| 76 | + (doseq [ns namespaces] |
| 77 | + (println "Compiling" ns) |
| 78 | + (compile (symbol ns))) |
73 | 79 |
|
74 |
| - (println "Compiling" main-ns) |
75 |
| - (prep-compile-path) |
76 |
| - (compile (symbol main-ns)) |
77 |
| - |
78 |
| - (let [classpath (deps->classpath (merged-deps)) |
79 |
| - class-name (munge-class-name main-ns)] |
80 |
| - (println (format "Building native image '%s' with classpath '%s'" class-name classpath)) |
81 |
| - (System/exit (exec-native-image nat-img-path nat-img-opts classpath class-name))))) |
| 80 | + (let [classpath (deps->classpath deps-map) |
| 81 | + class-name (munge-class-name main-ns)] |
| 82 | + (println (format "Building native image with classpath '%s'" classpath)) |
| 83 | + (System/exit (exec-native-image nat-img-path nat-img-opts classpath class-name)))))) |
82 | 84 |
|
83 | 85 | (defn -main [main-ns & args]
|
84 | 86 | (try
|
|
0 commit comments