Skip to content

Commit

Permalink
Extract native libs for all arch's into native/ dir.
Browse files Browse the repository at this point in the history
Choose which to use at runtime.

I forgot it's not uncommon for users to switch architectures on the
same machine--switching from a 64-bit JVM to a 32-bit client hotspot
needs to be supported without re-running deps.
  • Loading branch information
technomancy committed Aug 16, 2011
1 parent b631a47 commit 928a6e4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
23 changes: 12 additions & 11 deletions src/leiningen/compile.clj
Expand Up @@ -75,20 +75,21 @@
"NUL"
"/dev/null")))

(defn- system-property [[k v]]
(defn- d-property [[k v]]
(format "-D%s=%s" (name k) v))

(defn ^{:internal true} get-jvm-args [project]
`(~@(let [opts (System/getenv "JVM_OPTS")]
(when (seq opts) [opts]))
~@(:jvm-opts project)
~@(:jvm-opts (user-settings))
~@(map system-property {:clojure.compile.path (:compile-path project)
(str (:name project) ".version") (:version project)
:clojure.debug (boolean (or (System/getenv "DEBUG")
(:debug project)))})
~@(when (.exists (file (:native-path project)))
[(system-property :java-library-path (:native-path project))])))
(let [native-arch-path (paths/native-arch-path project)]
`(~@(let [opts (System/getenv "JVM_OPTS")]
(when (seq opts) [opts]))
~@(:jvm-opts project)
~@(:jvm-opts (user-settings))
~@(map d-property {:clojure.compile.path (:compile-path project)
(str (:name project) ".version") (:version project)
:clojure.debug (boolean (or (System/getenv "DEBUG")
(:debug project)))})
~@(when (and native-arch-path (.exists native-arch-path))
[(d-property [:java-library-path native-arch-path])]))))

(defn- injected-forms []
(with-open [rdr (-> "robert/hooke.clj" resource reader PushbackReader.)]
Expand Down
12 changes: 5 additions & 7 deletions src/leiningen/deps.clj
Expand Up @@ -163,21 +163,19 @@
"Returns a seq of Files for all the jars in the project's library directory."
[project]
(filter #(.endsWith (.getName %) ".jar")
(concat (if (:local-repo-classpath project)
(concat (if (:local-repo-classpath project) ; TODO: default in 2.0
(find-local-repo-jars project)
(find-lib-jars project))
;; This must be hard-coded because it's used in
;; bin/lein and thus can't be changed in project.clj.
(.listFiles (file (:root project) "lib/dev")))))

(def native-subdir (format "native/%s/%s/" (name (get-os)) (name (get-arch))))

(defn extract-native-deps [project]
(doseq [jar (map #(JarFile. %) (find-jars project))
entry (enumeration-seq (.entries jar))
:when (.startsWith (.getName entry) native-subdir)]
(let [f (file (:native-path project)
(subs (.getName entry) (count native-subdir)))]
:when (.startsWith (.getName entry) "native/")]
(let [f (file (:native-path project) (subs (.getName entry)
(count "native/")))]
(if (.isDirectory entry)
(.mkdirs f)
(copy (.getInputStream jar entry) f)))))
Expand All @@ -191,7 +189,7 @@
(when-not (or (:disable-deps-clean project)
(:disable-implicit-clean project))
(delete-file-recursively (:library-path project) :silently)
(delete-file-recursively (File. (:root project) "native") :silently))
(delete-file-recursively (:native-path project) :silently))
(let [fileset (do-deps project :dependencies)]
(when-not (no-dev?)
(do-deps project :dev-dependencies))
Expand Down
5 changes: 3 additions & 2 deletions src/leiningen/new.clj
Expand Up @@ -76,8 +76,9 @@
test-ns (str prefix ".test.core")
project-clj (ns->path project-ns)]
(spit (file project-dir ".gitignore")
(apply str (interleave ["pom.xml" "*jar" "/lib/" "/classes/"
".lein-failures" ".lein-deps-sum"]
(apply str (interleave ["/pom.xml" "*jar" "/lib" "/classes"
"/native" "/.lein-failures" "/checkouts"
"/.lein-deps-sum"]
(repeat "\n"))))
(write-implementation project-dir project-clj project-ns)
(write-test project-dir test-ns project-ns)
Expand Down
6 changes: 2 additions & 4 deletions src/leiningen/util/paths.clj
Expand Up @@ -29,10 +29,8 @@
[]
(get-by-pattern native-names (System/getProperty "os.arch")))

(defn legacy-native-path
"Deeply-nested path to native libraries used by native-deps plugin.
Kept for backwards-compatibility; libraries are encouraged to switch
to Leiningen's improved built-in native dependency support."
(defn native-arch-path
"Path to the os/arch-specific directory containing native libs."
[project]
(when (and (get-os) (get-arch))
(file (:native-path project) (name (get-os)) (name (get-arch)))))
Expand Down

0 comments on commit 928a6e4

Please sign in to comment.