Permalink
Browse files

Start ripping out Lein 1 compat. Issue #175.

  • Loading branch information...
1 parent 341b689 commit f69f3890c1500aa1ef82b590394f42159f5b63e8 @emezeske committed Jan 20, 2013
View
@@ -4,6 +4,9 @@ lib
classes/
lein-cljsbuild-*.*.*
cljsbuild-*.*.*
+target
+plugin/target
+support/target
example-projects/*/*.jar
example-projects/simple/resources
example-projects/advanced/resources/public/js
View
@@ -14,7 +14,7 @@ pushd $project_root
rm -rf ~/.m2/repository/lein-cljsbuild ~/.m2/repository/cljsbuild/
for d in support plugin; do
pushd $d
- lein install, midje
+ lein do install, test
popd
done
for d in $projects; do
@@ -23,10 +23,6 @@ for d in $projects; do
extra_command=', cljsbuild test'
fi
lein clean
- rm -rf .lein-*
- lein cljsbuild clean, cljsbuild once$extra_command
- lein clean
- rm -rf .lein-*
- lein2 do cljsbuild clean, cljsbuild once$extra_command
+ lein do cljsbuild clean, cljsbuild once$extra_command
popd
done
@@ -4,7 +4,7 @@
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.0.4"]
[hiccup "1.0.0"]]
- :plugins [[lein-cljsbuild "0.2.9"]
+ :plugins [[lein-cljsbuild "0.3.0"]
[lein-ring "0.7.0"]]
; Enable the lein hooks for: clean, compile, test, and jar.
:hooks [leiningen.cljsbuild]
@@ -71,7 +71,4 @@
:compiler {:output-to "resources/private/js/unit-test.js"
:optimizations :whitespace
:pretty-print true}}}}
- :ring {:handler example.routes/app}
- ; for Leiningen 1.x:
- :source-path "src-clj"
- :dev-dependencies [[lein-ring "0.7.0"]])
+ :ring {:handler example.routes/app})
@@ -4,14 +4,11 @@
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.0.4"]
[hiccup "1.0.0"]]
- :plugins [[lein-cljsbuild "0.2.9"]
+ :plugins [[lein-cljsbuild "0.3.0"]
[lein-ring "0.7.0"]]
:cljsbuild {
:builds [{:source-path "src-cljs"
:compiler {:output-to "resources/public/js/main.js"
:optimizations :whitespace
:pretty-print true}}]}
- :ring {:handler example.routes/app}
- ; for Leiningen 1.x:
- :source-path "src-clj"
- :dev-dependencies [[lein-ring "0.7.0"]])
+ :ring {:handler example.routes/app})
View
@@ -1,12 +1,15 @@
(defproject lein-cljsbuild "0.3.0"
:description "ClojureScript Autobuilder Plugin"
:url "http://github.com/emezeske/lein-cljsbuild"
- :license {:name "Eclipse Public License - v 1.0"
- :url "http://www.eclipse.org/legal/epl-v10.html"
- :distribution :repo}
+ :license
+ {:name "Eclipse Public License - v 1.0"
+ :url "http://www.eclipse.org/legal/epl-v10.html"
+ :distribution :repo}
:dependencies [[fs "1.1.2"]]
- :dev-dependencies [[midje "1.4.0"]
- ; NOTE: lein-midje requires different versions to be
- ; installed for lein1 vs lein2 compatibility :(.
- [lein-midje "1.0.10"]]
+ :profiles {
+ :dev {
+ :dependencies [
+ [midje "1.4.0"]
+ [cljsbuild "0.3.0"]]
+ :plugins [[lein-midje "2.0.4"]]}}
:eval-in-leiningen true)
@@ -8,48 +8,20 @@
[leiningen.cljsbuild.jar :as jar]
[leiningen.cljsbuild.subproject :as subproject]
[leiningen.compile :as lcompile]
+ [leiningen.core.eval :as leval]
+ [leiningen.core.main :as lmain]
[leiningen.help :as lhelp]
[leiningen.jar :as ljar]
[leiningen.test :as ltest]
[leiningen.trampoline :as ltrampoline]
[robert.hooke :as hooke]))
-; TODO: lein2: All temporary output files, etc, should go into (:target-path project),
-; in which case they will automatically be removed upon "lein clean".
-
-(def repl-output-path ".lein-cljsbuild-repl")
-
-(def exit-code-success 0)
-(def exit-code-failure 1)
-
-; TODO: lein1 does not have a leiningen.core.main ns. This can go away once lein2
-; is released, if that ever happens.
-(def ^:private lein2?
- (try
- (require 'leiningen.core.main)
- true
- (catch java.io.FileNotFoundException _
- false)))
-
-(defn- exit-success
- "Exit successfully in a way that satisifies lein1 and lein2."
- []
- (if lein2?
- nil
- exit-code-success))
-
-(defn- exit-failure
- "Fail in a way that satisifies lein1 and lein2."
- []
- (if lein2?
- ((resolve 'leiningen.core.main/abort))
- exit-code-failure))
+(def ^:private repl-output-path "repl")
(defn- run-local-project [project crossover-path builds requires form]
- (subproject/eval-in-project project crossover-path builds
+ (leval/eval-in-project (subproject/make-subproject project crossover-path builds)
form
- requires)
- (exit-success))
+ requires))
(defn- run-compiler [project {:keys [crossover-path crossovers builds]} build-ids watch?]
(doseq [build-id build-ids]
@@ -117,7 +89,7 @@
(do ~@forms)
(do
(println "REPL subcommands must be run via \"lein trampoline cljsbuild <command>\".")
- (exit-failure))))
+ (lmain/abort))))
(defn- once
"Compile the ClojureScript project once."
@@ -133,7 +105,7 @@
"Remove automatically generated files."
[project {:keys [crossover-path builds repl-launch-commands test-commands]}]
(println "Deleting files generated by lein-cljsbuild.")
- (fs/delete-dir repl-output-path)
+ (fs/delete-dir (config/in-target-path (:target-path project) repl-output-path))
(fs/delete-dir crossover-path)
(let [raw-commands (concat
(keep identity (map :notify-command builds))
@@ -153,10 +125,8 @@
(defn- test
"Run ClojureScript tests."
[project options args]
- (let [compile-result (run-compiler project options nil false)]
- (if (and (not lein2?) (not= compile-result exit-code-success))
- compile-result
- (run-tests project options args))))
+ (run-compiler project options nil false)
+ (run-tests project options args))
(defn- repl-listen
"Run a REPL that will listen for incoming connections."
@@ -207,7 +177,7 @@
([project]
(println
(lhelp/help-for "cljsbuild"))
- (exit-failure))
+ (lmain/abort))
([project subtask & args]
(let [options (config/extract-options project)]
(case subtask
@@ -222,59 +192,36 @@
(println
"Subtask" (str \" subtask \") "not found."
(lhelp/subtask-help-for *ns* #'cljsbuild))
- (exit-failure))))))
+ (lmain/abort))))))
-; Lein2 "preps" the project when eval-in-project is called. This
+; Lein "preps" the project when eval-in-project is called. This
; causes it to be compiled, which normally would trigger the compile
; hook below, which is bad because we can't compile unless we're in
; the dummy subproject. To solve this problem, we disable all of the
-; hooks if we notice that lein2 is currently prepping.
+; hooks if we notice that lein is currently prepping.
(defmacro skip-if-prepping [task args & forms]
- `(if (subproject/prepping?)
+ `(if false ; FIXME FIXME leval/*prepping?*
(apply ~task ~args)
(do ~@forms)))
-; Supporting both lein1 and lein2 is starting to become VERY PAINFUL.
-(if lein2?
- (do
- (defn compile-hook [task & args]
- (skip-if-prepping task args
- (apply task args)
- (run-compiler (first args) (config/extract-options (first args)) nil false)))
-
- (defn test-hook [task & args]
- (skip-if-prepping task args
- (apply task args)
- (run-tests (first args) (config/extract-options (first args)) [])))
-
- (defn clean-hook [task & args]
- (skip-if-prepping task args
- (apply task args)
- (clean (first args) (config/extract-options (first args)))))
+(defn compile-hook [task & args]
+ (skip-if-prepping task args
+ (apply task args)
+ (run-compiler (first args) (config/extract-options (first args)) nil false)))
- (defn jar-hook [task & [project out-file filespecs]]
- (skip-if-prepping task [project out-file filespecs]
- (apply task [project out-file (concat filespecs (jar/get-filespecs project))]))))
- (do
- (defn compile-hook [task & args]
- (let [compile-result (apply task args)]
- (if (not= compile-result exit-code-success)
- compile-result
- (run-compiler (first args) (config/extract-options (first args)) nil false))))
+(defn test-hook [task & args]
+ (skip-if-prepping task args
+ (apply task args)
+ (run-tests (first args) (config/extract-options (first args)) [])))
- (defn test-hook [task & args]
- (let [test-results [(apply task args)
- (run-tests (first args) (config/extract-options (first args)) [])]]
- (if (every? #(= % exit-code-success) test-results)
- (exit-success)
- (exit-failure))))
+(defn clean-hook [task & args]
+ (skip-if-prepping task args
+ (apply task args)
+ (clean (first args) (config/extract-options (first args)))))
- (defn clean-hook [task & args]
- (apply task args)
- (clean (first args) (config/extract-options (first args))))
-
- (defn jar-hook [task & [project out-file filespecs]]
- (apply task [project out-file (concat filespecs (jar/get-filespecs project))]))))
+(defn jar-hook [task & [project out-file filespecs]]
+ (skip-if-prepping task [project out-file filespecs]
+ (apply task [project out-file (concat filespecs (jar/get-filespecs project))])))
(defn activate
"Set up hooks for the plugin. Eventually, this can be changed to just hook,
@@ -284,7 +231,3 @@
(hooke/add-hook #'ltest/test #'test-hook)
(hooke/add-hook #'lclean/clean #'clean-hook)
(hooke/add-hook #'ljar/write-jar #'jar-hook))
-
-; Lein1 hooks have to be called manually, in lein2 the activate function will
-; be automatically called.
-(when-not lein2? (activate))
@@ -3,34 +3,39 @@
(:require
[clojure.pprint :as pprint]))
-(def compiler-output-dir-base ".lein-cljsbuild-compiler-")
+(defn in-target-path [target-path subpath]
+ (str target-path "/cljsbuild-" subpath))
+
+(defn- compiler-output-dir-base [target-path]
+ (in-target-path target-path "compiler-"))
+
(def compiler-global-dirs
{:libs "closure-js/libs"
:externs "closure-js/externs"})
-(def default-global-options
+(defn- default-global-options [target-path]
{:repl-launch-commands {}
:repl-listen-port 9000
:test-commands {}
- :crossover-path ".crossover-cljs"
+ :crossover-path (in-target-path target-path "crossover")
:crossover-jar false
:crossovers []})
-(def default-compiler-options
- {:output-to "main.js"
+(defn- default-compiler-options [target-path]
+ {:output-to (in-target-path target-path "main.js")
:optimizations :whitespace
:warnings true
:externs []
:libs []
:pretty-print true})
-(def default-build-options
+(defn- default-build-options [target-path]
{:source-path "src-cljs"
:jar false
:notify-command nil
:incremental true
:assert true
- :compiler default-compiler-options})
+ :compiler (default-compiler-options target-path)})
(defn convert-builds-map [options]
(update-in options [:builds]
@@ -95,27 +100,27 @@
(deep-merge a b)
b))
-(defn- set-default-build-options [options]
- (deep-merge default-build-options options))
+(defn- set-default-build-options [target-path options]
+ (deep-merge (default-build-options target-path) options))
-(defn- set-default-output-dirs [options]
+(defn- set-default-output-dirs [target-path options]
(let [output-dir-key [:compiler :output-dir]
builds
(for [[build counter] (map vector (:builds options) (range))]
(if (get-in build output-dir-key)
build
(assoc-in build output-dir-key
- (str compiler-output-dir-base counter))))]
+ (str (compiler-output-dir-base target-path) counter))))]
(if (or (empty? builds)
(apply distinct? (map #(get-in % output-dir-key) builds)))
(assoc options :builds builds)
(throw (Exception. (str "All " output-dir-key " options must be distinct."))))))
-(defn set-default-options [options]
- (set-default-output-dirs
- (deep-merge default-global-options
+(defn set-default-options [target-path options]
+ (set-default-output-dirs target-path
+ (deep-merge (default-global-options target-path)
(assoc options :builds
- (map set-default-build-options (:builds options))))))
+ (map #(set-default-build-options target-path %) (:builds options))))))
(defn set-build-global-dirs [build]
(reduce (fn [build [k v]] (update-in build [:compiler k] conj v))
@@ -128,13 +133,13 @@
(defn- normalize-options
"Sets default options and accounts for backwards compatibility."
- [options]
+ [target-path options]
(let [options (convert-builds-map options)
compat (backwards-compat options)]
(when (not= options compat)
(warn-deprecated compat))
- (-> compat
- set-default-options
+ (->> compat
+ (set-default-options target-path)
set-compiler-global-dirs)))
(defn parse-shell-command [raw]
@@ -163,4 +168,4 @@
(when (nil? (:cljsbuild project))
(println "WARNING: no :cljsbuild entry found in project definition."))
(let [raw-options (:cljsbuild project)]
- (normalize-options raw-options)))
+ (normalize-options (:target-path project) raw-options)))
Oops, something went wrong.

0 comments on commit f69f389

Please sign in to comment.