made changes as suggested by technomancy

This commit is contained in:
Bagu is my name. Show my code to River Man 2009-12-16 16:25:44 +01:00 committed by Phil Hagelberg
parent fa5cc6f326
commit 8d35fe3f91

View file

@ -41,19 +41,23 @@
"sparc" "sparc"}) "sparc" "sparc"})
(defn get-native-dir-name (defn get-native-dir-name
"Gets a value from the native-dir-names map, but uses a regex
to check the prop-value for a match against keys instead of just
doing a map lookup. Reason for this is that e.g. windows may
report different names for different OS versions but will likely
always contain the string 'Windows'"
[prop-value] [prop-value]
(native-dir-names (native-dir-names
(first (drop-while #(nil? (re-find (re-pattern %) prop-value)) (first (drop-while #(nil? (re-find (re-pattern %) prop-value))
(keys native-dir-names))))) (keys native-dir-names)))))
(defn find-native-lib-path (defn find-native-lib-path
"Returns a File representing the directory where native libs for the "Returns a File representing the directory where native libs for the
current platform are located." current platform are located."
[project] [project]
(let [osdir (get-native-dir-name (System/getProperty "os.name")) (let [osdir (get-native-dir-name (System/getProperty "os.name"))
archdir (get-native-dir-name (System/getProperty "os.arch")) archdir (get-native-dir-name (System/getProperty "os.arch"))
sep (System/getProperty "file.separator") f (file "native" osdir archdir)]
f (file (str "native" sep osdir sep archdir sep))]
(if (.exists f) (if (.exists f)
f f
nil))) nil)))
@ -78,14 +82,14 @@
(.setKey "clojure.compile.path") (.setKey "clojure.compile.path")
(.setValue (:compile-path project)))) (.setValue (:compile-path project))))
(when-let [path (or (:native-path project) (when-let [path (or (:native-path project)
(find-native-lib-path project))] (find-native-lib-path project))]
(.addSysproperty java (doto (Environment$Variable.) (.addSysproperty java (doto (Environment$Variable.)
(.setKey "java.library.path") (.setKey "java.library.path")
(.setValue (cond (.setValue (cond
(= java.io.File (class path)) (= java.io.File (class path))
(.getAbsolutePath path) (.getAbsolutePath path)
(fn? path) (path) (fn? path) (path)
:default path))))) :default path)))))
(.setClasspath java (apply make-path (.setClasspath java (apply make-path
(:source-path project) (:source-path project)
(:test-path project) (:test-path project)