From efbd53eb956d9e78164be13db768c97de2648538 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 18 Feb 2023 04:03:56 -0800 Subject: [PATCH] feat(DSL): Add package-descriptor (#124) * feat(DSL): Add package-descriptor * wip * add test * Fix ci * changelog * present more info --- .github/workflows/docs.yml | 6 +- CHANGELOG.md | 1 + docs/content/en/DSL/_index.md | 9 +++ lisp/_prepare.el | 112 +++++++++++++++++++++++----------- test/checker/dsl/Eask | 3 + 5 files changed, 94 insertions(+), 37 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 38e303c2..569155f4 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -24,7 +24,11 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - + + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Setup Hugo uses: peaceiris/actions-hugo@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d6f10a6..ea7611af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * fix: Also expose `bin` folder for symlink package (#115) * Resolve infinite recursion in `exec-path` setup (#118) * feat: Add capability to search through path (#119) +* Support DSL `package-descriptor` (#124) ## 0.7.x > Released Sep 08, 2022 diff --git a/docs/content/en/DSL/_index.md b/docs/content/en/DSL/_index.md index 1205ce7a..f9a573a3 100644 --- a/docs/content/en/DSL/_index.md +++ b/docs/content/en/DSL/_index.md @@ -47,6 +47,15 @@ of a file (used only for package development). (package-file "foo.el") ``` +## 🔍 **package-descriptor** (`pkg-file`) + +Declare all package metadata directly by specifying a package descriptor +contained in file with name given by file. + +```elisp +(package-descriptor "foo-pkg.el") +``` + ## 🔍 **files** (`&rest patterns`) Specify list of files that are included in this project. diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 33920456..8d4eb112 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -565,7 +565,7 @@ other scripts internally. See function `eask-call'.") (defconst eask-file-keywords '("package" "website-url" "keywords" - "package-file" "files" + "package-file" "package-descriptor" "files" "script" "source" "source-priority" "depends-on" "development" @@ -577,7 +577,7 @@ other scripts internally. See function `eask-call'.") for function `eask--alias-env'." (dolist (keyword eask-file-keywords) (let ((keyword-sym (intern keyword)) - (api (intern (concat "eask-f-" keyword))) ; existing function + (api (intern (concat "eask-f-" keyword))) ; existing function (old (intern (concat "eask--f-" keyword)))) ; variable that holds function pointer (funcall func keyword-sym api old)))) @@ -756,16 +756,17 @@ This uses function `locate-dominating-file' to look up directory tree." (shmelpa . "https://shmelpa.commandlinesystems.com/packages/")) "Mapping of source name and url.") -(defvar eask-package nil) -(defvar eask-package-desc nil) ; package descriptor -(defvar eask-website-url nil) -(defvar eask-keywords nil) -(defvar eask-package-file nil) -(defvar eask-files nil) -(defvar eask-scripts nil) -(defvar eask-depends-on-emacs nil) -(defvar eask-depends-on nil) -(defvar eask-depends-on-dev nil) +(defvar eask-package nil) +(defvar eask-package-desc nil) ; package descriptor +(defvar eask-package-descriptor nil) +(defvar eask-website-url nil) +(defvar eask-keywords nil) +(defvar eask-package-file nil) +(defvar eask-files nil) +(defvar eask-scripts nil) +(defvar eask-depends-on-emacs nil) +(defvar eask-depends-on nil) +(defvar eask-depends-on-dev nil) (defmacro eask--save-eask-file-state (&rest body) "Execute BODY without touching the Eask-file global variables." @@ -777,6 +778,7 @@ This uses function `locate-dominating-file' to look up directory tree." eask-website-url eask-keywords eask-package-file + eask-package-descriptor eask-files eask-scripts eask-depends-on-emacs @@ -823,37 +825,66 @@ This uses function `locate-dominating-file' to look up directory tree." (setq eask-website-url url))) (defun eask-f-keywords (&rest keywords) - "Set package keywords." + "Set package KEYWORDS." (if eask-keywords (eask-error "Multiple definition of `keywords'") (setq eask-keywords keywords))) +(defun eask--try-construct-package-desc (file) + "Try construct the package descriptor from FILE." + (let (skipped) + (with-temp-buffer + (insert-file-contents file) + (setq eask-package-desc + (ignore-errors + (cond ((string-suffix-p "-pkg.el" file) ; if ensure -pkg.el + (package--read-pkg-desc 'dir)) + ((eask-pkg-el) ; if -pkg.el is presented, + (setq skipped t) nil) ; skip it + (t (package-buffer-info)))))) ; default read main package file + (eask-msg (concat + (if eask-package-desc "✓ " "✗ ") + "Try constructing the package-descriptor (%s)... " + (cond (eask-package-desc "succeeded!") + (skipped "skipped!") + (t "failed!"))) + (file-name-nondirectory file)))) + (defun eask-f-package-file (file) - "Set package file." + "Set package FILE." (if eask-package-file (eask-error "Multiple definition of `package-file'") (setq eask-package-file (expand-file-name file)) - (let* ((package-file-exists (file-exists-p eask-package-file)) - (def-point (if (eask-pkg-el) "-pkg.el file" "package-file")) - (target-file (cond ((eask-pkg-el) (expand-file-name (eask-pkg-el))) - (package-file-exists eask-package-file)))) - (unless package-file-exists - (eask-warn "Package-file seems to be missing `%s'" file)) - (when target-file - (with-temp-buffer - (insert-file-contents target-file) - (setq eask-package-desc (ignore-errors - (if (eask-pkg-el) - (package--read-pkg-desc 'dir) - (package-buffer-info))))) - (eask-msg (concat - (if eask-package-desc "✓ " "✗ ") - "Try constructing the package-descriptor (%s)... " - (if eask-package-desc "succeeded! " "failed!")) - (file-name-nondirectory target-file)))))) + (if (file-exists-p eask-package-file) + (eask--try-construct-package-desc eask-package-file) + (eask-warn "Package-file seems to be missing `%s'" file)) + (when-let + (((and (not eask-package-descriptor) ; prevent multiple definition error + (not eask-package-desc))) ; check if constructed + (pkg-file (eask-pkg-el))) + (eask-f-package-descriptor pkg-file) + ;; XXX: Make sure DSL package descriptor is set back to `nil' + (setq eask-package-descriptor nil)))) + +(defun eask-f-package-descriptor (pkg-file) + "Set package PKG-FILE." + (cond + (eask-package-descriptor + (eask-error "Multiple definition of `package-descriptor'")) + ((and eask-package-desc ; check if construct successfully + (equal (eask-pkg-el) pkg-file)) ; check filename the same + ) ; ignore + (t + (setq eask-package-descriptor (expand-file-name pkg-file)) + (cond ((not (string-suffix-p "-pkg.el" eask-package-descriptor)) + (eask-error "Pkg-file must end with `-pkg.el'")) + ((not (file-exists-p eask-package-descriptor)) + (eask-warn "Pkg-file seems to be missing `%s'" pkg-file)) + (t + (eask--try-construct-package-desc eask-package-descriptor)))))) (defun eask-f-files (&rest patterns) - "Set files patterns." + "Set files PATTERNS." (setq eask-files (append eask-files patterns))) (defun eask-f-script (name command &rest args) @@ -1291,7 +1322,11 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)." (eask--check-optional eask-website-url url "Unmatched website URL '%s'; it should be '%s'" - (format "Unmatched website URL '%s'; add ;; URL: %s to %s" eask-website-url eask-website-url def-point) + (format "Unmatched website URL '%s'; add %s to %s" eask-website-url + (if (string-prefix-p "-pkg.el" def-point) + (format ":url \"%s\"" eask-website-url) + (format ";; URL: %s" eask-website-url)) + def-point) (format "Unmatched website URL '%s'; add (website-url \"%s\") to Eask-file" url url) (format "URL header is optional, but it's often recommended"))) (let ((keywords (eask-package-desc-keywords))) @@ -1299,10 +1334,15 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)." ((or keywords eask-keywords) (dolist (keyword keywords) (unless (member keyword eask-keywords) - (eask-warn "Unmatched keyword '%s'; add (keywords ... \"%s\") to Eask-file or consider removing it" keyword keyword))) + (eask-warn "Unmatched keyword '%s'; add (keywords \"%s\") to Eask-file or consider removing it" keyword keyword))) (dolist (keyword eask-keywords) (unless (member keyword keywords) - (eask-warn "Unmatched keyword '%s'; add ;; Keywords ... %s to %s or consider removing it" keyword keyword def-point)))) + (eask-warn "Unmatched keyword '%s'; add %s to %s or consider removing it" + keyword + (if (string-prefix-p "-pkg.el" def-point) + (format ":keywords '(\"%s\")" keyword) + (format ";; Keywords: %s" keyword)) + def-point)))) (t (eask-warn "Keywords header is optional, but it's often recommended")))) (let* ((dependencies (append eask-depends-on-emacs eask-depends-on)) diff --git a/test/checker/dsl/Eask b/test/checker/dsl/Eask index 9b9129e9..373bdbe1 100644 --- a/test/checker/dsl/Eask +++ b/test/checker/dsl/Eask @@ -14,6 +14,9 @@ (package-file "check-dsl.el") ; duplicate `package-file` directive (package-file "check-dsl.el") +(package-descriptor "check-pkg.el") ; duplicate `package-descriptor` directive +(package-descriptor "check-pkg.el") + ;; duplicate scripts (script "test" "echo \"Error: no test specified\" && exit 1") (script "test" "echo \"Error: no test specified\" && exit 1")