deps phase 2: jolt-deps tool resolves deps.edn git/local deps
A separate jolt-deps executable (mirroring jpm beside janet) resolves a deps.edn into source roots and runs jolt with them on JOLT_PATH; the runtime stays deps-agnostic. - src/jolt/deps.janet: read deps.edn (Janet parses it directly), resolve :git/* and :local/root via jpm/pm's download-bundle (git fetch + cache, no build), recurse for transitive deps, return de-duped roots. jpm loaded lazily so it's never embedded. Roots cached on a deps.edn hash. - src/jolt/deps_cli.janet + project.janet: the jolt-deps tool — path/run/repl/-e. - main: apply JOLT_PATH at runtime (the CLI ctx is frozen into the image at build, so init's env read wouldn't see it). Verified end to end against a local dep and a real git dep (medley). git only, pure clj/cljc. Test: deps-resolve-test (local deps, no network).
This commit is contained in:
parent
6ea43fb623
commit
4d8494d620
6 changed files with 234 additions and 14 deletions
61
test/integration/deps-resolve-test.janet
Normal file
61
test/integration/deps-resolve-test.janet
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# deps.edn resolution into source roots, then loading a library through them.
|
||||
# Uses :local/root deps only so it needs no network (the git path is the same
|
||||
# code, exercised manually against real repos).
|
||||
|
||||
(use ../../src/jolt/api)
|
||||
(use ../../src/jolt/types)
|
||||
(import ../../src/jolt/deps :as deps)
|
||||
|
||||
(def base (string (os/getenv "TMPDIR") "/jolt-deps-resolve-" (os/time)))
|
||||
(defn rmrf [p]
|
||||
(when (os/stat p)
|
||||
(if (= :directory (os/stat p :mode))
|
||||
(do (each e (os/dir p) (rmrf (string p "/" e))) (os/rmdir p))
|
||||
(os/rm p))))
|
||||
(rmrf base)
|
||||
|
||||
(defn mkdirs [p]
|
||||
(def abs (string/has-prefix? "/" p))
|
||||
(var acc nil)
|
||||
(each seg (filter |(not= "" $) (string/split "/" p))
|
||||
(set acc (cond (nil? acc) (if abs (string "/" seg) seg) (string acc "/" seg)))
|
||||
(unless (os/stat acc) (os/mkdir acc))))
|
||||
|
||||
# project -> depends on lib-a (local), which depends on lib-b (local, transitive)
|
||||
(each d ["proj/src" "a/src/liba" "b/src/libb"] (mkdirs (string base "/" d)))
|
||||
(spit (string base "/proj/deps.edn") `{:paths ["src"] :deps {my/a {:local/root "../a"}}}`)
|
||||
(spit (string base "/a/deps.edn") `{:paths ["src"] :deps {my/b {:local/root "../b"}}}`)
|
||||
(spit (string base "/b/deps.edn") `{:paths ["src"]}`)
|
||||
(spit (string base "/a/src/liba/core.clj") "(ns liba.core (:require [libb.core :as b]))\n(defn val [] (b/n))\n")
|
||||
(spit (string base "/b/src/libb/core.clj") "(ns libb.core)\n(defn n [] 99)\n")
|
||||
|
||||
(var fails 0)
|
||||
(defn check [label got expected]
|
||||
(if (= got expected) (print " ok " label)
|
||||
(do (++ fails) (printf " FAIL %s: want %q, got %q" label expected got))))
|
||||
|
||||
(os/cd (string base "/proj"))
|
||||
(def roots (deps/resolve-deps "deps.edn" (string base "/proj/jpm_tree")))
|
||||
# roots: proj/src, a/src (transitive: b/src) — at least the two dep srcs present
|
||||
(check "resolves transitive local dep roots"
|
||||
(truthy? (and (some |(string/has-suffix? "/a/src" $) roots)
|
||||
(some |(string/has-suffix? "/b/src" $) roots)))
|
||||
true)
|
||||
|
||||
# load through the resolved roots: liba.core requires libb.core transitively
|
||||
(def ctx (init {:paths roots}))
|
||||
(ctx-set-current-ns ctx "user")
|
||||
(let [r (protect (eval-string ctx "(do (require (quote [liba.core :as a])) (a/val))"))]
|
||||
(check "require local lib + transitive dep" (if (r 0) (r 1) (string "ERR " (r 1))) 99))
|
||||
|
||||
# cached resolution returns the same roots without re-walking
|
||||
(check "cached resolve matches"
|
||||
(deep= roots (deps/resolve-deps-cached "deps.edn" (string base "/proj/jpm_tree")))
|
||||
true)
|
||||
|
||||
(os/cd "/")
|
||||
(rmrf base)
|
||||
|
||||
(if (> fails 0)
|
||||
(error (string "deps-resolve-test: " fails " failing check(s)"))
|
||||
(print "\nAll deps-resolve tests passed!"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue