1
0
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:
Michael Camilleri
2025-10-26 06:53:27 +09:00
parent 2a3308005d
commit 6bd02bb5b6
7 changed files with 40 additions and 18 deletions

View File

@@ -0,0 +1,3 @@
@{
:name "sample-bad-bundle1"
}

View File

@@ -0,0 +1,3 @@
@{
:name "sample-bad-bundle2"
}

View File

@@ -4338,8 +4338,8 @@
# Detect bundle name # Detect bundle name
(def infofile-src1 (string path s "bundle" s "info.jdn")) (def infofile-src1 (string path s "bundle" s "info.jdn"))
(def infofile-src2 (string path s "info.jdn")) (def infofile-src2 (string path s "info.jdn"))
(def infofile-src (cond (fexists infofile-src1) infofile-src1 (def infofile-src (if (fexists infofile-src1) infofile-src1 infofile-src2))
(fexists infofile-src2) infofile-src2)) (assert (fexists infofile-src) "bundle must contain info.jdn or bundle/info.jdn")
(def info (-?> infofile-src slurp parse)) (def info (-?> infofile-src slurp parse))
(def bundle-name (get config :name (get info :name))) (def bundle-name (get config :name (get info :name)))
(assertf bundle-name "unable to infer bundle name for %v, use :name argument" path) (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") (assert (next bundle-name) "cannot use empty bundle-name")
(assertf (not (fexists (get-manifest-filename bundle-name))) (assertf (not (fexists (get-manifest-filename bundle-name)))
"bundle %v is already installed" 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 # Setup installed paths
(prime-bundle-paths) (prime-bundle-paths)
(os/mkdir (bundle-dir bundle-name)) (os/mkdir (bundle-dir bundle-name))
# Copy infofile # Copy aliased infofile
(def infofile-dest (bundle-file bundle-name "info.jdn")) (when (fexists infofile-src2)
(when infofile-src (copyfile infofile-src infofile-dest)) (copyfile infofile-src2 (bundle-file bundle-name "info.jdn")))
# Copy aliased initfile # Copy aliased initfile
(def initfile-alias (string path s "bundle.janet")) (when (fexists initfile-src2)
(def initfile-dest (bundle-file bundle-name "init.janet")) (copyfile initfile-src2 (bundle-file bundle-name "init.janet")))
(when (fexists initfile-alias) (copyfile initfile-alias initfile-dest))
# Copy some files into the new location unconditionally # Copy some files into the new location unconditionally
(def implicit-sources (string path s "bundle")) (def implicit-sources (string path s "bundle"))
(when (= :directory (os/stat implicit-sources :mode)) (when (= :directory (os/stat implicit-sources :mode))
@@ -4366,15 +4370,13 @@
(merge-into man config) (merge-into man config)
(sync-manifest man) (sync-manifest man)
(edefer (do (print "installation error, uninstalling") (bundle/uninstall bundle-name)) (edefer (do (print "installation error, uninstalling") (bundle/uninstall bundle-name))
(when (os/stat infofile-dest :mode) (def deps (seq [d :in (get info :dependencies @[])]
(def info (-> infofile-dest slurp parse)) (string (if (dictionary? d) (get d :name) d))))
(def deps (seq [d :in (get info :dependencies @[])] (def missing (filter (complement bundle/installed?) deps))
(string (if (dictionary? d) (get d :name) d)))) (when (next missing)
(def missing (filter (complement bundle/installed?) deps)) (error (string "missing dependencies " (string/join missing ", "))))
(when (next missing) (put man :dependencies deps)
(error (string "missing dependencies " (string/join missing ", ")))) (put man :info info)
(put man :dependencies deps)
(put man :info info))
(def module (get-bundle-module bundle-name)) (def module (get-bundle-module bundle-name))
(def clean (get config :clean)) (def clean (get config :clean))
(def check (get config :check)) (def check (get config :check))

View File

@@ -50,6 +50,11 @@
(def errsym (keyword (gensym))) (def errsym (keyword (gensym)))
~(assert (= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg)) ~(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 (defn check-compile-error
[form] [form]
(def result (compile form)) (def result (compile form))

View File

@@ -117,8 +117,17 @@
(assert (= 0 (length (bundle/list))) "bundles are listed correctly 7") (assert (= 0 (length (bundle/list))) "bundles are listed correctly 7")
(assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8") (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 # 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/list))) "check failure 0")
(assert (= 0 (length (bundle/topolist))) "check failure 1") (assert (= 0 (length (bundle/topolist))) "check failure 1")