Skip to content

Commit

Permalink
Improve detection of release tags
Browse files Browse the repository at this point in the history
- Support more commonly used prefixes namely "release" and the name of
  the package.  These prefixes must be separated from the version with
  either "-" or "/".  These separators may optionally be follow by an
  additional prefix "v", which is odd but not completely bonkers.

- If a package-specific version regexp contains "%v",
  "\\(?1:[0-9]+\\(\\.[0-9]+\\)*\\)" is substituted for that.
  Previously all such instances didn't bother and just used the much
  less precise "\\(.+\\)".

- If a package-specific version regexp does not begin with "\\`", then
  add that.  Likewise if it does not end with "\\'", then add that.
  While some instances were properly anchored before, many more were
  not.  This ensures they are, without recipe authors having to worry
  about it.
  • Loading branch information
tarsius committed Sep 15, 2024
1 parent c0d8e63 commit 5c23af6
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions package-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,21 @@ channel that is being build."
:type '(list (string :tag "Archive name") color))

(defcustom package-build-version-regexp
"\\`[rRvV]?\\(?1:[0-9]+\\(\\.[0-9]+\\)*\\)\\'"
"\\`\\(?:\\|[vVrR]\\|\\(?:release\\|%p\\)[-/]v?\\)?\
\\(?1:[0-9]+\\(\\.[0-9]+\\)*\\)\\'"
"Regexp used to match valid version-strings.
The first capture is used to extract the actual version string.
Strings matched by that group must be valid according to
`version-to-list', but the used regexp can be more strict. The
default value supports only releases but no pre-releases. It
also intentionally ignores cedrtain unfortunate version strings
The first capture group is used to extract the actual version
string. Strings matched by that group must be valid according
to `version-to-list', but the used regexp can be more strict.
The default value supports only releases but no pre-releases.
It also intentionally ignores certain unfortunate version strings
such as \"1A\" or \".5\", and only supports \".\" as separator.
The part before the first capture group should match prefixes
commonly used in version tags.
commonly used in version tags. To support tags that contain
the name package of the package (e.g., \"foobar-0.1.3\"), the
name of the package is substituted for \"%p\".
Note that this variable can be overridden in a package's recipe,
using the `:version-regexp' slot."
Expand Down Expand Up @@ -342,6 +345,15 @@ being run for a particular package."
;;; Version Handling
;;;; Common

(defun package-build--version-regexp (rcp)
"Return the version regexp for RCP."
(if-let* ((re (oref rcp version-regexp))
(re (format-spec re '((?v . "\\(?1:[0-9]+\\(\\.[0-9]+\\)*\\)")))))
(progn (unless (string-prefix-p "\\`" re) (setq re (concat "\\`" re)))
(unless (string-suffix-p "\\'" re) (setq re (concat re "\\'")))
re)
(format-spec package-build-version-regexp `((?p . ,(oref rcp name))))))

(defun package-build--select-version (rcp)
(pcase-let*
((default-directory (package-recipe--working-tree rcp))
Expand Down Expand Up @@ -401,7 +413,7 @@ or snapshots are build.")
(defun package-build-tag-version (rcp)
"Determine version corresponding to largest version tag for RCP.
Return (COMMIT-HASH COMMITTER-DATE VERSION-STRING)."
(let ((regexp (or (oref rcp version-regexp) package-build-version-regexp))
(let ((regexp (package-build--version-regexp rcp))
(tag nil)
(version '(0)))
(dolist (n (package-build--list-tags rcp))
Expand Down Expand Up @@ -499,7 +511,7 @@ Return (COMMIT-HASH COMMITTER-DATE VERSION-STRING)."
"Return version specified in the \"NAME-pkg.el\" file.
Return (COMMIT-HASH COMMITTER-DATE VERSION-STRING)."
(and-let* ((file (package-build--pkgfile rcp)))
(let ((regexp (or (oref rcp version-regexp) package-build-version-regexp))
(let ((regexp (package-build--version-regexp rcp))
commit date version)
(catch 'before-latest
(pcase-dolist (`(,c ,d) (package-build--pkgfile-commits rcp file))
Expand Down

0 comments on commit 5c23af6

Please sign in to comment.