From 43581e240fb651456720c31663cad86fb887bbd5 Mon Sep 17 00:00:00 2001 From: Marc Liberatore Date: Tue, 19 Mar 2013 15:25:51 -0400 Subject: [PATCH 1/3] update java.library.path based on :native-prefix, addressing #898 --- .../src/leiningen/core/classpath.clj | 3 ++- leiningen-core/src/leiningen/core/eval.clj | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/leiningen-core/src/leiningen/core/classpath.clj b/leiningen-core/src/leiningen/core/classpath.clj index 0c9862bf..51679295 100644 --- a/leiningen-core/src/leiningen/core/classpath.clj +++ b/leiningen-core/src/leiningen/core/classpath.clj @@ -181,7 +181,8 @@ (when (= (subvec dep 0 2) (subvec v 0 2 )) v)) dependencies)) -(defn- get-native-prefix +(defn get-native-prefix + "Return the :native-prefix of a dependency vector, or nil." [[id version & {:as opts}]] (get opts :native-prefix)) diff --git a/leiningen-core/src/leiningen/core/eval.clj b/leiningen-core/src/leiningen/core/eval.clj index f82fd35c..31ff1c5e 100644 --- a/leiningen-core/src/leiningen/core/eval.clj +++ b/leiningen-core/src/leiningen/core/eval.clj @@ -59,13 +59,19 @@ leiningen.core.utils/platform-nullsink instead." ;; # Subprocess stuff -(defn native-arch-path - "Path to the os/arch-specific directory containing native libs." +(defn- native-arch-paths + "Paths to the os/arch-specific directory containing native libs." [project] (let [os (:os project (get-os)) - arch (:arch project (get-arch))] + arch (:arch project (get-arch)) + native-path (:native-path project)] (if (and os arch) - (io/file (:native-path project) (name os) (name arch))))) + (conj + (->> (:dependencies project) + (map classpath/get-native-prefix) + (remove nil?) + (map #(io/file native-path %))) + (io/file native-path (name os) (name arch)))))) (defn- as-str [x] (if (instance? clojure.lang.Named x) @@ -91,7 +97,7 @@ leiningen.core.utils/platform-nullsink instead." (defn- get-jvm-args "Calculate command-line arguments for launching java subprocess." [project] - (let [native-arch-path (native-arch-path project)] + (let [native-arch-paths (native-arch-paths project)] `(~@(get-jvm-opts-from-env (System/getenv "JVM_OPTS")) ~@(:jvm-opts project) ~@(get arch-options (:arch project)) @@ -101,8 +107,12 @@ leiningen.core.utils/platform-nullsink instead." :file.encoding (or (System/getProperty "file.encoding") "UTF-8") :clojure.debug (boolean (or (System/getenv "DEBUG") (:debug project)))}) - ~@(if (and native-arch-path (.exists native-arch-path)) - [(d-property [:java.library.path native-arch-path])]) + ~@(if native-arch-paths + (let [extant-paths (filter #(.exists %) native-arch-paths)] + (if (seq extant-paths) + [(d-property [:java.library.path + (string/join java.io.File/pathSeparatorChar + extant-paths)])]))) ~@(when-let [{:keys [host port non-proxy-hosts]} (classpath/get-proxy-settings)] [(d-property [:http.proxyHost host]) (d-property [:http.proxyPort port]) From 8540c73c1746fd23122f331d1d573d3c72ff73e8 Mon Sep 17 00:00:00 2001 From: Marc Liberatore Date: Tue, 19 Mar 2013 15:39:28 -0400 Subject: [PATCH 2/3] document user-visible changes addressing #898 --- sample.project.clj | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sample.project.clj b/sample.project.clj index 996af7a5..48afd615 100644 --- a/sample.project.clj +++ b/sample.project.clj @@ -31,14 +31,24 @@ :url "http://www.eclipse.org/legal/epl-v10.html" :distribution :repo :comments "same as Clojure"} - ;; Dependencies are listed as [group-id/name version]. + ;; Dependencies are listed as [group-id/name version]; in addition + ;; to keywords supported by Pomegranate, you can use :native-prefix + ;; to specify a prefix. This prefix is used to extract natives in + ;; jars that don't adhere to the default "//" layout that + ;; Leiningen expects. :dependencies [[org.clojure/clojure "1.3.0"] [org.jclouds/jclouds "1.0" :classifier "jdk15" :scope "test"] [net.sf.ehcache/ehcache "2.3.1" :extension "pom"] [log4j "1.2.15" :exclusions [[javax.mail/mail :extension "jar"] [javax.jms/jms :classifier "*"] com.sun.jdmk/jmxtools - com.sun.jmx/jmxri]]] + com.sun.jmx/jmxri]] + [org.lwjgl.lwjgl/lwjgl "2.8.5"] + [org.lwjgl.lwjgl/lwjgl-platform "2.8.5" + :classifier "natives-osx" + ;; LWJGL stores natives in the root of the jar; this + ;; :native-prefix will extract them. + :native-prefix ""]] ;; Global exclusions are applied across the board, as an alternative ;; to duplication for multiple dependencies with the same excluded libraries. :exclusions [org.apache.poi/poi From d9e943e519a175932d073b7d206a20b822111944 Mon Sep 17 00:00:00 2001 From: Marc Liberatore Date: Tue, 19 Mar 2013 16:07:06 -0400 Subject: [PATCH 3/3] fix error in test introduced in 43581e2 --- leiningen-core/src/leiningen/core/eval.clj | 2 +- test/leiningen/test/deps.clj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/leiningen-core/src/leiningen/core/eval.clj b/leiningen-core/src/leiningen/core/eval.clj index 31ff1c5e..26f19b4b 100644 --- a/leiningen-core/src/leiningen/core/eval.clj +++ b/leiningen-core/src/leiningen/core/eval.clj @@ -59,7 +59,7 @@ leiningen.core.utils/platform-nullsink instead." ;; # Subprocess stuff -(defn- native-arch-paths +(defn native-arch-paths "Paths to the os/arch-specific directory containing native libs." [project] (let [os (:os project (get-os)) diff --git a/test/leiningen/test/deps.clj b/test/leiningen/test/deps.clj index 1583e54c..f679172c 100644 --- a/test/leiningen/test/deps.clj +++ b/test/leiningen/test/deps.clj @@ -109,6 +109,6 @@ (deps native-project) (is (= (conj (get-in native-lib-files-map [(eval/get-os) (eval/get-arch)]) ".gitkeep") - (set (for [f (rest (file-seq (io/file (eval/native-arch-path - native-project))))] + (set (for [f (rest (file-seq (io/file (first (eval/native-arch-paths + native-project)))))] (.getName f))))))