Merge remote-tracking branch 'weavejester/smarter-target-profiles'

Conflicts:
	leiningen-core/src/leiningen/core/project.clj
This commit is contained in:
Phil Hagelberg 2017-03-23 14:35:02 -07:00
commit 627d4448d4
2 changed files with 51 additions and 1 deletions

View file

@ -466,11 +466,38 @@
(.toString (BigInteger. 1 (-> (java.security.MessageDigest/getInstance "SHA1")
(.digest (.getBytes content)))) 16))
(defn- keyword-composite-profile? [profile]
(and (composite-profile? profile) (every? keyword? profile)))
(defn- ordered-keyword-composite-profiles [project]
(->> project meta :profiles
(filter (comp keyword-composite-profile? val))
(remove (comp empty? val))
(sort-by count)
(reverse)))
(defn- first-matching-composite [profiles composites]
(->> composites
(filter (fn [[_ v]] (= v (take (count v) profiles))))
(first)))
(defn- normalize-profile-names [project profiles]
(let [composites (ordered-keyword-composite-profiles project)]
(loop [profiles' profiles
normalized ()]
(if (seq profiles')
(if-let [[k v] (first-matching-composite profiles' composites)]
(recur (drop (count v) profiles') (cons k normalized))
(recur (rest profiles') (cons (first profiles') normalized)))
(if (= (count profiles) (count normalized))
profiles
(normalize-profile-names project (reverse normalized)))))))
(defn profile-scope-target-path [project profiles]
(let [n #(if (map? %) (subs (sha1 (pr-str %)) 0 8) (name %))]
(if (:target-path project)
(update-in project [:target-path] format
(str/join "+" (map n (remove #{:default :provided} profiles))))
(str/join "+" (map n (normalize-profile-names project profiles))))
project)))
(defn target-path-subdirs [{:keys [target-path] :as project} key]

View file

@ -590,3 +590,26 @@
[["central" {:url "https://repo1.maven.org/maven2/"
:snapshots false}]
["clojars" {:url "https://clojars.org/repo/"}]]}})))))))
(deftest test-profile-scope-target-path
(let [project (with-meta
{:target-path "target/%s"}
{:profiles {:ab [:a :b]
:abc [:ab :c]
:bcd [:b :c :d]
:a {}
:b {}
:c {}
:d {}
:e {}}})]
(are [ps tp] (= (profile-scope-target-path project ps) {:target-path tp})
[:a :b] "target/ab"
[:a :b :c] "target/abc"
[:b :c] "target/b+c"
[:b :a] "target/b+a"
[:c :b :a] "target/c+b+a"
[:c :a :b] "target/c+ab"
[:a :b :c :d] "target/abc+d"
[:e :b :c :d] "target/e+bcd"
[:c :a :b :d] "target/c+ab+d"
[:a] "target/a")))