Skip to content

Commit

Permalink
feat(DSL): Add package-descriptor (#124)
Browse files Browse the repository at this point in the history
* feat(DSL): Add package-descriptor

* wip

* add test

* Fix ci

* changelog

* present more info
  • Loading branch information
jcs090218 authored Feb 18, 2023
1 parent cfc439d commit efbd53e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 37 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/content/en/DSL/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
112 changes: 76 additions & 36 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))))

Expand Down Expand Up @@ -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."
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1291,18 +1322,27 @@ 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)))
(cond
((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))
Expand Down
3 changes: 3 additions & 0 deletions test/checker/dsl/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit efbd53e

Please sign in to comment.