Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix trampoline task.

  • Loading branch information...
commit 032a023eb51781ce5b6428a49196880a065b26ca 1 parent 30bdafc
@technomancy authored
View
48 leiningen-core/src/leiningen/core/eval.clj
@@ -126,28 +126,33 @@ corresponding .class files before performing actual compilation."
(.join pump-err))
(.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
"Evaluate the given from in either a subprocess or the leiningen process."
- (fn [project _] (:eval-in project)) :default :classloader)
-
-(defmethod eval-in :subprocess
- [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
- [project form]
+ (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))
classloader (cl/classlojure classpath)]
(try (cl/eval-in classloader form)
@@ -156,8 +161,7 @@ corresponding .class files before performing actual compilation."
(.printStackTrace e)
1))))
-(defmethod eval-in :leiningen
- [project form]
+(defmethod eval-in :leiningen [project form]
(when (:debug project)
(System/setProperty "clojure.debug" "true"))
;; :dependencies are loaded the same way as plugins in eval-in-leiningen
View
17 src/leiningen/trampoline.clj
@@ -2,7 +2,8 @@
(:refer-clojure :exclude [trampoline])
(:use [leiningen.core.main :only [apply-task task-not-found abort]])
(:require [clojure.string :as string]
- [leiningen.core.eval :as eval]))
+ [leiningen.core.eval :as eval]
+ [clojure.pprint :as pprint]))
(def ^:dynamic *trampoline?* false)
@@ -10,6 +11,9 @@
(.endsWith (System/getProperty "leiningen.trampoline-file") ".bat"))
(defn write-trampoline [command]
+ (when (System/getenv "DEBUG")
+ (println "Trampoline-command:" command)
+ (flush))
(spit (System/getProperty "leiningen.trampoline-file")
(string/join " " (if (win-batch?)
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.
Not compatible with chaining."
[project task-name & args]
- (let [command (atom nil)]
+ (let [command (promise)]
(when (:eval-in-leiningen project)
(println "Warning: trampoline has no effect with :eval-in-leiningen."))
- (binding [*trampoline?* true
- eval/sh (fn [& c] (reset! command c) 0)]
- (apply-task task-name project args task-not-found))
- (if @command
+ (binding [*trampoline?* true]
+ (apply-task task-name (assoc project
+ :eval-in :trampoline
+ :trampoline-promise command) args))
+ (if (realized? command)
(write-trampoline @command)
(abort task-name "did not run any project code for trampolining."))))
View
4 todo.org
@@ -19,8 +19,9 @@ See also https://github.com/technomancy/leiningen/issues
- [X] Allow disabling of all injected code
- [X] Activate :test profile in test task
- [X] Resurrect native deps
+ - [X] Trampoline
- [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?
- [ ] Pass user-level repository auth settings on to pomegranate.
- [ ] In-process eval-in-project? (possibly post-preview)
@@ -35,7 +36,6 @@ See also https://github.com/technomancy/leiningen/issues
- [ ] compile (transitive cleaning)
- [ ] shell wrappers
- [ ] javac (can we do this without ant?)
- - [ ] trampoline
** Documentation
- [X] readme
- [X] plugin guide
Please sign in to comment.
Something went wrong with that request. Please try again.