Fix trampoline task.

This commit is contained in:
Phil Hagelberg 2012-02-07 17:01:23 -08:00
parent 30bdafc9d6
commit 032a023eb5
3 changed files with 37 additions and 28 deletions

View file

@ -126,28 +126,33 @@ corresponding .class files before performing actual compilation."
(.join pump-err)) (.join pump-err))
(.waitFor proc)))) (.waitFor proc))))
(defmulti eval-in ;; work around java's command line handling on windows
"Evaluate the given from in either a subprocess or the leiningen process." ;; http://bit.ly/9c6biv This isn't perfect, but works for what's
(fn [project _] (:eval-in project)) :default :classloader) ;; currently being passed; see http://www.perlmonks.org/?node_id=300286
;; for some of the landmines involved in doing it properly
(defmethod eval-in :subprocess (defn- form-string [form]
[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) (if (= (get-os) :windows)
(pr-str (pr-str form)) (pr-str (pr-str form))
(pr-str form))] (pr-str form)))
(apply sh `(~(or (System/getenv "JAVA_CMD") "java")
(defn shell-command [project form]
`(~(or (System/getenv "JAVA_CMD") "java")
"-cp" ~(string/join java.io.File/pathSeparatorChar "-cp" ~(string/join java.io.File/pathSeparatorChar
(classpath/get-classpath project)) (classpath/get-classpath project))
~@(get-jvm-args project) ~@(get-jvm-args project)
"clojure.main" "-e" ~form-string)))) "clojure.main" "-e" ~(form-string form)))
(defmethod eval-in :classloader (defmulti eval-in
[project form] "Evaluate the given from in either a subprocess or the leiningen process."
(fn [project _] (:eval-in project)))
(defmethod eval-in :subprocess [project form]
(apply sh (shell-command project form)))
(defmethod eval-in :trampoline [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

View file

@ -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."))))

View file

@ -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