added native-path key to project

This commit is contained in:
Bagu is my name. Show my code to River Man 2009-12-13 14:46:47 +01:00 committed by Phil Hagelberg
parent fb13db7d38
commit 768e5d1b18

View file

@ -28,6 +28,32 @@
(filter #(.endsWith (.getName %) ".jar") (filter #(.endsWith (.getName %) ".jar")
(file-seq (file (:library-path project))))) (file-seq (file (:library-path project)))))
(def native-dir-names
{"Mac OS X" "macosx"
"Windows" "windows"
"Linux" "linux"
"amd64" "64"
"x86_64" "64"
"x86" "32"})
(defn get-native-dir-name
[prop-value]
(native-dir-names
(first (drop-while #(nil? (re-find (re-pattern %) prop-value))
(keys native-dir-names)))))
(defn find-native-lib-path
"Returns a File representing the directory where native libs for the
current platform are located."
[project]
(let [osdir (get-native-dir-name (System/getProperty "os.name"))
archdir (get-native-dir-name (System/getProperty "os.arch"))
sep (System/getProperty "file.separator")
f (file (str "native" sep osdir sep archdir sep))]
(if (.exists f)
f
nil)))
(defn make-path (defn make-path
"Constructs an ant Path object from Files and strings." "Constructs an ant Path object from Files and strings."
[& paths] [& paths]
@ -47,6 +73,14 @@
(.addSysproperty java (doto (Environment$Variable.) (.addSysproperty java (doto (Environment$Variable.)
(.setKey "clojure.compile.path") (.setKey "clojure.compile.path")
(.setValue (:compile-path project)))) (.setValue (:compile-path project))))
(when-let [path (or (:native-path project)
(find-native-lib-path project))]
(println (str "path is: " path))
(.addSysproperty java (doto (Environment$Variable.)
(.setKey "java.library.path")
(.setValue (if (= java.io.File (class path))
(.getAbsolutePath path)
path)))))
(.setClasspath java (apply make-path (.setClasspath java (apply make-path
(:source-path project) (:source-path project)
(:test-path project) (:test-path project)