mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Allow :dependencies value in info.jdn to contain dictionaries for complex dependency coordinates
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| @{ | @{ | ||||||
|   :name "sample-dep1" |   :name "sample-dep1" | ||||||
|   :dependencies ["sample-dep2"] |   :dependencies [{:name "sample-dep2"}] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4302,12 +4302,10 @@ | |||||||
|                             (fexists infofile-src2) infofile-src2)) |                             (fexists infofile-src2) infofile-src2)) | ||||||
|     (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 |     (assertf bundle-name "unable to infer bundle name for %v, use :name argument" path) | ||||||
|              "unable to infer bundle name for %v, use :name argument" path) |  | ||||||
|     (assertf (not (string/check-set "\\/" bundle-name)) |     (assertf (not (string/check-set "\\/" bundle-name)) | ||||||
|              "bundle name %v cannot contain path separators" bundle-name) |              "bundle name %v cannot contain path separators" bundle-name) | ||||||
|     (assert (next bundle-name) |     (assert (next bundle-name) "cannot use empty 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) | ||||||
|     # Setup installed paths |     # Setup installed paths | ||||||
| @@ -4316,7 +4314,7 @@ | |||||||
|     # Copy infofile |     # Copy infofile | ||||||
|     (def infofile-dest (bundle-file bundle-name "info.jdn")) |     (def infofile-dest (bundle-file bundle-name "info.jdn")) | ||||||
|     (when infofile-src (copyfile infofile-src infofile-dest)) |     (when infofile-src (copyfile infofile-src infofile-dest)) | ||||||
|     # Copy initfile |     # Copy aliased initfile | ||||||
|     (def initfile-alias (string path s "bundle.janet")) |     (def initfile-alias (string path s "bundle.janet")) | ||||||
|     (def initfile-dest (bundle-file bundle-name "init.janet")) |     (def initfile-dest (bundle-file bundle-name "init.janet")) | ||||||
|     (when (fexists initfile-alias) (copyfile initfile-alias initfile-dest)) |     (when (fexists initfile-alias) (copyfile initfile-alias initfile-dest)) | ||||||
| @@ -4328,22 +4326,28 @@ | |||||||
|     (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)) | ||||||
|       (put man :info info) |       (when (os/stat infofile-dest :mode) | ||||||
|       (def deps (get config :dependencies @[])) |         (def info (-> infofile-dest slurp parse)) | ||||||
|       (def missing (filter (complement bundle/installed?) deps)) |         (def deps (seq [d :in (get info :dependencies @[])] | ||||||
|       (when (next missing) |                    (string (if (dictionary? d) (get d :name) d)))) | ||||||
|         (error (string "missing dependencies " (string/join missing ", ")))) |         (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 clean (get config :clean)) | ||||||
|  |       (def check (get config :check)) | ||||||
|       (def module (get-bundle-module bundle-name)) |       (def module (get-bundle-module bundle-name)) | ||||||
|       (def all-hooks (seq [[k v] :pairs module :when (symbol? k) :unless (get v :private)] (keyword k))) |       (def all-hooks (seq [[k v] :pairs module :when (symbol? k) :unless (get v :private)] (keyword k))) | ||||||
|       (put man :hooks all-hooks) |       (put man :hooks all-hooks) | ||||||
|       (do-hook module bundle-name :dependencies man) |       (do-hook module bundle-name :dependencies man) | ||||||
|       (when (get config :clean) |       (when clean | ||||||
|         (do-hook module bundle-name :clean man)) |         (do-hook module bundle-name :clean man)) | ||||||
|       (do-hook module bundle-name :build man) |       (do-hook module bundle-name :build man) | ||||||
|       (do-hook module bundle-name :install man) |       (do-hook module bundle-name :install man) | ||||||
|       (if (empty? (get man :files)) (print "no files installed, is this a valid bundle?")) |       (if (empty? (get man :files)) (print "no files installed, is this a valid bundle?")) | ||||||
|       (sync-manifest man) |       (sync-manifest man) | ||||||
|       (when (get config :check) |       (when check | ||||||
|         (do-hook module bundle-name :check man))) |         (do-hook module bundle-name :check man))) | ||||||
|     (print "installed " bundle-name) |     (print "installed " bundle-name) | ||||||
|     (when (get man :has-bin-script) |     (when (get man :has-bin-script) | ||||||
|   | |||||||
| @@ -47,26 +47,24 @@ | |||||||
|  |  | ||||||
| # Try (and fail) to install sample-bundle (missing deps) | # Try (and fail) to install sample-bundle (missing deps) | ||||||
| (assert-error "missing dependencies sample-dep1, sample-dep2" | (assert-error "missing dependencies sample-dep1, sample-dep2" | ||||||
|               (bundle/install "./examples/sample-bundle" :dependencies ["sample-dep1" "sample-dep2"])) |               (bundle/install "./examples/sample-bundle")) | ||||||
| (assert (empty? (bundle/list))) | (assert (empty? (bundle/list))) | ||||||
|  |  | ||||||
| # Install deps (dep1 as :auto-remove) | # Install deps (dep1 as :auto-remove) | ||||||
| (assert-no-error "sample-dep2" | (assert-no-error "sample-dep2" | ||||||
|                  (bundle/install "./examples/sample-dep2")) |                  (bundle/install "./examples/sample-dep2")) | ||||||
| (assert (= 1 (length (bundle/list)))) | (assert (= 1 (length (bundle/list)))) | ||||||
| (assert-no-error "sample-dep1" (bundle/install "./examples/sample-dep1" :dependencies ["sample-dep2"])) | (assert-no-error "sample-dep1" (bundle/install "./examples/sample-dep1")) | ||||||
| (assert (= 2 (length (bundle/list)))) | (assert (= 2 (length (bundle/list)))) | ||||||
|  |  | ||||||
| (assert-no-error "sample-dep2 reinstall" (bundle/reinstall "sample-dep2")) | (assert-no-error "sample-dep2 reinstall" (bundle/reinstall "sample-dep2")) | ||||||
| (assert-no-error "sample-dep1 reinstall" | (assert-no-error "sample-dep1 reinstall" (bundle/reinstall "sample-dep1" :auto-remove true)) | ||||||
|                  (bundle/reinstall "sample-dep1" :auto-remove true :dependencies ["sample-dep2"])) |  | ||||||
|  |  | ||||||
| (assert (= 2 (length (bundle/list))) "bundles are listed correctly 1") | (assert (= 2 (length (bundle/list))) "bundles are listed correctly 1") | ||||||
| (assert (= 2 (length (bundle/topolist))) "bundles are listed correctly 2") | (assert (= 2 (length (bundle/topolist))) "bundles are listed correctly 2") | ||||||
|  |  | ||||||
| # Now install sample-bundle | # Now install sample-bundle | ||||||
| (assert-no-error "sample-bundle install" | (assert-no-error "sample-bundle install" (bundle/install "./examples/sample-bundle")) | ||||||
|                  (bundle/install "./examples/sample-bundle" :dependencies ["sample-dep1" "sample-dep2"])) |  | ||||||
|  |  | ||||||
| (assert-error "" (bundle/install "./examples/sample-dep11111")) | (assert-error "" (bundle/install "./examples/sample-dep11111")) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Camilleri
					Michael Camilleri