diff --git a/.gitignore b/.gitignore index 18f55b0..ccce74c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ test/mvn # IntelliJ .idea deps.clj.iml +scratch.clj diff --git a/API.md b/API.md index 9c0b7dc..0542dc1 100644 --- a/API.md +++ b/API.md @@ -10,7 +10,9 @@ - [`clojure-tools-download-java!`](#borkdude.deps/clojure-tools-download-java!) - Downloads :url zip file to :dest by invoking java with :proxy options on a .java program file, and returns true on success. - [`clojure-tools-install!`](#borkdude.deps/clojure-tools-install!) - Installs clojure tools archive by downloading it in :out-dir, if not already there, and extracting in-place. - [`deps-clj-version`](#borkdude.deps/deps-clj-version) - The current version of deps.clj. + - [`get-basis-file`](#borkdude.deps/get-basis-file) - Returns path to basis file. - [`get-cache-dir`](#borkdude.deps/get-cache-dir) - Returns cache dir (.cpcache) from either local dir, if deps-edn exists, or the user cache dir. + - [`get-checksum`](#borkdude.deps/get-checksum) - Returns checksum based on cli-opts (as returned by parse-cli-opts) and config-paths (as returned by get-config-paths). - [`get-config-dir`](#borkdude.deps/get-config-dir) - Retrieves configuration directory. - [`get-config-paths`](#borkdude.deps/get-config-paths) - Returns vec of configuration paths, i.e. - [`get-help`](#borkdude.deps/get-help) - Returns help text as string. @@ -121,7 +123,7 @@ See [`help-text`](#borkdude.deps/help-text). env variable is set and a succesful attempt is made to download the archive by invoking a java subprocess passing the env variable value as command line options. -

Source

+

Source

## `clojure-tools-download-direct!` ``` clojure @@ -173,6 +175,18 @@ Installs clojure tools archive by downloading it in `:out-dir`, if not already t The current version of deps.clj

Source

+## `get-basis-file` +``` clojure + +(get-basis-file {:keys [cache-dir checksum]}) +``` + +Returns path to basis file. Required options: + + * - `cache-dir` as returned by [`get-cache-dir`](#borkdude.deps/get-cache-dir) + * - `checksum` as returned by `get-check-sum` +

Source

+ ## `get-cache-dir` ``` clojure @@ -183,6 +197,16 @@ Returns cache dir (`.cpcache`) from either local dir, if `deps-edn` exists, or the user cache dir.

Source

+## `get-checksum` +``` clojure + +(get-checksum {:keys [cli-opts config-paths]}) +``` + +Returns checksum based on cli-opts (as returned by [`parse-cli-opts`](#borkdude.deps/parse-cli-opts)) + and config-paths (as returned by [`get-config-paths`](#borkdude.deps/get-config-paths)) +

Source

+ ## `get-config-dir` ``` clojure @@ -212,7 +236,7 @@ Returns vec of configuration paths, i.e. deps.edn from: ``` Returns help text as string. -

Source

+

Source

## `get-install-dir` ``` clojure @@ -263,7 +287,7 @@ Parses the command line options. ``` Print help text -

Source

+

Source

## `proxy-jvm-opts` ``` clojure diff --git a/src/borkdude/deps.clj b/src/borkdude/deps.clj index cca9c69..fe3ebed 100755 --- a/src/borkdude/deps.clj +++ b/src/borkdude/deps.clj @@ -718,16 +718,19 @@ public class ClojureToolsDownloader { [(.getPath (io/file config-dir "deps.edn")) deps-edn]))) -(defn- calculate-checksum [opts config-paths] +(defn get-checksum + "Returns checksum based on cli-opts (as returned by `parse-cli-opts`) + and config-paths (as returned by `get-config-paths`)" + [{:keys [cli-opts config-paths]}] (let [val* (str/join "|" (concat [cache-version] - (:repl-aliases opts) - [(:exec-aliases opts) - (:main-aliases opts) - (:deps-data opts) - (:tool-name opts) - (:tool-aliases opts)] + (:repl-aliases cli-opts) + [(:exec-aliases cli-opts) + (:main-aliases cli-opts) + (:deps-data cli-opts) + (:tool-name cli-opts) + (:tool-aliases cli-opts)] (map (fn [config-path] (if (.exists (io/file config-path)) config-path @@ -745,6 +748,14 @@ public class ClojureToolsDownloader { [] (println @help-text)) +(defn get-basis-file + "Returns path to basis file. Required options: + + * - `cache-dir` as returned by `get-cache-dir` + * - `checksum` as returned by `get-check-sum`" + [{:keys [cache-dir checksum]}] + (.getPath (io/file cache-dir (str checksum ".basis")))) + (defn -main "See `help-text`. @@ -831,11 +842,11 @@ public class ClojureToolsDownloader { ;; Construct location of cached classpath file tool-name (:tool-name cli-opts) tool-aliases (:tool-aliases cli-opts) - ck (calculate-checksum cli-opts config-paths) + ck (get-checksum {:cli-opts cli-opts :config-paths config-paths}) cp-file (.getPath (io/file cache-dir (str ck ".cp"))) jvm-file (.getPath (io/file cache-dir (str ck ".jvm"))) main-file (.getPath (io/file cache-dir (str ck ".main"))) - basis-file (.getPath (io/file cache-dir (str ck ".basis"))) + basis-file (get-basis-file {:cache-dir cache-dir :checksum ck}) manifest-file (.getPath (io/file cache-dir (str ck ".manifest"))) _ (when (:verbose cli-opts) (println "deps.clj version =" deps-clj-version) diff --git a/test/borkdude/deps_test.clj b/test/borkdude/deps_test.clj index 5c712fb..15e7a7f 100644 --- a/test/borkdude/deps_test.clj +++ b/test/borkdude/deps_test.clj @@ -205,7 +205,7 @@ program, but throws an exception in case of error while is still in the `babashka.deps` scope." [env-vars & body] - (let [body-str (pr-str body)] + (let [body-str (pr-str body)] `(let [shell-command# @#'deps/internal-shell-command ret*# (promise) sh-mock# (fn mock# @@ -433,3 +433,27 @@ (test) (delete) (test))) + +(deftest get-basis-file-test + (let [deps-edn (deps/get-local-deps-edn + {:cli-opts []}) + config-dir (deps/get-config-dir) + install-dir (deps/get-install-dir)] + (is + (set/subset? + (-> (deps/get-basis-file {:cache-dir + (deps/get-cache-dir + {:deps-edn deps-edn + :config-dir config-dir}) + :checksum (deps/get-checksum + {:cli-opts [] + :config-paths + (deps/get-config-paths {:cli-opts [] + :deps-edn deps-edn + :config-dir config-dir + :install-dir install-dir})})}) + slurp + edn/read-string + keys + set) + (set '(:paths :deps :aliases :mvn/repos :libs :classpath-roots :classpath :basis-config))))))