Skip to content

Commit

Permalink
Don't re-extract native deps unless deps have changed. Fixes technoma…
Browse files Browse the repository at this point in the history
…ncy#535.

Also introduces the when-stale helper function which should be useful
in other cases as well.
  • Loading branch information
technomancy committed May 7, 2012
1 parent 3826e78 commit f6a4ba5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
36 changes: 27 additions & 9 deletions leiningen-core/src/leiningen/core/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:require [cemerick.pomegranate.aether :as aether]
[cemerick.pomegranate :as pomegranate]
[clojure.java.io :as io]
[clojure.string :as str]
[leiningen.core.user :as user])
(:import (java.util.jar JarFile)
(java.util.regex Pattern)
Expand Down Expand Up @@ -48,6 +49,21 @@
(.mkdirs f)
(io/copy (.getInputStream jar entry) f)))))

(defn- checksum-file [project keys]
(io/file (:target-path project) "checksums" (str/join "+" (map name keys))))

(defn when-stale
"Call f with args when keys in project.clj have changed since the last run.
Stores value of project keys in .lein/checksums directory."
[keys project f & args]
(let [file (checksum-file project keys)
current-value (pr-str (map (juxt identity project) keys))
old-value (and (.exists file) (read-string (slurp file)))]
(when (not= current-value old-value)
(apply f args)
(.mkdirs (.getParentFile file))
(spit file (pr-str current-value)))))

(defn add-repo-auth
"Repository credentials (a map containing some of
#{:username :password :passphrase :private-key-file}) are discovered
Expand Down Expand Up @@ -114,18 +130,20 @@
(throw e)))))

(defn resolve-dependencies
"Simply delegate regular dependencies to pomegranate. This will
ensure they are downloaded into ~/.m2/repositories and that native
deps have been extracted to :native-path. If :add-classpath? is
logically true, will add the resolved dependencies to Leiningen's
"Delegate dependencies to pomegranate. This will ensure they are
downloaded into ~/.m2/repository and that native components of
dependencies have been extracted to :native-path. If :add-classpath?
is logically true, will add the resolved dependencies to Leiningen's
classpath.
Returns a set of the dependencies' files."
Returns a seq of the dependencies' files."
[dependencies-key {:keys [repositories native-path] :as project} & rest]
(doto (->> (apply get-dependencies dependencies-key project rest)
(aether/dependency-files)
(filter #(re-find #"\.(jar|zip)$" (.getName %))))
(extract-native-deps native-path)))
(let [jars (->> (apply get-dependencies dependencies-key project rest)
(aether/dependency-files)
(filter #(re-find #"\.(jar|zip)$" (.getName %))))]
(when-stale [:dependencies] project
extract-native-deps jars native-path)
jars))

(defn dependency-hierarchy
"Returns a graph of the project's dependencies."
Expand Down
2 changes: 1 addition & 1 deletion test_projects/native/project.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(defproject project-name "1.0.0-SNAPSHOT"
:description "Test support for transitive native dependencies"
:native-path "nnnative"
:dependencies [[org.clojure/clojure "1.2.1"]
:dependencies [[org.clojure/clojure "1.4.0"]
[serial-port "1.0.7"]
[penumbra/lwjgl "2.4.2"]
[org.clojars.samaaron/rxtx "2.2.0"]
Expand Down
16 changes: 4 additions & 12 deletions todo.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ See also https://github.com/technomancy/leiningen/issues

* For 2.0.0
** preview4
- [ ] Don't re-extract native deps (#535)
- [ ] Install task outside projects (#546)
- [ ] Force checking of snapshots (#518)
- [ ] Make offline profile use dev profile (#514)
** Low-hanging fruit (newbies, try one of these!)
- [X] Look for :java-cmd in project map
- [X] Remove task-specific silent flags in favour of global bit (#473)
- [X] Port arbitrary upgrade functionality from 1.x branch
- [X] Move newnew template listing into subtasks (newnew #11)
- [X] Collapse all :repl-* settings into :repl-options map (#432)
- [ ] Document creation of new project templates
- [ ] Suppress stack trace when getting help on non-existent task (#515)
- [X] Don't re-extract native deps (#535)
- [ ] Install task outside projects (#546) (LHF)
- [ ] Force checking of snapshots (#518) (LHF)
- [ ] Make offline profile use dev profile (#514) (LHF)
** Intermediate
- [X] Pretty-print pom
- [X] deps :tree
Expand Down

0 comments on commit f6a4ba5

Please sign in to comment.