Skip to content

Commit

Permalink
Add :dir option to create-basis to change relative directory for basi…
Browse files Browse the repository at this point in the history
…s creation
  • Loading branch information
puredanger committed Mar 8, 2024
1 parent f315666 commit 9f5754b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changelog

* next
* Default to Clojure 1.11.2 in root deps.edn
* Fix bug in TDEPS-256 change for :project using relative dirs
* Add :dir option to create-basis to change relative directory for basis creation
* 0.18.1398 on Jan 4, 2023
* Fix function spec typo
* 0.18.1394 on Dec 29, 2023
Expand Down
25 changes: 5 additions & 20 deletions src/main/clojure/clojure/tools/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -787,19 +787,6 @@
project-edn (assoc :project project-edn)
extra-edn (assoc :extra extra-edn))))

(defmacro ^:private in-project-dir
"If project deps.edn is not in the current dir, push project directory
into current directory context while creating basis. Local deps use paths
relative to project dir. Use anaphoric 'assumed-project in body."
[project-deps & body]
`(if (and (instance? String ~project-deps)
(not (.equals dir/*the-dir* (.getParentFile (jio/file ~project-deps)))))
(dir/with-dir (.getParentFile (jio/file ~project-deps))
(let [~'assumed-project (.getName (jio/file ~project-deps))]
~@body))
(let [~'assumed-project ~project-deps]
~@body)))

(defn create-basis
"Create a basis from a set of deps sources and a set of aliases. By default, use
root, user, and project deps and no argmaps (essentially the same classpath you get by
Expand All @@ -812,9 +799,10 @@
subprocesses (tool, resolve-deps, make-classpath-map).
Options:
:dir - directory root path, defaults to current directory
:root - dep source, default = :standard
:user - dep source, default = :standard
:project - dep source, default = :standard (\"./deps.edn\")
:project - dep source, default = :standard (\"deps.edn\")
:extra - dep source, default = nil
:aliases - coll of aliases, default = nil
Expand All @@ -834,12 +822,9 @@
:libs - lib map, per resolve-deps
:classpath - classpath map per make-classpath-map
:classpath-roots - vector of paths in classpath order"
[{:keys [root user project extra aliases] :as params}]
(in-project-dir project
(let [project assumed-project ;; use anaphoric for project deps in context of project dir
params (cond-> params (contains? params :project) (assoc :project project))

basis-config (cond-> nil
[{:keys [dir root user project extra aliases] :as params}]
(dir/with-dir (jio/file (or dir "."))
(let [basis-config (cond-> nil
(contains? params :root) (assoc :root root)
(contains? params :project) (assoc :project project)
(contains? params :user) (assoc :user user)
Expand Down
13 changes: 11 additions & 2 deletions src/test/clojure/clojure/tools/deps/test_deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,14 @@
(let [base (.getCanonicalFile *test-dir*)
adeps (.getPath (jio/file base "a/deps.edn"))
bdeps (.getPath (jio/file base "b/deps.edn"))
adir (.getAbsolutePath (jio/file base "a"))
bdir (.getAbsolutePath (jio/file base "b"))]
(jio/make-parents *test-dir* "a/deps.edn")
(jio/make-parents *test-dir* "b/deps.edn")
(spit adeps "{:deps {b/b {:local/root \"../b\"}}}")
(spit bdeps "{:paths [\"src\"]}")
(let [b (deps/create-basis {:user nil :project adeps})]
(is (contains? (:classpath b) (.getAbsolutePath (jio/file bdir "src"))))))))
(let [abasis (deps/create-basis {:user nil :dir adir})]
(is (contains? (:classpath abasis) (.getAbsolutePath (jio/file bdir "src"))))))))

(deftest empty-nil-deps-is-valid
(testing "file exists but is empty (nil)"
Expand Down Expand Up @@ -513,6 +514,14 @@
:basis-config {:root nil, :user nil, :aliases [:a1 :a2]} ;; aliases remembered
})))

(deftest test-project-deps-doesnt-exist
(is (= "BOGUS.edn" (-> (deps/create-basis {:user nil :project "BOGUS.edn"})
:basis-config :project)))
(is (= "BOGUS.edn" (-> (deps/create-basis {:user nil :dir "foo" :project "BOGUS.edn"})
:basis-config :project)))
(is (= "foo/BOGUS.edn" (-> (deps/create-basis {:user nil :project "foo/BOGUS.edn"})
:basis-config :project))))

(deftest test-resolved-added-libs
(let [basis (deps/create-basis {:user nil :project nil})
libs (:libs basis)]
Expand Down

0 comments on commit 9f5754b

Please sign in to comment.