Fix trampoline task.
This commit is contained in:
parent
30bdafc9d6
commit
032a023eb5
3 changed files with 37 additions and 28 deletions
|
@ -126,28 +126,33 @@ corresponding .class files before performing actual compilation."
|
||||||
(.join pump-err))
|
(.join pump-err))
|
||||||
(.waitFor proc))))
|
(.waitFor proc))))
|
||||||
|
|
||||||
|
;; work around java's command line handling on windows
|
||||||
|
;; http://bit.ly/9c6biv This isn't perfect, but works for what's
|
||||||
|
;; currently being passed; see http://www.perlmonks.org/?node_id=300286
|
||||||
|
;; for some of the landmines involved in doing it properly
|
||||||
|
(defn- form-string [form]
|
||||||
|
(if (= (get-os) :windows)
|
||||||
|
(pr-str (pr-str form))
|
||||||
|
(pr-str form)))
|
||||||
|
|
||||||
|
(defn shell-command [project form]
|
||||||
|
`(~(or (System/getenv "JAVA_CMD") "java")
|
||||||
|
"-cp" ~(string/join java.io.File/pathSeparatorChar
|
||||||
|
(classpath/get-classpath project))
|
||||||
|
~@(get-jvm-args project)
|
||||||
|
"clojure.main" "-e" ~(form-string form)))
|
||||||
|
|
||||||
(defmulti eval-in
|
(defmulti eval-in
|
||||||
"Evaluate the given from in either a subprocess or the leiningen process."
|
"Evaluate the given from in either a subprocess or the leiningen process."
|
||||||
(fn [project _] (:eval-in project)) :default :classloader)
|
(fn [project _] (:eval-in project)))
|
||||||
|
|
||||||
(defmethod eval-in :subprocess
|
(defmethod eval-in :subprocess [project form]
|
||||||
[project form]
|
(apply sh (shell-command project form)))
|
||||||
;; work around java's command line handling on windows
|
|
||||||
;; http://bit.ly/9c6biv This isn't perfect, but works for what's
|
|
||||||
;; currently being passed; see http://www.perlmonks.org/?node_id=300286
|
|
||||||
;; for some of the landmines involved in doing it properly
|
|
||||||
(let [form-string
|
|
||||||
(if (= (get-os) :windows)
|
|
||||||
(pr-str (pr-str form))
|
|
||||||
(pr-str form))]
|
|
||||||
(apply sh `(~(or (System/getenv "JAVA_CMD") "java")
|
|
||||||
"-cp" ~(string/join java.io.File/pathSeparatorChar
|
|
||||||
(classpath/get-classpath project))
|
|
||||||
~@(get-jvm-args project)
|
|
||||||
"clojure.main" "-e" ~form-string))))
|
|
||||||
|
|
||||||
(defmethod eval-in :classloader
|
(defmethod eval-in :trampoline [project form]
|
||||||
[project form]
|
(deliver (:trampoline-promise project) (shell-command project form)))
|
||||||
|
|
||||||
|
(defmethod eval-in :classloader [project form]
|
||||||
(let [classpath (map io/file (classpath/get-classpath project))
|
(let [classpath (map io/file (classpath/get-classpath project))
|
||||||
classloader (cl/classlojure classpath)]
|
classloader (cl/classlojure classpath)]
|
||||||
(try (cl/eval-in classloader form)
|
(try (cl/eval-in classloader form)
|
||||||
|
@ -156,8 +161,7 @@ corresponding .class files before performing actual compilation."
|
||||||
(.printStackTrace e)
|
(.printStackTrace e)
|
||||||
1))))
|
1))))
|
||||||
|
|
||||||
(defmethod eval-in :leiningen
|
(defmethod eval-in :leiningen [project form]
|
||||||
[project form]
|
|
||||||
(when (:debug project)
|
(when (:debug project)
|
||||||
(System/setProperty "clojure.debug" "true"))
|
(System/setProperty "clojure.debug" "true"))
|
||||||
;; :dependencies are loaded the same way as plugins in eval-in-leiningen
|
;; :dependencies are loaded the same way as plugins in eval-in-leiningen
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
(:refer-clojure :exclude [trampoline])
|
(:refer-clojure :exclude [trampoline])
|
||||||
(:use [leiningen.core.main :only [apply-task task-not-found abort]])
|
(:use [leiningen.core.main :only [apply-task task-not-found abort]])
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[leiningen.core.eval :as eval]))
|
[leiningen.core.eval :as eval]
|
||||||
|
[clojure.pprint :as pprint]))
|
||||||
|
|
||||||
(def ^:dynamic *trampoline?* false)
|
(def ^:dynamic *trampoline?* false)
|
||||||
|
|
||||||
|
@ -10,6 +11,9 @@
|
||||||
(.endsWith (System/getProperty "leiningen.trampoline-file") ".bat"))
|
(.endsWith (System/getProperty "leiningen.trampoline-file") ".bat"))
|
||||||
|
|
||||||
(defn write-trampoline [command]
|
(defn write-trampoline [command]
|
||||||
|
(when (System/getenv "DEBUG")
|
||||||
|
(println "Trampoline-command:" command)
|
||||||
|
(flush))
|
||||||
(spit (System/getProperty "leiningen.trampoline-file")
|
(spit (System/getProperty "leiningen.trampoline-file")
|
||||||
(string/join " " (if (win-batch?)
|
(string/join " " (if (win-batch?)
|
||||||
command
|
command
|
||||||
|
@ -26,12 +30,13 @@ than as a subprocess of Leiningen's project.
|
||||||
Use this to save memory or to work around things like stdin issues.
|
Use this to save memory or to work around things like stdin issues.
|
||||||
Not compatible with chaining."
|
Not compatible with chaining."
|
||||||
[project task-name & args]
|
[project task-name & args]
|
||||||
(let [command (atom nil)]
|
(let [command (promise)]
|
||||||
(when (:eval-in-leiningen project)
|
(when (:eval-in-leiningen project)
|
||||||
(println "Warning: trampoline has no effect with :eval-in-leiningen."))
|
(println "Warning: trampoline has no effect with :eval-in-leiningen."))
|
||||||
(binding [*trampoline?* true
|
(binding [*trampoline?* true]
|
||||||
eval/sh (fn [& c] (reset! command c) 0)]
|
(apply-task task-name (assoc project
|
||||||
(apply-task task-name project args task-not-found))
|
:eval-in :trampoline
|
||||||
(if @command
|
:trampoline-promise command) args))
|
||||||
|
(if (realized? command)
|
||||||
(write-trampoline @command)
|
(write-trampoline @command)
|
||||||
(abort task-name "did not run any project code for trampolining."))))
|
(abort task-name "did not run any project code for trampolining."))))
|
||||||
|
|
4
todo.org
4
todo.org
|
@ -19,8 +19,9 @@ See also https://github.com/technomancy/leiningen/issues
|
||||||
- [X] Allow disabling of all injected code
|
- [X] Allow disabling of all injected code
|
||||||
- [X] Activate :test profile in test task
|
- [X] Activate :test profile in test task
|
||||||
- [X] Resurrect native deps
|
- [X] Resurrect native deps
|
||||||
|
- [X] Trampoline
|
||||||
- [X] Allow hooks to provide activate fn to avoid load-time side-effects
|
- [X] Allow hooks to provide activate fn to avoid load-time side-effects
|
||||||
- [ ] Hook up reply to nrepl for new repl task?
|
- [X] Hook up reply to nrepl for new repl task
|
||||||
- [ ] Honor hooks declared in plugin jar metadata?
|
- [ ] Honor hooks declared in plugin jar metadata?
|
||||||
- [ ] Pass user-level repository auth settings on to pomegranate.
|
- [ ] Pass user-level repository auth settings on to pomegranate.
|
||||||
- [ ] In-process eval-in-project? (possibly post-preview)
|
- [ ] In-process eval-in-project? (possibly post-preview)
|
||||||
|
@ -35,7 +36,6 @@ See also https://github.com/technomancy/leiningen/issues
|
||||||
- [ ] compile (transitive cleaning)
|
- [ ] compile (transitive cleaning)
|
||||||
- [ ] shell wrappers
|
- [ ] shell wrappers
|
||||||
- [ ] javac (can we do this without ant?)
|
- [ ] javac (can we do this without ant?)
|
||||||
- [ ] trampoline
|
|
||||||
** Documentation
|
** Documentation
|
||||||
- [X] readme
|
- [X] readme
|
||||||
- [X] plugin guide
|
- [X] plugin guide
|
||||||
|
|
Loading…
Reference in a new issue