Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 6da801d

Browse files
[l.d.compile] Add regexp support to :aot and :aot-exclude-ns
1 parent da95ce0 commit 6da801d

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

src/leiningen/droid/compile.clj

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
(ns leiningen.droid.compile
22
"This part of the plugin is responsible for the project compilation."
33
(:refer-clojure :exclude [compile])
4-
(:require [leiningen compile javac]
4+
(:require [bultitude.core :as bultitude]
55
[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]]
711
[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))
1819

1920
;; ### Pre-compilation tasks
2021

@@ -58,12 +59,13 @@
5859
constants))
5960

6061
(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}]
6264
(let [res (io/resource "templates/BuildConfig.java")
6365
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 #"\."))
6567
version-name (-> project :version)
66-
application-id (or (-> project :android :rename-manifest-package) package-name)
68+
application-id (or rename-manifest-package package-name)
6769
template-constants (map-constants (merge {"VERSION_NAME" version-name
6870
"APPLICATION_ID" application-id}
6971
build-config))]
@@ -72,8 +74,7 @@
7274
:package-name package-name
7375
:constants template-constants}
7476
(clostache/render (slurp-resource res))
75-
(spit (io/file package-path "BuildConfig.java"))))
76-
project)
77+
(spit (io/file package-path "BuildConfig.java")))))
7778

7879
(defn generate-resource-code
7980
"Generates the R.java file from the resources.
@@ -99,8 +100,7 @@
99100
external-resources
100101
"-I" android-jar
101102
"-J" gen-path
102-
"--generate-dependencies"))
103-
project)
103+
"--generate-dependencies")))
104104

105105
(defn code-gen
106106
"Generates R.java and builds a manifest with the appropriate version
@@ -113,16 +113,31 @@
113113
(defn namespaces-to-compile
114114
"Takes project and returns a set of namespaces that should be AOT-compiled."
115115
[{{: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))))
126141

127142
(defn compile-clojure
128143
"Compiles Clojure files into .class files.

0 commit comments

Comments
 (0)