Compare commits

...

2 Commits

Author SHA1 Message Date
Vekhir --
00df744eb2 Merge branch 'fix-pkgrel-pkgver-match' into 'master'
fix(pkgbuild.sh): Use grep -Fx to check for pkgrel and pkgver declaration

Closes #242

See merge request archlinux/devtools!283
2025-08-20 12:58:34 +00:00
Vekhir
6dd555ed1f fix(pkgbuild.sh): Use grep -Fx to check for pkgrel and pkgver declaration
In order to automatically replace pkgrel and pkgver, we must first check
that they are declared in the usual way as a key-value pair.
If pkgrel or pkgver contain special characters like +, they are currently
interpreted as regex. Use --fixed-strings to instead signify that they should
be literal patterns. Since the declaration must be on its own line and anchors
can't be in literal patterns, also specify --line-regexp to only consider
whole line matches.

Using sed with --extended-regexp fails for a similar reason in that the +
is treated as a special character. As it's only use was to save some
typing (not repeating pkgver= and pkgrel=), remove the option.
2025-08-20 14:55:32 +02:00

View File

@@ -26,10 +26,10 @@ pkgbuild_set_pkgver() {
warning 'setting pkgver variable has no effect if the PKGBUILD has a pkgver() function'
fi
if ! grep --extended-regexp --quiet --max-count=1 "^pkgver=${pkgver}$" PKGBUILD; then
if ! grep --fixed-strings --line-regexp --quiet --max-count=1 "pkgver=${pkgver}" PKGBUILD; then
die "Non-standard pkgver declaration"
fi
sed --regexp-extended "s|^(pkgver=)${pkgver}$|\1${new_pkgver}|g" --in-place PKGBUILD
sed "s|^pkgver=${pkgver}$|pkgver=${new_pkgver}|g" --in-place PKGBUILD
}
# set the pkgrel variable in a PKGBUILD
@@ -38,10 +38,10 @@ pkgbuild_set_pkgrel() {
local new_pkgrel=$1
local pkgrel=${pkgrel}
if ! grep --extended-regexp --quiet --max-count=1 "^pkgrel=${pkgrel}$" PKGBUILD; then
if ! grep --fixed-strings --line-regexp --quiet --max-count=1 "pkgrel=${pkgrel}" PKGBUILD; then
die "Non-standard pkgrel declaration"
fi
sed --regexp-extended "s|^(pkgrel=)${pkgrel}$|\1${new_pkgrel}|g" --in-place PKGBUILD
sed "s|^pkgrel=${pkgrel}$|pkgrel=${new_pkgrel}|g" --in-place PKGBUILD
}
pkgbuild_update_checksums() {