kiss: support escaping markers in sources files.

VERSION  -> resolved version
\VERSION -> VERSION

This allows users to disable substitution of specific markers
while keeping others functional.

Example (URL contains literal RELEASE):

https://github.com/jedisct1/libsodium/releases/download/VERSION-\RELEASE/libsodium-VERSION.tar.gz
This commit is contained in:
Dylan Araps 2021-07-20 12:08:31 +03:00
parent 3be01d38a6
commit 83c88b4222
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C

19
kiss
View File

@ -105,7 +105,6 @@ fnr() {
shift 1 shift 1
while :; do case $_fnr-$# in while :; do case $_fnr-$# in
raw:*) _fnr=${_fnr##raw:}; break ;;
*"$1"*) _fnr=${_fnr%"$1"*}${2}${_fnr##*"$1"} ;; *"$1"*) _fnr=${_fnr%"$1"*}${2}${_fnr##*"$1"} ;;
*-2) break ;; *-2) break ;;
*) shift 2 *) shift 2
@ -333,14 +332,18 @@ pkg_source_resolve() {
# path to the source if it already exists, error if not. # path to the source if it already exists, error if not.
ok "${2##\#*}" || { _res=; return; } ok "${2##\#*}" || { _res=; return; }
# Surround each replacement with substitutions to handled escaped markers.
# First substitution turns '\MARKER' into ' ' (can't appear in sources as
# they're already split on whitespace), second replaces 'MARKER' with its
# value and the third, turns ' ' into 'MARKER' (dropping \\).
fnr "${2%"${2##*[!/]}"}" \ fnr "${2%"${2##*[!/]}"}" \
VERSION "$repo_ver" \ \\VERSION \ VERSION "$repo_ver" \ VERSION \
RELEASE "$repo_rel" \ \\RELEASE \ RELEASE "$repo_rel" \ RELEASE \
MAJOR "$repo_major" \ \\MAJOR \ MAJOR "$repo_major" \ MAJOR \
MINOR "$repo_minor" \ \\MINOR \ MINOR "$repo_minor" \ MINOR \
PATCH "$repo_patch" \ \\PATCH \ PATCH "$repo_patch" \ PATCH \
IDENT "$repo_ident" \ \\IDENT \ IDENT "$repo_ident" \ IDENT \
PACKAGE "$repo_name" \\PACKAGE \ PACKAGE "$repo_name" \ PACKAGE
set -- "$1" "$_fnr" "${3%"${3##*[!/]}"}" "$4" set -- "$1" "$_fnr" "${3%"${3##*[!/]}"}" "$4"