Skip to content

Commit

Permalink
Expose get-basis-file and get-checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed May 15, 2023
1 parent 647d40a commit 4f54654
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ test/mvn
# IntelliJ
.idea
deps.clj.iml
scratch.clj
30 changes: 27 additions & 3 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
- [`clojure-tools-download-java!`](#borkdude.deps/clojure-tools-download-java!) - Downloads <code>:url</code> zip file to <code>:dest</code> by invoking <code>java</code> with <code>:proxy</code> options on a <code>.java</code> program file, and returns true on success.
- [`clojure-tools-install!`](#borkdude.deps/clojure-tools-install!) - Installs clojure tools archive by downloading it in <code>:out-dir</code>, 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 (<code>.cpcache</code>) from either local dir, if <code>deps-edn</code> exists, or the user cache dir.
- [`get-checksum`](#borkdude.deps/get-checksum) - Returns checksum based on cli-opts (as returned by <code>parse-cli-opts</code>) and config-paths (as returned by <code>get-config-paths</code>).
- [`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.
Expand Down Expand Up @@ -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.
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L748-L995">Source</a></sub></p>
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L759-L1006">Source</a></sub></p>

## <a name="borkdude.deps/clojure-tools-download-direct!">`clojure-tools-download-direct!`</a><a name="borkdude.deps/clojure-tools-download-direct!"></a>
``` clojure
Expand Down Expand Up @@ -173,6 +175,18 @@ Installs clojure tools archive by downloading it in `:out-dir`, if not already t
The current version of deps.clj
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L23-L27">Source</a></sub></p>

## <a name="borkdude.deps/get-basis-file">`get-basis-file`</a><a name="borkdude.deps/get-basis-file"></a>
``` 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`
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L751-L757">Source</a></sub></p>

## <a name="borkdude.deps/get-cache-dir">`get-cache-dir`</a><a name="borkdude.deps/get-cache-dir"></a>
``` clojure

Expand All @@ -183,6 +197,16 @@ Returns cache dir (`.cpcache`) from either local dir, if `deps-edn`
exists, or the user cache dir.
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L691-L702">Source</a></sub></p>

## <a name="borkdude.deps/get-checksum">`get-checksum`</a><a name="borkdude.deps/get-checksum"></a>
``` 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))
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L721-L739">Source</a></sub></p>

## <a name="borkdude.deps/get-config-dir">`get-config-dir`</a><a name="borkdude.deps/get-config-dir"></a>
``` clojure

Expand Down Expand Up @@ -212,7 +236,7 @@ Returns vec of configuration paths, i.e. deps.edn from:
```

Returns help text as string.
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L738-L741">Source</a></sub></p>
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L741-L744">Source</a></sub></p>

## <a name="borkdude.deps/get-install-dir">`get-install-dir`</a><a name="borkdude.deps/get-install-dir"></a>
``` clojure
Expand Down Expand Up @@ -263,7 +287,7 @@ Parses the command line options.
```

Print help text
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L743-L746">Source</a></sub></p>
<p><sub><a href="https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L746-L749">Source</a></sub></p>

## <a name="borkdude.deps/proxy-jvm-opts">`proxy-jvm-opts`</a><a name="borkdude.deps/proxy-jvm-opts"></a>
``` clojure
Expand Down
29 changes: 20 additions & 9 deletions src/borkdude/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion test/borkdude/deps_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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#
Expand Down Expand Up @@ -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))))))

0 comments on commit 4f54654

Please sign in to comment.