From 5c23af6d0bbe09650b71a98953e9c78eeaf4c8bf Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sun, 15 Sep 2024 23:04:07 +0200 Subject: [PATCH] Improve detection of release tags - 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. --- package-build.el | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/package-build.el b/package-build.el index 221bd2f..e687bd9 100644 --- a/package-build.el +++ b/package-build.el @@ -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." @@ -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)) @@ -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)) @@ -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))