mirror of
https://github.com/janet-lang/janet
synced 2025-12-13 12:08:07 +00:00
Confirm necessary files during bundle installation
This commit is contained in:
3
examples/sample-bad-bundle1/info.jdn
Normal file
3
examples/sample-bad-bundle1/info.jdn
Normal file
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
:name "sample-bad-bundle1"
|
||||
}
|
||||
3
examples/sample-bad-bundle2/info.jdn
Normal file
3
examples/sample-bad-bundle2/info.jdn
Normal file
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
:name "sample-bad-bundle2"
|
||||
}
|
||||
@@ -4338,8 +4338,8 @@
|
||||
# Detect bundle name
|
||||
(def infofile-src1 (string path s "bundle" s "info.jdn"))
|
||||
(def infofile-src2 (string path s "info.jdn"))
|
||||
(def infofile-src (cond (fexists infofile-src1) infofile-src1
|
||||
(fexists infofile-src2) infofile-src2))
|
||||
(def infofile-src (if (fexists infofile-src1) infofile-src1 infofile-src2))
|
||||
(assert (fexists infofile-src) "bundle must contain info.jdn or bundle/info.jdn")
|
||||
(def info (-?> infofile-src slurp parse))
|
||||
(def bundle-name (get config :name (get info :name)))
|
||||
(assertf bundle-name "unable to infer bundle name for %v, use :name argument" path)
|
||||
@@ -4348,16 +4348,20 @@
|
||||
(assert (next bundle-name) "cannot use empty bundle-name")
|
||||
(assertf (not (fexists (get-manifest-filename bundle-name)))
|
||||
"bundle %v is already installed" bundle-name)
|
||||
# Check initfile
|
||||
(def initfile-src1 (string path s "bundle" s "init.janet"))
|
||||
(def initfile-src2 (string path s "bundle.janet"))
|
||||
(def initfile-src (if (fexists initfile-src1) initfile-src1 initfile-src2))
|
||||
(assert (fexists initfile-src) "bundle must contain bundle.janet or bundle/init.janet")
|
||||
# Setup installed paths
|
||||
(prime-bundle-paths)
|
||||
(os/mkdir (bundle-dir bundle-name))
|
||||
# Copy infofile
|
||||
(def infofile-dest (bundle-file bundle-name "info.jdn"))
|
||||
(when infofile-src (copyfile infofile-src infofile-dest))
|
||||
# Copy aliased infofile
|
||||
(when (fexists infofile-src2)
|
||||
(copyfile infofile-src2 (bundle-file bundle-name "info.jdn")))
|
||||
# Copy aliased initfile
|
||||
(def initfile-alias (string path s "bundle.janet"))
|
||||
(def initfile-dest (bundle-file bundle-name "init.janet"))
|
||||
(when (fexists initfile-alias) (copyfile initfile-alias initfile-dest))
|
||||
(when (fexists initfile-src2)
|
||||
(copyfile initfile-src2 (bundle-file bundle-name "init.janet")))
|
||||
# Copy some files into the new location unconditionally
|
||||
(def implicit-sources (string path s "bundle"))
|
||||
(when (= :directory (os/stat implicit-sources :mode))
|
||||
@@ -4366,15 +4370,13 @@
|
||||
(merge-into man config)
|
||||
(sync-manifest man)
|
||||
(edefer (do (print "installation error, uninstalling") (bundle/uninstall bundle-name))
|
||||
(when (os/stat infofile-dest :mode)
|
||||
(def info (-> infofile-dest slurp parse))
|
||||
(def deps (seq [d :in (get info :dependencies @[])]
|
||||
(string (if (dictionary? d) (get d :name) d))))
|
||||
(def missing (filter (complement bundle/installed?) deps))
|
||||
(when (next missing)
|
||||
(error (string "missing dependencies " (string/join missing ", "))))
|
||||
(put man :dependencies deps)
|
||||
(put man :info info))
|
||||
(def deps (seq [d :in (get info :dependencies @[])]
|
||||
(string (if (dictionary? d) (get d :name) d))))
|
||||
(def missing (filter (complement bundle/installed?) deps))
|
||||
(when (next missing)
|
||||
(error (string "missing dependencies " (string/join missing ", "))))
|
||||
(put man :dependencies deps)
|
||||
(put man :info info)
|
||||
(def module (get-bundle-module bundle-name))
|
||||
(def clean (get config :clean))
|
||||
(def check (get config :check))
|
||||
|
||||
@@ -50,6 +50,11 @@
|
||||
(def errsym (keyword (gensym)))
|
||||
~(assert (= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg))
|
||||
|
||||
(defmacro assert-error-value
|
||||
[msg errval & forms]
|
||||
(def e (gensym))
|
||||
~(assert (= ,errval (try (do ,;forms) ([,e] ,e))) ,msg))
|
||||
|
||||
(defn check-compile-error
|
||||
[form]
|
||||
(def result (compile form))
|
||||
|
||||
@@ -117,8 +117,17 @@
|
||||
(assert (= 0 (length (bundle/list))) "bundles are listed correctly 7")
|
||||
(assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8")
|
||||
|
||||
# Try installing a bundle that is missing initfile
|
||||
(assert-error-value "bad test"
|
||||
"bundle must contain bundle.janet or bundle/init.janet"
|
||||
(bundle/install "./examples/sample-bad-bundle1"))
|
||||
(assert (= 0 (length (bundle/list))) "check failure 0")
|
||||
(assert (= 0 (length (bundle/topolist))) "check failure 1")
|
||||
|
||||
# Try installing a bundle that fails check
|
||||
(assert-error "bad test" (bundle/install "./examples/sample-bad-bundle" :check true))
|
||||
(assert-error-value "bad test"
|
||||
"Check failed!"
|
||||
(bundle/install "./examples/sample-bad-bundle2" :check true))
|
||||
(assert (= 0 (length (bundle/list))) "check failure 0")
|
||||
(assert (= 0 (length (bundle/topolist))) "check failure 1")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user