diff --git a/core/core-lib.el b/core/core-lib.el index 8be5a53a8..d7f22c6c7 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -244,16 +244,36 @@ executed when called with `set!'. FORMS are not evaluated until `set!' calls it. (defmacro def-bootstrap! (name &rest forms) "TODO" (declare (indent defun)) - `(push (cons ',name - (lambda () - (cl-flet ((sh (lambda (&rest args) (apply 'doom-sh args))) - (sudo (lambda (&rest args) (apply 'doom-sudo args))) - (fetch (lambda (&rest args) (apply 'doom-fetch args))) - (message (lambda (&rest args) - (apply 'message (format "[%s] %s" ,(symbol-name name) (car args)) - (cdr args))))) - ,@forms))) - doom-bootstraps)) + (let ((prereqs (plist-get forms :requires))) + (while (keywordp (car forms)) + (dotimes (i 2) (pop forms))) + `(push (cons ',name + (lambda () + (cl-flet ((sh (lambda (&rest args) (apply 'doom-sh args))) + (sudo (lambda (&rest args) (apply 'doom-sudo args))) + (fetch (lambda (&rest args) (apply 'doom-fetch args))) + (message (lambda (&rest args) + (apply 'message (format "[%s] %s" ,(symbol-name name) (car args)) + (cdr args))))) + (if (not ,(if (not prereqs) + 't + (unless (listp prereqs) + (setq prereqs (list prereqs))) + `(and ,@(mapcar (lambda (sym) `(doom-bootstrap ',sym)) prereqs)))) + (message "Aborting (prerequisites failed)") + (message "Bootstrapping") + ,@forms + (message "Done"))))) + doom-bootstraps))) + +(defun doom-bootstrap (id) + (when-let (bootstrap (assq id doom-bootstraps)) + (condition-case ex + (progn (funcall (cdr bootstrap)) t) + ('error + (message "[%s] Aborted (ERROR: %s)" + id (if (eq (car ex) 'error) (cadr ex) ex)) + nil)))) (defun doom/bootstrap (ids) "Bootstraps a module, if it has a bootstrapper. Bootstraps are expected to be @@ -275,12 +295,7 @@ using `doom-fetch'." (and err-not-func (message "ERROR: These bootstraps were invalid: %s" err-not-func))) (error "There were errors. Aborting.")) - (dolist (id ids) - (let ((bootstrap (assq id doom-bootstraps))) - (message "[%s] BOOTSTRAP START" id) - (with-demoted-errors (format "[%s] ERROR: %%s" id) - (message "[%s] %s" - id (if (funcall (cdr bootstrap)) "SKIPPED (nothing to do)" "DONE"))))))) + (mapc 'doom-bootstrap ids))) (provide 'core-lib) ;;; core-lib.el ends here diff --git a/modules/lang/cc/packages.el b/modules/lang/cc/packages.el index 8906cb090..ead0e03c8 100644 --- a/modules/lang/cc/packages.el +++ b/modules/lang/cc/packages.el @@ -56,5 +56,4 @@ (when IS-MAC (sh (format "install_name_tool -change @rpath/libclang.dylib %s %s" "/usr/local/opt/llvm/lib/libclang.dylib" - (expand-file-name "bin/irony-server" irony-server-install-prefix))))) - t)) + (expand-file-name "bin/irony-server" irony-server-install-prefix))))))) diff --git a/modules/lang/go/packages.el b/modules/lang/go/packages.el index c841c1b5d..e72dc8d0d 100644 --- a/modules/lang/go/packages.el +++ b/modules/lang/go/packages.el @@ -32,5 +32,4 @@ '("github.com/nsf/gocode" "github.com/motemen/gore" "golang.org/x/tools/cmd/guru" - "golang.org/x/tools/cmd/gorename")) - (or changed (not gobin)))) + "golang.org/x/tools/cmd/gorename")))) diff --git a/modules/lang/javascript/packages.el b/modules/lang/javascript/packages.el index 06e55701b..6079601b1 100644 --- a/modules/lang/javascript/packages.el +++ b/modules/lang/javascript/packages.el @@ -17,25 +17,27 @@ (package! xref-js2)) ;; +(def-bootstrap! nodejs + (pcase (doom-system-os) + ('arch + (let (progs) + (unless (executable-find "node") (push "nodejs" progs)) + (unless (executable-find "npm") (push "npm" progs)) + (when progs + (sudo "pacman --noconfirm -S %s" progs)))) + ('debian) ;; TODO + ('macos + (unless (executable-find "node") + (sh "brew install node")))) + ;; return success + (unless (cl-every 'executable-find '("node" "npm")) + (error "Something went wrong installing NodeJS"))) + (def-bootstrap! javascript - (unless (cl-every 'executable-find '("node" "npm" "tern" "js-beautify" "eslint")) - (pcase (doom-system-os) - ('arch - (let (progs) - (unless (executable-find "node") (push "nodejs" progs)) - (unless (executable-find "npm") (push "npm" progs)) - (when progs - (sudo "pacman --noconfirm -S %s" progs)))) - ('debian) ;; TODO - ('macos - (unless (executable-find "node") - (sh "brew install node")))) - (unless (executable-find "node") - (error "Failed to install NodeJS")) - (unless (executable-find "tern") - (sh "npm -g install tern")) - (unless (executable-find "js-beautify") - (sh "npm -g install js-beautify")) - (unless (executable-find "eslint") - (sh "npm -g install eslint eslint-plugin-react")) - t)) + :requires nodejs + (unless (executable-find "tern") + (sh "npm -g install tern")) + (unless (executable-find "js-beautify") + (sh "npm -g install js-beautify")) + (unless (executable-find "eslint") + (sh "npm -g install eslint eslint-plugin-react"))) diff --git a/modules/lang/python/packages.el b/modules/lang/python/packages.el index 38e4486cf..42db3a7bc 100644 --- a/modules/lang/python/packages.el +++ b/modules/lang/python/packages.el @@ -20,5 +20,4 @@ (when-let (pkgs (cl-remove-if (lambda (pkg) (zerop (shell-command (format "pip show %s" pkg)))) '("jedi" "setuptools"))) - (sh "pip install %s" (s-join " " pkgs)) - t)) + (sh "pip install jedi setuptools"))) diff --git a/modules/lang/ruby/packages.el b/modules/lang/ruby/packages.el index 0a6c6f538..1d72cfc56 100644 --- a/modules/lang/ruby/packages.el +++ b/modules/lang/ruby/packages.el @@ -8,3 +8,15 @@ (when (featurep! :completion company) (package! company-inf-ruby)) + +;; +(def-bootstrap! ruby + ;; Since there are so many possible setups for a ruby environment (rbenv, rvm, + ;; etc), I'll leave it to you and only take care of installing gem + ;; dependencies. + (unless (executable-find "ruby") + (error "ruby isn't installed")) + (unless (executable-find "gem") + (error "gem isn't installed")) + (when-let (pkgs (cl-remove-if 'executable-find) '("ruby-lint"))) + (sh "gem install %s" (s-join " " pkgs))) diff --git a/modules/lang/rust/packages.el b/modules/lang/rust/packages.el index 723fedf3c..b192a40d4 100644 --- a/modules/lang/rust/packages.el +++ b/modules/lang/rust/packages.el @@ -23,19 +23,16 @@ ('macos (unless (executable-find "rustc") (sh "brew install rust")))) - (dolist (bin '("rustc" "cargo")) (unless (executable-find bin) (error "Failed to install %s" bin))) (require! :lang rust t) (require 'racer) - (and (unless (file-directory-p racer-rust-src-path) - (fetch :github "rust-lang/rust" (expand-file-name "rust" +rust-ext-dir)) - t) - (unless (file-executable-p racer-cmd) - (let ((racer-dir (expand-file-name "racer" +rust-ext-dir))) - (fetch :github "phildawes/racer" racer-dir) - (let ((default-directory racer-dir)) - (sh "cargo build --release")) - t)))) + (unless (file-directory-p racer-rust-src-path) + (fetch :github "rust-lang/rust" (expand-file-name "rust" +rust-ext-dir))) + (unless (file-executable-p racer-cmd) + (let ((racer-dir (expand-file-name "racer" +rust-ext-dir))) + (fetch :github "phildawes/racer" racer-dir) + (let ((default-directory racer-dir)) + (sh "cargo build --release"))))) diff --git a/modules/lang/sh/packages.el b/modules/lang/sh/packages.el index 664fad280..95c9f4700 100644 --- a/modules/lang/sh/packages.el +++ b/modules/lang/sh/packages.el @@ -14,5 +14,4 @@ ('debian (sudo "apt-get install -y %s" prog-str)) ('macos - (sh "brew install %s" prog-str)))) - t)) + (sh "brew install %s" prog-str)))))) diff --git a/modules/lang/web/packages.el b/modules/lang/web/packages.el index 28105098b..c707827a2 100644 --- a/modules/lang/web/packages.el +++ b/modules/lang/web/packages.el @@ -18,3 +18,10 @@ (package! sass-mode) (package! stylus-mode) +;; +(def-bootstrap! web + :requires nodejs + (unless (executable-find "js-beautify") + (sh "npm -g install js-beautify")) + (unless (executable-find "stylelint") + (sh "npm -g install stylelint stylelint-scss")))