diff --git a/.doom b/.doom index e7485f033..a068657fe 100644 --- a/.doom +++ b/.doom @@ -26,12 +26,13 @@ (make (".github/CODEOWNERS" - "# Auto-generated by 'doom make .github/CODEOWNERS', do not edit it by hand.") - "*\t@doomemacs/maintainers" ; default until another takes precedence + "# Auto-generated by 'doom make .github/CODEOWNERS', do not edit it by hand.\n" + "* @doomemacs/maintainers\n" ; default until another takes precedence + "# Module maintainers" ,@(cl-sort (cl-loop for path in (doom-module-load-path (list doom-modules-dir)) if (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)$" path) - collect (format "%s\t@doomemacs/%s-%s" + collect (format "%-35s @doomemacs/%s-%s" (substring (match-string 0 path) 1) (match-string 1 path) (match-string 2 path))) diff --git a/lisp/cli/make.el b/lisp/cli/make.el index a7a5c657a..917460de3 100644 --- a/lisp/cli/make.el +++ b/lisp/cli/make.el @@ -10,62 +10,37 @@ ;; ;;; Variables -(defvar doom-make-codeowners-file ".github/CODEOWNERS" - "Where to write the CODEOWNERS file, relative to the repo's toplevel.") - -(defvar doom-make-codeowners () - "An alist of codeowners for this project. - -Each entry can either be a string (inserted verbatim, surrounded by newlines) or -a pair of strings (in a cons cell) consisting of: (GLOB . CODEOWNERS). - -The contents of this variable are inserted in reverse.") ;; ;;; Commands -(defcli! make () - "(Re)Generate project files and boilerplate." - :partial t) - -(defcli! (make codeowners) - ((outfile ("-o" "--file" (file stdout)) "Where to write the codeowners file") - (dryrun? ("--dryrun"))) - "Generate (or update) a CODEOWNERS file. - -By default, this means $GIT_WORK_TREE/.github/CODEOWNERS. This will throw an -error if not run in a Git repo. - -OPTIONS: - -o, --file - Pass this option a dash to print the codeowners file to stdout." +(defcli! make + ((dryrun? ("--dryrun")) + (output ("-o" "--output" path)) + &args targets) + "Run make targets (defined in .doom)." (when dryrun? - (setq outfile "-") - (print! (warn "Running dry run; will only print to stdout:"))) - (with-temp-buffer - (let ((codeowners-file - (cond ((equal outfile "-") nil) - (outfile (expand-file-name outfile)) - ((file-name-concat (doom-git-toplevel) doom-make-codeowners-file))))) - (insert "# -*- mode: conf -*-\n" - "# Each line is a file pattern followed by one or more owners.\n" - "# This file was generated by 'doom make codeowners', do not edit it by hand.\n") - (dolist (entry (nreverse doom-make-codeowners)) - (if (stringp entry) - (insert "\n" entry "\n") - (insert (format "%-35s %s" (car entry) (cdr entry)) "\n"))) - (insert "\n# End of CODEOWNERS") - (setq indent-tabs-mode nil) ; align w/ spaces, not tabs - (align-regexp (point-min) (point-max) "/\\(\\s-+\\)@" 1) - (if (null codeowners-file) - (print! "%s" (buffer-string)) - (print! (start "%s codeowners file at: %s") - (if (file-exists-p codeowners-file) - "Regenerated" - "Generated") - (relpath codeowners-file)) - (write-region (buffer-string) nil codeowners-file))))) + (print! (warn "Running dry run"))) + (let* ((root (doom-git-toplevel)) + (rc (doom-rcfile-read `(project make) root))) + (dolist (target targets) + (with-temp-buffer + (let* ((outfile + (unless (equal output "-") + (expand-file-name target))) + (name (file-relative-name (file-truename target) root)) + (rule (assoc name rc))) + (if (null rule) + (print! (warn "No known make rule for: %s" name)) + (dolist (entry rule) + (when (stringp entry) + (insert entry "\n"))) + (if (null outfile) + (print! "%s --" (buffer-string)) + (print! (start "Wrote %s") name) + (unless dryrun? + (write-region (buffer-string) nil outfile))))))))) ;; TODO Finish me (defcli-stub! (make changelog))