|
1 | 1 | (ns leiningen.droid.compile |
2 | 2 | "This part of the plugin is responsible for the project compilation." |
3 | 3 | (:refer-clojure :exclude [compile]) |
4 | | - (:require [leiningen compile javac] |
| 4 | + (:require [bultitude.core :as bultitude] |
5 | 5 | [clojure.java.io :as io] |
6 | | - [clojure.set :as sets] |
| 6 | + [clojure.set :as set] |
| 7 | + [clojure.string :as str] |
| 8 | + [clostache.parser :as clostache] |
| 9 | + [leiningen.compile :refer [stale-namespaces]] |
| 10 | + [leiningen.core.classpath :refer [get-classpath]] |
7 | 11 | [leiningen.core.eval :as eval] |
8 | | - [clojure.string :as st] |
9 | | - [clostache.parser :as clostache]) |
10 | | - (:use [leiningen.droid.utils :only [get-sdk-android-jar sdk-binary |
11 | | - ensure-paths sh dev-build?]] |
12 | | - [leiningen.new.templates :only [slurp-resource sanitize]] |
13 | | - [leiningen.droid.manifest :only [get-package-name generate-manifest]] |
14 | | - [leiningen.core |
15 | | - [main :only [debug info abort]] |
16 | | - [classpath :only [get-classpath]]] |
17 | | - [bultitude.core :only [namespaces-on-classpath]])) |
| 12 | + [leiningen.core.main :refer [debug info abort]] |
| 13 | + [leiningen.droid.manifest :refer [get-package-name generate-manifest]] |
| 14 | + [leiningen.droid.utils :refer [get-sdk-android-jar sdk-binary |
| 15 | + ensure-paths sh dev-build?]] |
| 16 | + leiningen.javac |
| 17 | + [leiningen.new.templates :refer [slurp-resource sanitize]]) |
| 18 | + (:import java.util.regex.Pattern)) |
18 | 19 |
|
19 | 20 | ;; ### Pre-compilation tasks |
20 | 21 |
|
|
58 | 59 | constants)) |
59 | 60 |
|
60 | 61 | (defn generate-build-constants |
61 | | - [{{:keys [manifest-path gen-path build-config]} :android :as project}] |
| 62 | + [{{:keys [manifest-path gen-path build-config rename-manifest-package]} |
| 63 | + :android :as project}] |
62 | 64 | (let [res (io/resource "templates/BuildConfig.java") |
63 | 65 | package-name (get-package-name manifest-path) |
64 | | - package-path (apply io/file gen-path (st/split package-name #"\.")) |
| 66 | + package-path (apply io/file gen-path (str/split package-name #"\.")) |
65 | 67 | version-name (-> project :version) |
66 | | - application-id (or (-> project :android :rename-manifest-package) package-name) |
| 68 | + application-id (or rename-manifest-package package-name) |
67 | 69 | template-constants (map-constants (merge {"VERSION_NAME" version-name |
68 | 70 | "APPLICATION_ID" application-id} |
69 | 71 | build-config))] |
|
72 | 74 | :package-name package-name |
73 | 75 | :constants template-constants} |
74 | 76 | (clostache/render (slurp-resource res)) |
75 | | - (spit (io/file package-path "BuildConfig.java")))) |
76 | | - project) |
| 77 | + (spit (io/file package-path "BuildConfig.java"))))) |
77 | 78 |
|
78 | 79 | (defn generate-resource-code |
79 | 80 | "Generates the R.java file from the resources. |
|
99 | 100 | external-resources |
100 | 101 | "-I" android-jar |
101 | 102 | "-J" gen-path |
102 | | - "--generate-dependencies")) |
103 | | - project) |
| 103 | + "--generate-dependencies"))) |
104 | 104 |
|
105 | 105 | (defn code-gen |
106 | 106 | "Generates R.java and builds a manifest with the appropriate version |
|
113 | 113 | (defn namespaces-to-compile |
114 | 114 | "Takes project and returns a set of namespaces that should be AOT-compiled." |
115 | 115 | [{{:keys [aot aot-exclude-ns]} :android :as project}] |
116 | | - (-> (case aot |
117 | | - :all |
118 | | - (seq (leiningen.compile/stale-namespaces (assoc project :aot :all))) |
119 | | - :all-with-unused |
120 | | - (namespaces-on-classpath :classpath |
121 | | - (map io/file (get-classpath project))) |
122 | | - ;; else |
123 | | - (map symbol aot)) |
124 | | - set |
125 | | - (sets/difference (set (map symbol aot-exclude-ns))))) |
| 116 | + (let [all-nses (bultitude/namespaces-on-classpath |
| 117 | + :classpath (map io/file (get-classpath project))) |
| 118 | + include (case aot |
| 119 | + :all (stale-namespaces (assoc project :aot :all)) |
| 120 | + :all-with-unused all-nses |
| 121 | + aot) |
| 122 | + exclude aot-exclude-ns |
| 123 | + |
| 124 | + {include-nses false, include-regexps true} |
| 125 | + (group-by #(instance? Pattern %) include) |
| 126 | + |
| 127 | + {exclude-nses false, exclude-regexps true} |
| 128 | + (group-by #(instance? Pattern %) exclude)] |
| 129 | + (->> (set/difference (set (map str (if (seq include-regexps) |
| 130 | + all-nses include-nses))) |
| 131 | + (set exclude-nses)) |
| 132 | + (filter (fn [ns] (if (seq include-regexps) |
| 133 | + (some #(re-matches % ns) include-regexps) |
| 134 | + true))) |
| 135 | + (remove (fn [ns] (if (seq exclude-regexps) |
| 136 | + (some #(re-matches % ns) exclude-regexps) |
| 137 | + false))) |
| 138 | + (concat (if (seq include-regexps) |
| 139 | + include-nses ())) |
| 140 | + (map symbol)))) |
126 | 141 |
|
127 | 142 | (defn compile-clojure |
128 | 143 | "Compiles Clojure files into .class files. |
|
0 commit comments