From 498d88ba9bc5941ad95ff006a74b2021e294447f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 19 Jun 2022 01:29:40 +0200 Subject: [PATCH] feat(cli): add -j/--jobs NUM options To 'doom sync', 'doom upgrade', and 'doom build'. So users can decide whether they want Doom 100%'ing their CPUs. After 3.0, many of these commands will be merged, so a little code duplication is fine for now. --- core/cli/packages.el | 5 ++++- core/cli/sync.el | 12 ++++++++++-- core/cli/upgrade.el | 7 +++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/cli/packages.el b/core/cli/packages.el index 4f78d64f5..70bb77d28 100644 --- a/core/cli/packages.el +++ b/core/cli/packages.el @@ -17,12 +17,15 @@ ;; DEPRECATED Replace with "doom sync --rebuild" (defcli! ((build b)) - ((rebuild-p ("-r") "Only rebuild packages that need rebuilding")) + ((rebuild-p ("-r") "Only rebuild packages that need rebuilding") + (jobs ("-j" "--jobs" num) "How many CPUs to use for native compilation")) "Byte-compiles & symlinks installed packages. This ensures that all needed files are symlinked from their package repo and their elisp files are byte-compiled. This is especially necessary if you upgrade Emacs (as byte-code is generally not forward-compatible)." + (when jobs + (setq native-comp-async-jobs-number (truncate jobs))) (when (doom-packages-build (not rebuild-p)) (doom-autoloads-reload)) t) diff --git a/core/cli/sync.el b/core/cli/sync.el index b9d3f4b07..9db881846 100644 --- a/core/cli/sync.el +++ b/core/cli/sync.el @@ -24,7 +24,8 @@ ((noenvvar? ("-e") "Don't regenerate the envvar file") (noelc? ("-c") "Don't recompile config") (update? ("-u") "Update installed packages after syncing") - (purge? ("-p") "Purge orphaned package repos & regraft them")) + (purge? ("-p") "Purge orphaned package repos & regraft them") + (jobs ("-j" "--jobs" num) "How many CPUs to use for native compilation")) "Synchronize your config with Doom Emacs. This is the equivalent of running autoremove, install, autoloads, then @@ -37,10 +38,17 @@ recompile. Run this whenever you: It will ensure that unneeded packages are removed, all needed packages are installed, autoloads files are up-to-date and no byte-compiled files have gone -stale." +stale. + +OPTIONS: + -j, --jobs + Defaults to the maximum number of threads (or 1, if your CPU's threadcount + can't be determined)." :benchmark t (run-hooks 'doom-before-sync-hook) (add-hook 'kill-emacs-hook #'doom-sync--abort-warning-h) + (when jobs + (setq native-comp-async-jobs-number (truncate jobs))) (print! (start "Synchronizing your config with Doom Emacs...")) (unwind-protect (print-group! diff --git a/core/cli/upgrade.el b/core/cli/upgrade.el index dce0119d0..d0b2ffdba 100644 --- a/core/cli/upgrade.el +++ b/core/cli/upgrade.el @@ -20,6 +20,7 @@ (defcli! ((upgrade up)) ((packages? ("-p" "--packages") "Only upgrade packages, not Doom") + (jobs ("-j" "--jobs" num) "How many CPUs to use for native compilation") &context context) "Updates Doom and packages. @@ -31,7 +32,7 @@ following shell commands: doom clean doom sync -u" (let* ((force? (doom-cli-context-suppress-prompts-p context)) - (sync-cmd '("sync" "-u"))) + (sync-cmd (append '("sync" "-u") (if jobs `("-j" ,num))))) (cond (packages? (call! sync-cmd) @@ -41,7 +42,9 @@ following shell commands: ;; Reload Doom's CLI & libraries, in case there were any upstream changes. ;; Major changes will still break, however (print! (item "Reloading Doom Emacs")) - (exit! "doom" "upgrade" "-p" (if force? "--force"))) + (exit! "doom" "upgrade" "-p" + (if force? "--force") + (if jobs (format "--jobs=%d" jobs)))) ((print! "Doom is up-to-date!") (call! sync-cmd)))))