From 1540d7fdaf9f707aca5ee9c16199af280a772fd9 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 31 Dec 2024 17:35:59 -0600 Subject: [PATCH] Refactored tool classpath calculation and align on create-basis --- CHANGELOG.md | 1 + src/main/clojure/clojure/tools/deps.clj | 28 +-- .../tools/deps/script/generate_manifest2.clj | 10 +- .../tools/deps/script/make_classpath2.clj | 88 +++----- .../deps/script/test_make_classpath2.clj | 188 +++++++++--------- 5 files changed, 141 insertions(+), 174 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcfc6b72..db3c70f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog *Also see [Tools and installer changelog](https://github.com/clojure/brew-install/blob/1.12.0/CHANGELOG.md)* * next + * Refactored tool classpath calculation and align on create-basis * Update to tools.gitlibs 2.6.206 * Update other dep versions to latest * 0.21.1460 on Nov 21, 2024 diff --git a/src/main/clojure/clojure/tools/deps.clj b/src/main/clojure/clojure/tools/deps.clj index e8a936e3..37624392 100644 --- a/src/main/clojure/clojure/tools/deps.clj +++ b/src/main/clojure/clojure/tools/deps.clj @@ -630,8 +630,9 @@ (-> (make-classpath-map {:paths paths} lib-map classpath-args) :classpath-roots join-classpath)) (defn tool - "Transform project edn for tool by applying tool args (keys = :paths, :deps) and - returning an updated project edn." + "Replaces project-edn :deps and :paths with tool :deps and :paths + and returns a new project-edn map. + (Also supports :replace-deps and :replace-paths as aliases.)" [project-edn tool-args] (let [{:keys [replace-deps replace-paths deps paths]} tool-args] (cond-> project-edn @@ -704,8 +705,7 @@ (dir/with-dir root-dir (let [basis (create-basis {:project :standard ;; deps.edn at root - :extra {:aliases {:deps/TOOL {:replace-deps {} :replace-paths ["."]}}} - :aliases [:deps/TOOL alias]}) + :args {:replace-deps {} :replace-paths ["."]}}) cp (join-classpath (:classpath-roots basis)) qual-f (qualify-fn f (get-in basis [:aliases alias])) exit (exec-prep! root-dir cp qual-f exec-args)] @@ -795,8 +795,9 @@ Each dep source value can be :standard, a string path, a deps edn map, or nil. Sources are merged in the order - :root, :user, :project, :extra. - Aliases refer to argmaps in the merged deps that will be supplied to the basis - subprocesses (tool, resolve-deps, make-classpath-map). + When resolving deps and forming the classpath, different steps need various + args. These are pulled from the 'argmap' which is a merged set of args + selected by the aliases and optionally a map of args. Options: :dir - directory root path, defaults to current directory @@ -805,6 +806,7 @@ :project - dep source, default = :standard (\"deps.edn\") :extra - dep source, default = nil :aliases - coll of aliases, default = nil + :args - extra map of argmap args, merged after aliases The following subprocess argmap args can be provided: Key Subproc Description @@ -822,13 +824,9 @@ :libs - lib map, per resolve-deps :classpath - classpath map per make-classpath-map :classpath-roots - vector of paths in classpath order" - [{:keys [dir root user project extra aliases] :as params}] + [{:keys [dir root user project extra aliases args] :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) - (contains? params :extra) (assoc :extra extra) + (let [basis-config (cond-> (select-keys params [:root :project :user :extra :args]) (seq aliases) (assoc :aliases (vec aliases))) {root-edn :root user-edn :user project-edn :project extra-edn :extra} (create-edn-maps params) @@ -841,11 +839,13 @@ argmap-data (->> aliases (remove nil?) (map #(get alias-data %))) - argmap (apply merge-alias-maps argmap-data) + argmap (apply merge-alias-maps (conj argmap-data args)) project-tooled-edn (tool project-edn argmap) merged-edn (merge-edns [root-edn user-edn project-tooled-edn extra-edn]) - basis (calc-basis merged-edn {:resolve-args argmap, :classpath-args argmap})] + basis (if (:skip-cp argmap) ;; UNSUPPORTED, USE AT YOUR OWN RISK + (assoc merged-edn :argmap argmap) + (calc-basis merged-edn {:resolve-args argmap, :classpath-args argmap}))] (cond-> (assoc basis :basis-config basis-config) (pos? (count argmap)) (assoc :argmap argmap))))) diff --git a/src/main/clojure/clojure/tools/deps/script/generate_manifest2.clj b/src/main/clojure/clojure/tools/deps/script/generate_manifest2.clj index bab31d04..69c2d986 100644 --- a/src/main/clojure/clojure/tools/deps/script/generate_manifest2.clj +++ b/src/main/clojure/clojure/tools/deps/script/generate_manifest2.clj @@ -10,7 +10,6 @@ clojure.tools.deps.script.generate-manifest2 (:require [clojure.java.io :as jio] [clojure.tools.cli :as cli] - [clojure.tools.deps :as deps] [clojure.tools.deps.gen.pom :as pom] [clojure.tools.deps.script.parse :as parse] [clojure.tools.deps.script.make-classpath2 :as makecp] @@ -36,9 +35,7 @@ --config-data={...} - deps.edn as data --gen TYPE - manifest type to generate (currently only pom) - Options: - -Raliases - concated resolve-deps alias names, applied to the :deps - -Aaliases - concatenated generic alias names" + Options (see make-classpath2)" [& args] (let [{:keys [options errors]} (cli/parse-opts args opts)] (when (seq errors) @@ -46,10 +43,7 @@ (System/exit 1)) (let [{:keys [gen config-user config-project]} options] (try - (let [basis-map (makecp/run-core (merge options - {:install-deps (deps/root-deps) - :user-deps (makecp/read-deps config-user) - :project-deps (makecp/read-deps config-project)})) + (let [basis-map (makecp/run-core options) mod-map (:basis basis-map) ;; treat all transitive deps as top-level deps updated-deps (reduce-kv (fn [m lib {:keys [dependents] :as coord}] diff --git a/src/main/clojure/clojure/tools/deps/script/make_classpath2.clj b/src/main/clojure/clojure/tools/deps/script/make_classpath2.clj index 94949d2e..247e65eb 100644 --- a/src/main/clojure/clojure/tools/deps/script/make_classpath2.clj +++ b/src/main/clojure/clojure/tools/deps/script/make_classpath2.clj @@ -11,7 +11,6 @@ (:require [clojure.java.io :as jio] [clojure.pprint :as pprint] - [clojure.string :as str] [clojure.tools.cli :as cli] [clojure.tools.deps :as deps] [clojure.tools.deps.extensions :as ext] @@ -22,9 +21,12 @@ (:import [clojure.lang IExceptionInfo])) +(defn blank-to-nil [s] + (if (zero? (count s)) nil s)) + (def ^:private opts [;; deps.edn inputs - [nil "--config-user PATH" "User deps.edn location"] + [nil "--config-user PATH" "User deps.edn location" :parse-fn blank-to-nil] [nil "--config-project PATH" "Project deps.edn location"] [nil "--config-data EDN" "Final deps.edn data to treat as the last deps.edn file" :parse-fn parse/parse-config] ;; tool args to resolve @@ -61,61 +63,45 @@ (defn resolve-tool-args "Resolves the tool by name to the coord + usage data. Returns the proper alias args as if the tool was specified as an alias." - [tool-name config] + [tool-name] (if-let [{:keys [lib coord]} (tool/resolve-tool tool-name)] - (let [manifest-type (ext/manifest-type lib coord config) + (let [config nil ;; for now, tools are only git or local which have none + manifest-type (ext/manifest-type lib coord config) coord' (merge coord manifest-type) {:keys [ns-default ns-aliases]} (ext/coord-usage lib coord' (:deps/manifest coord') config)] {:replace-deps {lib coord'} - :replace-paths ["."] :ns-default ns-default :ns-aliases ns-aliases}) (throw (ex-info (str "Unknown tool: " tool-name) {:tool tool-name})))) (defn run-core - "Run make-classpath script from/to data (no file stuff). Returns: - {;; Outputs: + "Run make-classpath script from/to data. Returns map w/keys: :basis ;; the basis, including classpath roots :trace ;; if requested, trace.edn file - :manifests ;; manifest files used in making classpath - }" - [{:keys [install-deps user-deps project-deps config-data ;; all deps.edn maps - tool-mode tool-name tool-resolver ;; -T options + :manifests ;; manifest files used in making classpath" + [{:keys [config-user config-project config-data tool-data main-aliases exec-aliases repl-aliases tool-aliases skip-cp threads trace tree] :as _opts}] (when (and main-aliases exec-aliases) (throw (ex-info "-M and -X cannot be used at the same time" {}))) - (let [pretool-edn (deps/merge-edns [install-deps user-deps project-deps config-data]) - ;; tool use - :deps/:paths/:replace-deps/:replace-paths in project if needed - tool-args (cond - tool-name (tool-resolver tool-name pretool-edn) - tool-mode {:replace-deps {} :replace-paths ["."]}) - tool-edn (when tool-args {:aliases {:deps/TOOL tool-args}}) - ;; :deps/TOOL is a synthetic deps.edn combining the tool definition and usage - ;; it is injected at the end of the deps chain and added as a pseudo alias - ;; the effects are seen in the basis but this pseduo alias should not escape - combined-tool-args (deps/combine-aliases - (deps/merge-edns [pretool-edn tool-edn]) - (concat main-aliases exec-aliases repl-aliases tool-aliases (when tool-edn [:deps/TOOL]))) - project-deps (deps/tool project-deps combined-tool-args) - - ;; calc basis - merge-edn (deps/merge-edns [install-deps user-deps project-deps config-data (when tool-edn tool-edn)]) ;; recalc to get updated project-deps - combined-exec-aliases (concat main-aliases exec-aliases repl-aliases tool-aliases (when tool-edn [:deps/TOOL])) - _ (check-aliases merge-edn combined-exec-aliases) - argmap (deps/combine-aliases merge-edn combined-exec-aliases) - resolve-args (cond-> argmap - threads (assoc :threads (Long/parseLong threads)) - trace (assoc :trace trace) - tree (assoc :trace true)) - basis (cond-> nil - (not skip-cp) (merge - (deps/calc-basis merge-edn {:resolve-args resolve-args, :classpath-args argmap}) - {:basis-config (cond-> {} ;; :root and :project are always :standard - (nil? user-deps) (assoc :user nil) ;; -Srepro => :user nil - config-data (assoc :extra config-data) ;; -Sdeps => :extra ... - (seq combined-exec-aliases) (assoc :aliases (vec combined-exec-aliases)))}) - (pos? (count argmap)) (assoc :argmap argmap)) + (let [combined-exec-aliases (concat main-aliases exec-aliases repl-aliases tool-aliases) + args (cond-> nil + threads (assoc :threads (Long/parseLong threads)) + trace (assoc :trace trace) + tree (assoc :trace true) + skip-cp (assoc :skip-cp true) + (or tool-data tool-aliases) (assoc :replace-paths ["."] :replace-deps {}) + tool-data (merge tool-data)) + basis (deps/create-basis + {:user config-user + :project config-project + :extra config-data + :aliases combined-exec-aliases + :args args}) + + ;; check for unused aliases and warn + _ (check-aliases basis combined-exec-aliases) + libs (:libs basis) trace (-> libs meta :trace) @@ -129,19 +115,12 @@ (ext/manifest-file lib coord (:deps/manifest mf) basis))) (remove nil?) seq)] - (when (and (-> argmap :main-opts seq) repl-aliases) + (when (and (-> (:argmap basis) :main-opts seq) repl-aliases) (io/printerrln "WARNING: Use of :main-opts with -A is deprecated. Use -M instead.")) (cond-> {:basis basis} trace (assoc :trace trace) manifests (assoc :manifests manifests)))) -(defn read-deps - [name] - (when (not (str/blank? name)) - (let [f (jio/file name)] - (when (.exists f) - (deps/slurp-deps f))))) - (defn write-lines [lines file] (if lines @@ -152,11 +131,10 @@ (defn run "Run make-classpath script. See -main for details." - [{:keys [config-user config-project cp-file jvm-file main-file basis-file manifest-file skip-cp trace tree] :as opts}] - (let [opts' (merge opts {:install-deps (deps/root-deps) - :user-deps (read-deps config-user) - :project-deps (read-deps config-project) - :tool-resolver resolve-tool-args}) + [{:keys [cp-file jvm-file main-file basis-file manifest-file skip-cp tool-mode tool-name tool-aliases trace tree] :as opts}] + (let [opts' (cond-> opts + (and tool-mode (not tool-aliases)) + (assoc :tool-data (when tool-name (resolve-tool-args tool-name)))) {:keys [basis manifests], trace-log :trace} (run-core opts') {:keys [argmap libs classpath-roots]} basis {:keys [jvm-opts main-opts]} argmap] diff --git a/src/test/clojure/clojure/tools/deps/script/test_make_classpath2.clj b/src/test/clojure/clojure/tools/deps/script/test_make_classpath2.clj index fba57ae2..c953f94d 100644 --- a/src/test/clojure/clojure/tools/deps/script/test_make_classpath2.clj +++ b/src/test/clojure/clojure/tools/deps/script/test_make_classpath2.clj @@ -4,13 +4,6 @@ [clojure.tools.deps.script.make-classpath2 :as mc] [clojure.java.io :as jio])) -(def install-data - {:paths ["src"] - :deps {'org.clojure/clojure {:mvn/version "1.10.1"}} - :aliases {:test {:extra-paths ["test"]}} - :mvn/repos {"central" {:url "https://repo1.maven.org/maven2/"} - "clojars" {:url "https://repo.clojars.org/"}}}) - (defn submap? "Is m1 a subset of m2?" [m1 m2] @@ -21,55 +14,61 @@ (= m1 m2))) (deftest outside-project - (let [{:keys [basis]} (mc/run-core {:install-deps install-data})] + (let [{:keys [basis]} (mc/run-core {:config-user nil})] (is (submap? - {:libs {'org.clojure/clojure {:mvn/version "1.10.1"} - 'org.clojure/spec.alpha {:mvn/version "0.2.176"} - 'org.clojure/core.specs.alpha {:mvn/version "0.2.44"}}} + {:libs {'org.clojure/clojure {} + 'org.clojure/spec.alpha {} + 'org.clojure/core.specs.alpha {}}} basis)))) (deftest in-project - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :project-deps {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}}}})] + (let [{:keys [basis]} (mc/run-core {:config-user nil + :config-project {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}}}})] (is (submap? {:libs {'org.clojure/clojure {:mvn/version "1.9.0"} - 'org.clojure/spec.alpha {:mvn/version "0.1.143"} - 'org.clojure/core.specs.alpha {:mvn/version "0.1.24"}}} + 'org.clojure/spec.alpha {} + 'org.clojure/core.specs.alpha {}}} basis)))) ;; alias :e with :extra-deps extends the project deps (deftest extra-deps - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :project-deps {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}} - :aliases {:e {:extra-deps {'org.clojure/test.check {:mvn/version "0.9.0"}}}}} + (let [{:keys [basis]} (mc/run-core {:config-project {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}} + :aliases {:e {:extra-deps {'org.clojure/test.check {:mvn/version "0.9.0"}}}}} :repl-aliases [:e]})] (is (submap? {:libs {'org.clojure/clojure {:mvn/version "1.9.0"} - 'org.clojure/spec.alpha {:mvn/version "0.1.143"} - 'org.clojure/core.specs.alpha {:mvn/version "0.1.24"} + 'org.clojure/spec.alpha {} + 'org.clojure/core.specs.alpha {} 'org.clojure/test.check {:mvn/version "0.9.0"}}} basis)))) -;; alias :t with :replace-deps replaces the project deps +;; alias :t with :replace-deps replaces the project deps and paths (deftest tool-deps - (doseq [k [:deps :replace-deps]] ;; FUTURE - remove :deps here (will warn for now) - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :project-deps {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}} - :aliases {:t {k {'org.clojure/test.check {:mvn/version "0.9.0"}}}}} - :repl-aliases [:t]})] + (doseq [k [:deps :replace-deps]] ;; synonyms + (let [{:keys [basis]} (mc/run-core {:config-project {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}} + :aliases {:t {k {'org.clojure/test.check {:mvn/version "0.9.0"}}}}} + :tool-aliases [:t]})] (is (submap? - {:paths ["src"] + {:paths ["."] :deps {'org.clojure/test.check {:mvn/version "0.9.0"}} - :libs {'org.clojure/clojure {:mvn/version "1.10.1"} - 'org.clojure/spec.alpha {:mvn/version "0.2.176"} - 'org.clojure/core.specs.alpha {:mvn/version "0.2.44"} - 'org.clojure/test.check {:mvn/version "0.9.0"}}} + :libs {'org.clojure/test.check {:mvn/version "0.9.0"}}} + basis))))) + +;; simulate named tool +(deftest tool-deps-named + (doseq [k [:deps :replace-deps]] ;; synonyms + (let [{:keys [basis]} (mc/run-core {:config-project {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}}} + :tool-data {k {'org.clojure/test.check {:mvn/version "0.9.0"}} + :replace-paths ["."]}})] + (is (submap? + {:paths ["."] + :deps {'org.clojure/test.check {:mvn/version "0.9.0"}} + :libs {'org.clojure/test.check {:mvn/version "0.9.0"}}} basis))))) ;; alias :o with :override-deps overrides the version to use (deftest override-deps - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :project-deps {:aliases {:o {:override-deps {'org.clojure/clojure {:mvn/version "1.6.0"}}}}} + (let [{:keys [basis]} (mc/run-core {:config-project {:aliases {:o {:override-deps {'org.clojure/clojure {:mvn/version "1.6.0"}}}}} :repl-aliases [:o]})] (is (submap? {:libs {'org.clojure/clojure {:mvn/version "1.6.0"}}} @@ -81,12 +80,11 @@ ;; paths and deps in alias replace (deftest alias-paths-and-deps - (doseq [p [:paths :replace-paths] ;; FUTURE - remove :paths, :deps here (will warn for now) + (doseq [p [:paths :replace-paths] d [:deps :replace-deps]] - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :project-deps {:paths ["a" "b"] - :aliases {:q {p ["a" "c"] - d {'org.clojure/clojure {:mvn/version "1.6.0"}}}}} + (let [{:keys [basis]} (mc/run-core {:config-project {:paths ["a" "b"] + :aliases {:q {p ["a" "c"] + d {'org.clojure/clojure {:mvn/version "1.6.0"}}}}} :repl-aliases [:q]})] (is (submap? {:paths ["a" "c"] @@ -96,9 +94,8 @@ ;; paths replace in chain (deftest paths-replace - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :user-deps {:paths ["x"]} - :project-deps {:paths ["y"]} + (let [{:keys [basis]} (mc/run-core {:config-user {:paths ["x"]} + :config-project {:paths ["y"]} :config-data {:paths ["z"]}})] (is (submap? {:paths ["z"]} basis)) (is (= #{"z"} (-> basis :classpath (select-cp :path-key) keys set))))) @@ -106,18 +103,16 @@ ;; :paths in alias replaces, multiple alias :paths will be combined (deftest alias-paths-replace (doseq [p [:paths :replace-paths]] ;; FUTURE - remove :paths here (will warn for now) - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :user-deps {:aliases {:p {p ["x" "y"]}}} - :project-deps {:aliases {:q {p ["z"]}}} + (let [{:keys [basis]} (mc/run-core {:config-user {:aliases {:p {p ["x" "y"]}}} + :config-project {:aliases {:q {p ["z"]}}} :repl-aliases [:p :q]})] (is (submap? {:paths ["x" "y" "z"]} basis)) (is (= #{"x" "y" "z"} (-> basis :classpath (select-cp :path-key) keys set)))))) ;; :extra-paths add (deftest extra-paths-add - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :user-deps {:aliases {:p {:extra-paths ["x" "y"]}}} - :project-deps {:aliases {:q {:extra-paths ["z"]}}} + (let [{:keys [basis]} (mc/run-core {:config-user {:aliases {:p {:extra-paths ["x" "y"]}}} + :config-project {:aliases {:q {:extra-paths ["z"]}}} :repl-aliases [:p :q]})] (is (submap? {:paths ["src"]} @@ -126,58 +121,53 @@ ;; java opts in aliases are additive (deftest jvm-opts-add - (let [core-ret (mc/run-core {:install-deps install-data - :user-deps {:aliases {:j1 {:jvm-opts ["-server" "-Xms100m"]}}} - :project-deps {:aliases {:j2 {:jvm-opts ["-Xmx200m"]}}} + (let [core-ret (mc/run-core {:config-user {:aliases {:j1 {:jvm-opts ["-server" "-Xms100m"]}}} + :config-project {:aliases {:j2 {:jvm-opts ["-Xmx200m"]}}} :repl-aliases [:j1 :j2]})] (is (= ["-server" "-Xms100m" "-Xmx200m"] (-> core-ret :basis :argmap :jvm-opts))))) ;; main opts replace (deftest main-opts-replace - (let [core-ret (mc/run-core {:install-deps install-data - :user-deps {:aliases {:m1 {:main-opts ["a" "b"]}}} - :project-deps {:aliases {:m2 {:main-opts ["c"]}}} - :repl-aliases [:m1 :m2]})] - (is (= ["c"] (-> core-ret :basis :argmap :main-opts))))) + (doseq [a [:repl-aliases :main-aliases]] ;; will WARN for -A, but not for -M + (let [core-ret (mc/run-core {:config-user {:aliases {:m1 {:main-opts ["a" "b"]}}} + :config-project {:aliases {:m2 {:main-opts ["c"]}}} + a [:m1 :m2]})] + (is (= ["c"] (-> core-ret :basis :argmap :main-opts)))))) ;; local manifests returned (deftest manifest-local - (let [{:keys [manifests]} (mc/run-core {:install-deps install-data - :project-deps {:deps {'io.github.clojure/data.json {:git/sha "f367490" :git/tag "v2.4.0"} - 'io.github.clojure/data.codec {:git/sha "8ef09db", :git/tag "data.codec-0.1.1", :deps/manifest :pom}}}})] + (let [{:keys [manifests]} (mc/run-core {:config-project {:deps {'io.github.clojure/data.json {:git/sha "f367490" :git/tag "v2.4.0"} + 'io.github.clojure/data.codec {:git/sha "8ef09db", :git/tag "data.codec-0.1.1", :deps/manifest :pom}}}})] ;; returns a manifest for both projects (deps.edn and pom.xml respectively) (is (= 2 (count manifests))))) ;; repositories should be retained for generate-manifest2's use (deftest repo-config-retained - (let [{:keys [basis]} (mc/run-core {:install-deps install-data})] ;; install-data has central and clojars + (let [{:keys [basis]} (mc/run-core {})] ;; root deps has central and clojars (is (= #{"central" "clojars"} (-> basis :mvn/repos keys set))))) ;; skip-cp flag prevents resolve-deps/make-classpath (deftest skip-cp-flag - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :project-deps {:deps {'org.clojure/clojure {:mvn/version "1.10.0"}}} + (let [{:keys [basis]} (mc/run-core {:config-project {:deps {'org.clojure/clojure {:mvn/version "1.10.0"}}} :skip-cp true})] - (is (nil? basis)))) + (= {} (select-keys basis [:libs :classpath :classpath-roots])))) ;; skip-cp flag still passes exec-args for -X or -T (deftest skip-cp-exec - (let [core-ret (mc/run-core {:install-deps install-data - :project-deps {:deps {'org.clojure/clojure {:mvn/version "1.10.0"}} - :aliases {:x {:exec-fn 'clojure.core/prn :exec-args {:a 1}}}} + (let [core-ret (mc/run-core {:config-project {:deps {'org.clojure/clojure {:mvn/version "1.10.0"}} + :aliases {:x {:exec-fn 'clojure.core/prn :exec-args {:a 1}}}} :exec-aliases [:x] :skip-cp true})] (is (submap? {:exec-fn 'clojure.core/prn, :exec-args {:a 1}} (-> core-ret :basis :argmap))))) (deftest removing-deps - (let [{:keys [basis]} (mc/run-core {:install-deps install-data - :user-deps {:aliases - {:remove-clojure - {:classpath-overrides - '{org.clojure/clojure nil - org.clojure/spec.alpha nil - org.clojure/core.specs.alpha nil}}}} + (let [{:keys [basis]} (mc/run-core {:config-user {:aliases + {:remove-clojure + {:classpath-overrides + '{org.clojure/clojure nil + org.clojure/spec.alpha nil + org.clojure/core.specs.alpha nil}}}} :repl-aliases [:remove-clojure]}) {:keys [libs classpath-roots classpath]} basis] (is (= 3 (count libs))) ;; lib set is not changed by classpath-overrides @@ -186,11 +176,9 @@ (deftest tool-alias (let [{:keys [basis]} - (mc/run-core {:install-deps install-data - :user-deps {:aliases {:t {:extra-deps {'org.clojure/data.json {:mvn/version "2.0.1"}}}}} - :project-deps {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} - :tool-aliases [:t] - :tool-mode true}) + (mc/run-core {:config-user {:aliases {:t {:extra-deps {'org.clojure/data.json {:mvn/version "2.0.1"}}}}} + :config-project {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} + :tool-aliases [:t]}) {:keys [libs classpath-roots classpath]} basis paths (filter #(get-in classpath [% :path-key]) classpath-roots)] ;; includes tool dep and not project deps @@ -203,10 +191,8 @@ ;; clj -T a/fn (deftest tool-bare (let [{:keys [basis]} - (mc/run-core {:install-deps install-data - :user-deps {} - :project-deps {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} - :tool-mode true}) + (mc/run-core {:config-project {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} + :tool-data {:replace-paths ["."]}}) {:keys [libs classpath-roots classpath]} basis paths (filter #(get-in classpath [% :path-key]) classpath-roots)] (is (not (contains? libs 'cheshire/cheshire))) @@ -216,14 +202,10 @@ ;; clj -Tfoo (deftest tool-by-name (let [{:keys [basis]} - (mc/run-core {:install-deps install-data - :user-deps {} - :project-deps {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} - :tool-mode true - :tool-name "foo" - :tool-resolver {"foo" {:replace-deps {'org.clojure/data.json {:mvn/version "2.0.1"}} - :replace-paths ["."] - :ns-default 'a.b}}}) + (mc/run-core {:config-project {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} + :tool-data {:replace-deps {'org.clojure/data.json {:mvn/version "2.0.1"}} + :replace-paths ["."] + :ns-default 'a.b}}) {:keys [libs classpath-roots classpath argmap]} basis paths (filter #(get-in classpath [% :path-key]) classpath-roots)] ;; execute-args in basis argmap @@ -235,23 +217,35 @@ (is (= (map #(.getCanonicalPath (jio/file %)) ["."]) (map #(.getCanonicalPath (jio/file %)) paths))))) +(deftest tool-by-name-newer-clojure + (let [{:keys [basis]} + (mc/run-core {:config-root {:deps {'org.clojure/clojure {:mvn/version "1.9.0"}} :path ["src"]} + :config-project {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}}} + :tool-data {:replace-deps {'org.clojure/clojure {:mvn/version "1.12.0"}} + :replace-paths ["."] + :ns-default 'a.b}}) + {:keys [libs classpath-roots classpath argmap]} basis + paths (filter #(get-in classpath [% :path-key]) classpath-roots)] + ;; execute-args in basis argmap + (is (= (:ns-default argmap) 'a.b)) + ;; tool deps, not project deps + (is (not (contains? libs 'cheshire/cheshire))) + (is (submap? {:deps {'org.clojure/clojure {:mvn/version "1.12.0"}}} basis)))) + ;; clj -T:a:b (deftest tool-with-aliases (let [{:keys [basis]} - (mc/run-core {:install-deps install-data - :user-deps {} - :project-deps {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}} - :aliases {:a {:replace-paths ["x"]} - :b {:replace-paths ["y"]}}} - :tool-mode true + (mc/run-core {:config-project {:deps {'cheshire/cheshire {:mvn/version "5.10.0"}} + :aliases {:a {:replace-paths ["x"]} + :b {:replace-paths ["y"]}}} :tool-aliases [:a :b]}) {:keys [libs classpath-roots classpath]} basis paths (filter #(get-in classpath [% :path-key]) classpath-roots)] ;; tool deps, not project deps (is (not (contains? libs 'cheshire/cheshire))) - (is (= (map #(.getCanonicalPath (jio/file %)) ["x" "y" "."]) + (is (= (map #(.getCanonicalPath (jio/file %)) ["." "x" "y"]) (map #(.getCanonicalPath (jio/file %)) paths))))) (comment (clojure.test/run-tests) -) +) \ No newline at end of file