1
0
mirror of https://github.com/janet-lang/janet synced 2024-10-03 01:00:40 +00:00

Don't expose bundle/pack, do expose bundle/add

Bundle/pack is a strange interface that is mostly just
to implement a safe reinistall process when the original source
is lost.
This commit is contained in:
Calvin Rose 2024-05-29 07:20:37 -05:00
parent 600e822933
commit 8fca6b7af4

View File

@ -4124,20 +4124,22 @@
(bundle-uninstall-unchecked bundle-name)) (bundle-uninstall-unchecked bundle-name))
(defn bundle/topolist (defn bundle/topolist
"Get topological order of all bundles, such that each bundle is listed after its dependencies. "Get topological order of all bundles, such that each bundle is listed after its dependencies."
DFS (tarjan)"
[] []
(def visited @{}) (def visited @{})
(def cycle-detect @{}) (def cycle-detect @{})
(def order @[]) (def order @[])
(def stack @[])
(defn visit (defn visit
[b] [b]
(array/push stack b)
(if (get visited b) (break)) (if (get visited b) (break))
(if (get cycle-detect b) (errorf "cycle detected in bundle dependencies: %s" b)) (if (get cycle-detect b) (errorf "cycle detected in bundle dependencies: %s" (string/join stack " -> ")))
(put cycle-detect b true) (put cycle-detect b true)
(each d (get (bundle/manifest b) :dependencies []) (visit d)) (each d (get (bundle/manifest b) :dependencies []) (visit d))
(put cycle-detect b nil) (put cycle-detect b nil)
(put visited b true) (put visited b true)
(array/pop stack)
(array/push order b)) (array/push order b))
(each b (bundle/list) (visit b)) (each b (bundle/list) (visit b))
order) order)
@ -4233,7 +4235,7 @@
(print "installed " bundle-name) (print "installed " bundle-name)
bundle-name) bundle-name)
(defn bundle/pack (defn- bundle/pack
"Take an installed bundle and create a bundle source directory that can be used to "Take an installed bundle and create a bundle source directory that can be used to
reinstall the bundle on a compatible system. This is used to create backups for installed reinstall the bundle on a compatible system. This is used to create backups for installed
bundles without rebuilding, or make a prebuilt bundle for other systems." bundles without rebuilding, or make a prebuilt bundle for other systems."
@ -4259,9 +4261,9 @@
(copyfile file (string dest-dir s filename)) (copyfile file (string dest-dir s filename))
(array/push install-source ~(bundle/add-file manifest ,filename ,relpath ,perm))) (array/push install-source ~(bundle/add-file manifest ,filename ,relpath ,perm)))
(errorf "unexpected file %v" file))) (errorf "unexpected file %v" file)))
(def b @"(defn install [manifest]\n") (def b @"(defn install [manifest]")
(each form install-source (buffer/format b " %j\n" form)) (each form install-source (buffer/format b "\n %j" form))
(buffer/push b ")") (buffer/push b ")\n")
(spit install-hook b)) (spit install-hook b))
dest-dir) dest-dir)
@ -4317,6 +4319,20 @@
(print "add " absdest) (print "add " absdest)
absdest) absdest)
(defn bundle/add
"Add files and directories during a bundle install relative to `(dyn *syspath*)`.
Added paths will be recorded in the bundle manifest such that they are properly tracked
and removed during an upgrade or uninstall."
[manifest src &opt dest chmod-mode]
(default dest src)
(def s (sep))
(case (os/stat src :mode)
:directory
(let [absdest (bundle/add-directory manifest dest chmod-mode)]
(each d (os/dir src) (bundle/add manifest (string src s d) (string dest s d) chmod-mode))
absdest)
:file (bundle/add-file manifest src dest chmod-mode)))
(defn bundle/update-all (defn bundle/update-all
"Reinstall all bundles" "Reinstall all bundles"
[] []