Skip to content

Commit f1d47bd

Browse files
committed
Use :dependencies argument in bundle/install for dependency checking
1 parent 58b1491 commit f1d47bd

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

src/boot/boot.janet

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4294,62 +4294,56 @@
42944294
"Install a bundle from the local filesystem. The name of the bundle will be inferred from the bundle, or passed as a parameter :name in `config`."
42954295
[path &keys config]
42964296
(def path (bundle-rpath path))
4297-
(def clean (get config :clean))
4298-
(def check (get config :check))
42994297
(def s (sep))
4300-
# Check meta file for dependencies and default name
4301-
(def infofile-pre-1 (string path s "bundle" s "info.jdn"))
4302-
(def infofile-pre (if (fexists infofile-pre-1) infofile-pre-1 (string path s "info.jdn"))) # allow for alias
4303-
(var default-bundle-name nil)
4304-
(when (os/stat infofile-pre :mode)
4305-
(def info (-> infofile-pre slurp parse))
4306-
(def deps (get info :dependencies @[]))
4307-
(set default-bundle-name (get info :name))
4308-
(def missing (seq [d :in deps :when (not (bundle/installed? d))] (string d)))
4309-
(when (next missing) (errorf "missing dependencies %s" (string/join missing ", "))))
4310-
(def bundle-name (get config :name default-bundle-name))
4311-
(assertf bundle-name "unable to infer bundle name for %v, use :name argument" path)
4298+
# Detect bundle name
4299+
(def infofile-src1 (string path s "bundle" s "info.jdn"))
4300+
(def infofile-src2 (string path s "info.jdn"))
4301+
(def infofile-src (cond (fexists infofile-src1) infofile-src1
4302+
(fexists infofile-src2) infofile-src2))
4303+
(def info (-?> infofile-src slurp parse))
4304+
(def bundle-name (get config :name (get info :name)))
4305+
(assertf bundle-name
4306+
"unable to infer bundle name for %v, use :name argument" path)
43124307
(assertf (not (string/check-set "\\/" bundle-name))
43134308
"bundle name %v cannot contain path separators" bundle-name)
4314-
(assert (next bundle-name) "cannot use empty bundle-name")
4309+
(assert (next bundle-name)
4310+
"cannot use empty bundle-name")
43154311
(assertf (not (fexists (get-manifest-filename bundle-name)))
43164312
"bundle %v is already installed" bundle-name)
43174313
# Setup installed paths
43184314
(prime-bundle-paths)
43194315
(os/mkdir (bundle-dir bundle-name))
4320-
# Aliases for common bundle/ files
4321-
(def bundle.janet (string path s "bundle.janet"))
4322-
(when (fexists bundle.janet) (copyfile bundle.janet (bundle-file bundle-name "init.janet")))
4323-
(when (fexists infofile-pre) (copyfile infofile-pre (bundle-file bundle-name "info.jdn")))
4316+
# Copy infofile
4317+
(def infofile-dest (bundle-file bundle-name "info.jdn"))
4318+
(when infofile-src (copyfile infofile-src infofile-dest))
4319+
# Copy initfile
4320+
(def initfile-alias (string path s "bundle.janet"))
4321+
(def initfile-dest (bundle-file bundle-name "init.janet"))
4322+
(when (fexists initfile-alias) (copyfile initfile-alias initfile-dest))
43244323
# Copy some files into the new location unconditionally
43254324
(def implicit-sources (string path s "bundle"))
43264325
(when (= :directory (os/stat implicit-sources :mode))
43274326
(copyrf implicit-sources (bundle-dir bundle-name)))
43284327
(def man @{:name bundle-name :local-source path :files @[]})
43294328
(merge-into man config)
4330-
(def infofile (bundle-file bundle-name "info.jdn"))
4331-
(put man :auto-remove (get config :auto-remove))
43324329
(sync-manifest man)
43334330
(edefer (do (print "installation error, uninstalling") (bundle/uninstall bundle-name))
4334-
(when (os/stat infofile :mode)
4335-
(def info (-> infofile slurp parse))
4336-
(def deps (get info :dependencies @[]))
4337-
(def missing (filter (complement bundle/installed?) deps))
4338-
(when (next missing)
4339-
(error (string "missing dependencies " (string/join missing ", "))))
4340-
(put man :dependencies deps)
4341-
(put man :info info))
4331+
(put man :info info)
4332+
(def deps (get config :dependencies @[]))
4333+
(def missing (filter (complement bundle/installed?) deps))
4334+
(when (next missing)
4335+
(error (string "missing dependencies " (string/join missing ", "))))
43424336
(def module (get-bundle-module bundle-name))
43434337
(def all-hooks (seq [[k v] :pairs module :when (symbol? k) :unless (get v :private)] (keyword k)))
43444338
(put man :hooks all-hooks)
43454339
(do-hook module bundle-name :dependencies man)
4346-
(when clean
4340+
(when (get config :clean)
43474341
(do-hook module bundle-name :clean man))
43484342
(do-hook module bundle-name :build man)
43494343
(do-hook module bundle-name :install man)
43504344
(if (empty? (get man :files)) (print "no files installed, is this a valid bundle?"))
43514345
(sync-manifest man)
4352-
(when check
4346+
(when (get config :check)
43534347
(do-hook module bundle-name :check man)))
43544348
(print "installed " bundle-name)
43554349
(when (get man :has-bin-script)

test/suite-bundle.janet

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,26 @@
4747

4848
# Try (and fail) to install sample-bundle (missing deps)
4949
(assert-error "missing dependencies sample-dep1, sample-dep2"
50-
(bundle/install "./examples/sample-bundle"))
50+
(bundle/install "./examples/sample-bundle" :dependencies ["sample-dep1" "sample-dep2"]))
5151
(assert (empty? (bundle/list)))
5252

5353
# Install deps (dep1 as :auto-remove)
5454
(assert-no-error "sample-dep2"
5555
(bundle/install "./examples/sample-dep2"))
5656
(assert (= 1 (length (bundle/list))))
57-
(assert-no-error "sample-dep1" (bundle/install "./examples/sample-dep1"))
57+
(assert-no-error "sample-dep1" (bundle/install "./examples/sample-dep1" :dependencies ["sample-dep2"]))
5858
(assert (= 2 (length (bundle/list))))
5959

6060
(assert-no-error "sample-dep2 reinstall" (bundle/reinstall "sample-dep2"))
61-
(assert-no-error "sample-dep1 reinstall" (bundle/reinstall "sample-dep1" :auto-remove true))
61+
(assert-no-error "sample-dep1 reinstall"
62+
(bundle/reinstall "sample-dep1" :auto-remove true :dependencies ["sample-dep2"]))
6263

6364
(assert (= 2 (length (bundle/list))) "bundles are listed correctly 1")
6465
(assert (= 2 (length (bundle/topolist))) "bundles are listed correctly 2")
6566

6667
# Now install sample-bundle
67-
(assert-no-error "sample-bundle install" (bundle/install "./examples/sample-bundle"))
68+
(assert-no-error "sample-bundle install"
69+
(bundle/install "./examples/sample-bundle" :dependencies ["sample-dep1" "sample-dep2"]))
6870

6971
(assert-error "" (bundle/install "./examples/sample-dep11111"))
7072

0 commit comments

Comments
 (0)