diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d8150e..1f06cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/clojure/clojure/tools/deps.clj b/src/main/clojure/clojure/tools/deps.clj index 35f6eb5..10359da 100644 --- a/src/main/clojure/clojure/tools/deps.clj +++ b/src/main/clojure/clojure/tools/deps.clj @@ -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 @@ -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 @@ -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) diff --git a/src/test/clojure/clojure/tools/deps/test_deps.clj b/src/test/clojure/clojure/tools/deps/test_deps.clj index e29746c..3171afc 100644 --- a/src/test/clojure/clojure/tools/deps/test_deps.clj +++ b/src/test/clojure/clojure/tools/deps/test_deps.clj @@ -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)" @@ -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)]