Skip to content

Commit

Permalink
Fix technomancy#1421 by decomposing profiles into collections of atom…
Browse files Browse the repository at this point in the history
…ic profiles.
  • Loading branch information
Marshall Bockrath-Vandegrift authored and hypirion committed Jan 27, 2014
1 parent 22d3880 commit 8bd6b8f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
23 changes: 19 additions & 4 deletions leiningen-core/src/leiningen/core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,13 @@

(defn- setup-profile-with-empty
"Setup a profile map with empty defaults."
[raw-profile-map]
(let [empty-defaults (select-keys empty-meta-merge-defaults
(keys raw-profile-map))]
(setup-map-defaults raw-profile-map empty-defaults)))
[raw-profile]
(if (composite-profile? raw-profile)
;; TODO: drop support for partially-composite profiles in 3.0
(mapv #(cond-> % (map? %) setup-profile-with-empty) raw-profile)
(let [empty-defaults (select-keys empty-meta-merge-defaults
(keys raw-profile))]
(setup-map-defaults raw-profile empty-defaults))))

(defn- setup-map-of-profiles
"Setup a map of profile maps with empty defaults."
Expand Down Expand Up @@ -494,6 +497,18 @@
(keyword? profile)
(vary-meta update-in [:active-profiles] (fnil conj []) profile)))

(defn- expand-profile* [profiles profile]
(let [content (get profiles profile)]
;; TODO: drop "support" for partially-composite profiles in 3.0
(if (or (nil? content) (map? content) (some map? content))
[profile]
(mapcat (partial expand-profile* profiles) content))))

(defn expand-profile
"Recursively expand the keyword `profile` in `project` to a sequence of
atomic (non-composite) profile keywords."
[project profile] (expand-profile* (:profiles project) profile))

(defn- warn-user-repos [profiles]
(let [has-url? (fn [entry] (or (string? entry) (:url entry)))
repo-profiles (filter #(->> (second %)
Expand Down
17 changes: 10 additions & 7 deletions src/leiningen/with_profile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
prefixes (map first profiles)]
(cond
(every? #{\+ \-} prefixes)
(distinct (reduce
(fn [result profile]
(if (= \+ (first profile))
(concat result [(keyword (subs profile 1))])
(remove #(= (keyword (subs profile 1)) %) result)))
(:active-profiles (meta project))
profiles))
(distinct
(reduce (fn [result profile]
(let [pm (first profile), profile (keyword (subs profile 1))
profiles (project/expand-profile project profile)]
(if (= \+ pm)
(concat result profiles)
(remove (set profiles) result))))
(mapcat (partial project/expand-profile project)
(:active-profiles (meta project)))
profiles))

(not-any? #{\+ \-} prefixes)
(map keyword profiles)
Expand Down
21 changes: 21 additions & 0 deletions test/leiningen/test/with_profile.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns leiningen.test.with-profile
(:use clojure.test leiningen.with-profile))

(defn- prj-map
([p] (prj-map p [:default]))
([p a]
(let [p {:profiles p}, m {:without-profiles p, :active-profiles a}]
(with-meta p m))))

(deftest test-profiles-in-group
(doseq [[project pgroup expected]
[[(prj-map {:default [:base :dev]}) "+foo" [:base, :dev, :foo]]
[(prj-map {:default [:base :dev]}) "-dev" [:base]]
[(prj-map {:default [:base :dev]}) "-dev,+foo" [:base, :foo]]
[(prj-map {:default [:base :dev]}) "-default,+foo" [:foo]]
[(prj-map {:default [:base :dev], :foo [:bar :baz]})
"-default,+foo" [:bar :baz]]
;; TODO: drop support for partially-composite profiles in 3.0
[(prj-map {:default [:base :dev], :foo [:bar {:gross true}]})
"-default,+foo" [:foo]]]]
(is (= expected (profiles-in-group project pgroup)))))

0 comments on commit 8bd6b8f

Please sign in to comment.