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

Commit

Permalink
Manipulate properties while AOT-compiling the project
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yakushev committed Jun 18, 2012
1 parent 26b8f31 commit 8a6eb98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/leiningen/droid/compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[clojure.java.io :as io]
[leiningen.core.eval :as eval])
(:use [leiningen.droid.utils :only [get-sdk-android-jar unique-jars
ensure-paths sh]]
ensure-paths sh with-properties
dev-build?]]
[leiningen.core
[main :only [debug info abort]]
[classpath :only [get-classpath]]]
Expand Down Expand Up @@ -69,25 +70,29 @@
compiles all namespaces of the dependencies whether they were
referenced in the code or not. The latter is useful for the
REPL-driven development."
[{:keys [aot aot-exclude-ns] :as project}]
[{{:keys [enable-dynamic-compilation start-nrepl-server]} :android,
:keys [aot aot-exclude-ns] :as project}]
(debug (get-classpath project))
(if (= aot :all-with-unused)
(let [nses (namespaces-on-classpath :classpath
(map io/file (get-classpath project)))
nses (remove (set (map symbol aot-exclude-ns)) nses)]
(try
(let [form `(doseq [namespace# '~nses]
(println "Compiling" namespace#)
(clojure.core/compile namespace#))
project (update-in project [:prep-tasks]
(partial remove #{"compile"}))]
(.mkdirs (io/file (:compile-path project)))
(try (eval/eval-in-project project form)
(info "Compilation succeeded.")
(catch Exception e
(abort "Compilation failed.")))))
(info "All namespaces already :aot compiled."))
(leiningen.compile/compile project)))
(with-properties ["android_dynamic_compilation" enable-dynamic-compilation
"android_start_nrepl_server" start-nrepl-server
"android_release_build" (not (dev-build? project))]
(if (= aot :all-with-unused)
(let [nses (namespaces-on-classpath :classpath
(map io/file (get-classpath project)))
nses (remove (set (map symbol aot-exclude-ns)) nses)]
(try
(let [form `(doseq [namespace# '~nses]
(println "Compiling" namespace#)
(clojure.core/compile namespace#))
project (update-in project [:prep-tasks]
(partial remove #{"compile"}))]
(.mkdirs (io/file (:compile-path project)))
(try (eval/eval-in-project project form)
(info "Compilation succeeded.")
(catch Exception e
(abort "Compilation failed.")))))
(info "All namespaces already :aot compiled."))
(leiningen.compile/compile project))))

(defn compile
"Compiles both Java and Clojure source files."
Expand Down
16 changes: 16 additions & 0 deletions src/leiningen/droid/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,19 @@ This function should be rewritten in future."
"-keypass" "android"
"-storepass" "android"
"-dname" "CN=Android Debug,O=Android,C=US"))

(defmacro with-properties
"Sets the given properties to the respective values to run the code
provided in `body`. At the end restore the initial property values."
[bindings & body]
(let [bindings (partition 2 bindings)
initial (gensym)]
`(let [~initial (hash-map ~@(mapcat (fn [[prop _]]
[prop `(System/getProperty ~prop)])
bindings))]
~@(for [[prop newval] bindings]
`(System/setProperty ~prop (str ~newval)))
(let [result# (do ~@body)]
~@(for [[prop newval] bindings]
`(System/setProperty ~prop (get ~initial ~prop)))
result#))))

0 comments on commit 8a6eb98

Please sign in to comment.