Permalink
Browse files

Fix mysterious fatal bug via :aot; Rename to lein-otf (jit is ambiguo…

…us!)

Somehow, the released version of lein-jit (which I had been using)
completely and utterly failed when I tried to use it again recently. The
loader never made it into the jar as either a .clj or .class! Perhaps the
problem was specifying a :main that wasn't in the target project's own
source tree... but again, it *used to work*. Tried using different versions
of Clojure, checkout-dependencies, deps vs. dev-deps... nothing worked.

I've fixed this by adding the loader to :aot.
  • Loading branch information...
1 parent a52066d commit 36de0ba7ac27c6498168e49fb35144be9223320e @timmc committed Feb 9, 2012
Showing with 27 additions and 18 deletions.
  1. +15 −8 README.md
  2. +2 −2 project.clj
  3. +3 −3 src/{lein_jit → lein_otf}/loader.clj
  4. +7 −5 src/leiningen/{uberjar_jit.clj → uberjar_otf.clj}
View
@@ -1,13 +1,13 @@
-# lein-jit
+# lein-otf
-Leiningen plugin to produce non-AOT uberjars.
+Leiningen plugin to produce OTF-compiled uberjars. (OTF = on-the-fly)
An uberjar's main class must be AOT-compiled for the jar to work as an
executable. Since AOT compilation is infectious (or "transitive"), most or all
of the jar is also AOT'd, along with any linked libraries. This reduces
portability.
-lein-jit works by injecting a sacrificial loader class that is AOT compiled.
+lein-otf works by injecting a sacrificial loader class that is AOT compiled.
This class inspects the jar's manifest file for an attribute (injected when the
jar was created) bearing the name of the :main namespace, and calls
clojure.main/main -m with that namespace. Because the loader is not statically
@@ -17,14 +17,21 @@ against, of course.)
## Usage
- :dev-dependencies [[org.timmc/lein-jit "0.0.1"]]
+ :dev-dependencies [[org.timmc/lein-otf "1.0.0"]]
- $ lein deps, uberjar-jit
+ $ lein deps, uberjar-otf
-Currently, only the standalone jar is any good -- to produce a working
-non-uber jar, use `lein jar` instead. (TODO: fix jar case)
+Compatible with projects using Clojure 1.3.
+(TODO: Replacement for clojure.main -m for 1.2)
-Compatible with Clojure 1.2 and 1.3. (Tested on 1.3.)
+## Changelog
+
+Please ignore [org.timmc/lein-jit "0.0.1"], which mysteriously stopped working
+after release and had a bad name anyhow.
+
+### v1.0.0
+
+* Provides `lein uberjar-otf` command. Works on Clojure v1.3.0.
## License
View
@@ -1,5 +1,5 @@
-(defproject org.timmc/lein-jit "0.0.1"
- :url "https://github.com/timmc/lein-jit"
+(defproject org.timmc/lein-otf "1.0.0"
+ :url "https://github.com/timmc/lein-otf"
:description "Leiningen plugin for non-AOT uberjars"
:dependencies [[org.clojure/clojure "1.3.0"]]
:eval-in-leiningen true)
@@ -1,4 +1,4 @@
-(ns lein-jit.loader
+(ns lein-otf.loader
"Loader to be added to projects as a sacrifice to the AOT gods."
(:require clojure.main)
(:import (java.net URL JarURLConnection)
@@ -11,7 +11,7 @@ is easy to accidentally pick up a MANIFEST.MF out of some other jar on the
class path if you use .getResourceAsStream."
[]
(-> ^Class (class get-manifest) ;; get a class file definitely in *this* jar
- ^URL (.getResource "/lein_jit/loader.class") ;; any resource will do
+ ^URL (.getResource "/lein_otf/loader.class") ;; any resource will do
^JarURLConnection (.openConnection)
(.getManifest)))
@@ -21,7 +21,7 @@ class path if you use .getResourceAsStream."
(let [manifest (get-manifest)]
(-> manifest
^Attributes (.getMainAttributes)
- (.getValue "lein-jit-real-main"))))
+ (.getValue "lein-otf-real-main"))))
(defn -main
"Loader entrance point; just relays the call on to the real -main."
@@ -1,17 +1,19 @@
-(ns leiningen.uberjar-jit
+(ns leiningen.uberjar-otf
(:use [leiningen.uberjar :only (uberjar)]))
(defn juggle
"Put in a loader namespace for :main and put the real main namespace in a
-manifest field. The lein-jit loader should already be present as a dependency."
+manifest field. The lein-otf loader should already be present as a dependency."
[project]
(if-let [real (:main project)]
(-> project
- (assoc-in ,,, [:main] 'lein-jit.loader)
- (assoc-in ,,, [:manifest "lein-jit-real-main"] (str real)))
+ (assoc-in ,,, [:main] 'lein-otf.loader)
+ (update-in ,,, [:aot]
+ (fnil #(conj % 'lein-otf.loader) []))
+ (assoc-in ,,, [:manifest "lein-otf-real-main"] (str real)))
project))
-(defn uberjar-jit
+(defn uberjar-otf
"Plugin entrance point."
[project & args]
(apply uberjar (juggle project) args))

0 comments on commit 36de0ba

Please sign in to comment.