diff --git a/leiningen-core/src/leiningen/core/project.clj b/leiningen-core/src/leiningen/core/project.clj index 78a3d2d3..0c563c16 100644 --- a/leiningen-core/src/leiningen/core/project.clj +++ b/leiningen-core/src/leiningen/core/project.clj @@ -467,11 +467,24 @@ (.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- normalize-profile-names [project profiles] + (reduce + (fn [profiles [composite keys]] + (if (set/subset? (set keys) (set profiles)) + (->> profiles (remove (set keys)) (cons composite)) + profiles)) + profiles + (filter (comp keyword-composite-profile? val) + (-> project meta :profiles)))) + (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 - (s/join "+" (map n (remove #{:default :provided} profiles)))) + (s/join "+" (map n (normalize-profile-names project profiles)))) project))) (defn target-path-subdirs [{:keys [target-path] :as project} key] diff --git a/leiningen-core/test/leiningen/core/test/project.clj b/leiningen-core/test/leiningen/core/test/project.clj index 3c49a78f..2edc2171 100755 --- a/leiningen-core/test/leiningen/core/test/project.clj +++ b/leiningen-core/test/leiningen/core/test/project.clj @@ -590,3 +590,15 @@ [["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] :a {} :b {} :c {} :d {}}})] + (are [ps tp] (= (profile-scope-target-path project ps) {:target-path tp}) + [:a :b] "target/ab" + [:a :b :c] "target/ab+c" + [:b :c] "target/b+c" + [:b :a] "target/ab" + [:c :b :a] "target/ab+c" + [:a] "target/a")))