Permalink
Browse files

Move normalization out of defproject into top-level comp.

  • Loading branch information...
technomancy committed Mar 1, 2012
1 parent 85f2fa1 commit 71874208f3e691fc1dbff398cc253cbb9df48dd8
@@ -34,41 +34,39 @@
:jar-exclusions [#"^\."]
:uberjar-exclusions [#"^META-INF/DUMMY.SF"]})
-(defn ^:internal add-repositories
- "Public only for macroexpansion purposes, :repositories needs special
- casing logic for merging default values with user-provided ones."
- [{:keys [omit-default-repositories repositories] :as project}]
- (assoc project :repositories
- (into (if-not omit-default-repositories
- (:repositories defaults)
- (ordered/ordered-map))
- (for [[id repo] repositories]
- [id (if (string? repo) {:url repo} repo)]))))
-
(defmacro defproject
"The project.clj file must either def a project map or call this macro."
[project-name version & {:as args}]
`(let [args# ~(unquote-project args)]
(def ~'project
- (merge defaults (dissoc (add-repositories args#)
- ;; Strip out aliases for normalization.
- :eval-in-leiningen :deps)
+ (merge defaults args#
{:name ~(name project-name)
:group ~(or (namespace project-name)
(name project-name))
:version ~version
- :dependencies (ordered/ordered-map
- (or (:dependencies args#) (:deps args#)))
- :compile-path (or (:compile-path args#)
- (.getPath (io/file (:target-path args#)
- "classes")))
- :plugins (ordered/ordered-map (:plugins args#))
:root ~(.getParent (io/file *file*))
:eval-in (or (:eval-in args#)
(if (:eval-in-leiningen args#)
:leiningen
:subprocess))}))))
+(defn normalize-repos [{:keys [omit-default-repositories
+ repositories] :as project}]
+ (assoc project :repositories
+ (into (if-not omit-default-repositories
+ (:repositories defaults)
+ (ordered/ordered-map))
+ (for [[id repo] repositories]
+ [id (if (map? repo) repo {:url repo})]))))
+
+(defn normalize-deps [project]
+ ;; TODO: mapize
+ (update-in project [:dependencies] ordered/ordered-map))
+
+(defn normalize-plugins [project]
+ ;; TODO: mapize
+ (update-in project [:plugins] ordered/ordered-map))
+
(defn- absolutize [root path]
(str (if (.startsWith path "/")
path
@@ -84,7 +82,17 @@
:else project))
(defn absolutize-paths [project]
- (reduce absolutize-path project (keys project)))
+ (let [project (reduce absolutize-path project (keys project))]
+ (assoc project :compile-path (or (:compile-path project)
+ (str (io/file (:target-path project)
+ "classes"))))))
+
+(defn remove-aliases [project]
+ (dissoc project :deps :eval-in-leiningen))
+
+(def ^{:arglists '([project])} normalize
+ "Normalize project map to standard representation."
+ (comp normalize-repos normalize-deps absolutize-paths remove-aliases))
(def default-profiles
"Profiles get merged into the project map. The :dev and :user
@@ -147,8 +155,8 @@
[project profiles-to-apply]
(let [merged (reduce merge-profile project
(profiles-for project profiles-to-apply))]
- (with-meta (absolutize-paths merged)
- {:without-profiles (absolutize-paths project)})))
+ (with-meta (normalize merged)
+ {:without-profiles (normalize project)})))
(defn ensure-dynamic-classloader []
(let [thread (Thread/currentThread)
@@ -54,7 +54,7 @@
(.mkdirs d1)
(spit (io/file d1 "project.clj")
(pr-str '(defproject hello "1.0")))
- (is (= (for [path ["src" "resources" "classes"]]
+ (is (= (for [path ["src" "resources" "target/classes"]]
(format "/tmp/lein-sample-project/checkouts/d1/%s" path))
(#'leiningen.core.classpath/checkout-deps-paths project)))
(finally
@@ -71,4 +71,7 @@
["internal" {:password "reindur" :username "milgrim"
:url "https://sekrit.info/repo"}]]
(add-auth [["sonatype" {:url "https://oss.sonatype.org/"}]
- ["internal" {:url "https://sekrit.info/repo"}]])))))
+ ["internal" {:url "https://sekrit.info/repo"}]])))))
+
+(deftest test-exclusions
+ )
@@ -13,7 +13,7 @@
(def paths {:source-paths ["src"],
:test-paths ["test"],
:resource-paths ["dev-resources" "resources"],
- :compile-path "classes",
+ :compile-path "target/classes",
:native-path "native",
:target-path "target"})
@@ -11,20 +11,20 @@
(use-fixtures :each (fn [f]
(delete-file-recursively
- (file "test_projects" "sample" "classes") true)
+ (file "test_projects" "sample" "target") true)
(delete-file-recursively
- (file "test_projects" "sample_failing" "classes") true)
+ (file "test_projects" "sample_failing" "target") true)
(f)))
(deftest test-compile
(is (zero? (compile sample-project)))
- (is (.exists (file "test_projects" "sample"
+ (is (.exists (file "test_projects" "sample" "target"
"classes" "nom" "nom" "nom.class")))
(is (pos? (compile sample-failing-project))))
(deftest test-compile-all
(is (zero? (compile sample-project ":all")))
- (is (.exists (file "test_projects" "sample"
+ (is (.exists (file "test_projects" "sample" "target"
"classes" "nom" "nom" "nom.class"))))
(def eip-check (atom false))
@@ -43,27 +43,27 @@
:clean-non-project-classes true))))
(is (zero? (eval/eval-in-project sample-project '(require 'nom.nom.nom)))
"can't load after compiling")
- (let [classes (seq (.list (file "test_projects" "sample"
+ (let [classes (seq (.list (file "test_projects" "sample" "target"
"classes" "nom" "nom")))]
(doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto____\d+.class"
#"nom\$_main__\d+.class" #"nom.class" #"nom__init.class"]]
(is (some (partial re-find r) classes) (format "missing %s" r))))
- (is (not (.exists (file "test_projects" "sample"
+ (is (not (.exists (file "test_projects" "sample" "target"
"classes" "sample2" "core.class"))))
- (is (not (.exists (file "test_projects" "sample"
+ (is (not (.exists (file "test_projects" "sample" "target"
"classes" "sample2" "alt.class")))))
(deftest ^:busted test-cleared-transitive-aot-by-regexes
(is (zero? (compile (assoc sample-project
:clean-non-project-classes [#"core"]))))
- (let [classes (seq (.list (file "test_projects" "sample"
+ (let [classes (seq (.list (file "test_projects" "sample" "target"
"classes" "nom" "nom")))]
(doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto____\d+.class"
#"nom\$_main__\d+.class" #"nom.class" #"nom__init.class"]]
(is (some (partial re-find r) classes) (format "missing %s" r))))
- (is (not (.exists (file "test_projects" "sample"
+ (is (not (.exists (file "test_projects" "sample" "target"
"classes" "sample2" "core.class"))))
- (is (.exists (file "test_projects" "sample" "classes"
+ (is (.exists (file "test_projects" "sample" "target" "classes"
"sample2" "alt__init.class"))))
(deftest test-skip-aot-on-main
View
@@ -27,8 +27,12 @@ See also https://github.com/technomancy/leiningen/issues
- [X] Get off snapshots (data.xml, reply)
- [X] Pass user-level repository auth settings on to pomegranate
- [X] Use ordered map for :dependencies and :repositories?
+ - [X] Project middleware
- [ ] Look for :java-cmd in project map
- [ ] Better error messages for misformatted :dependencies/:repositories
+ - [ ] Test top-level :exclusions
+ - [ ] Utility function for plugins to add dependencies
+ Needs to be a no-op if the dep is present, but warn
** Other stuff (post-preview)
- [ ] Offline mode
- [ ] Honor hooks declared in plugin jar metadata?
@@ -39,7 +43,6 @@ See also https://github.com/technomancy/leiningen/issues
- [ ] Address chaining issues in with-profile
- [ ] Use pomegranate to dynamically resolve missing "lein new" templates
- [ ] Install task outside projects
- - [ ] Project middleware
- [ ] Non-transitive AOT
- [ ] Mirror/proxy support, also for search indices
- [ ] Drop clojars snapshots from default repos

0 comments on commit 7187420

Please sign in to comment.