dkbuild: ajout de from_glob()

This commit is contained in:
Jephté Clain 2023-01-07 14:06:27 +04:00
parent 2293239614
commit 027f9b8c45
1 changed files with 28 additions and 0 deletions

28
dkbuild
View File

@ -1108,6 +1108,34 @@ function load_environ() {
eval "$(declare -p -x | sed -r 's/^declare -x ([^=]+)=/_ENVIRON[\1]=/')" eval "$(declare -p -x | sed -r 's/^declare -x ([^=]+)=/_ENVIRON[\1]=/')"
} }
function from_glob() {
local var=value value
[[ "$1" != *=* ]] && { var="$1"; shift; }
local path extract add_prefix add_suffix
while [ $# -gt 0 ]; do
case "$1" in
path=*) path="${1#path=}";;
extract=*) extract="${1#extract=}";;
add-prefix=*) add_prefix="${1#add-prefix=}";;
add-suffix=*) add_suffix="${1#add-suffix=}";;
*=*) ewarn "path: $1: argument ignoré";;
*) break;;
esac
shift
done
value="$(list_all . "$path" | sort -rn | head -1)"
[ -n "$extract" ] || extract="${path//\*/(.*)}"
if [ -n "$extract" ]; then
extract="${extract//\//\\/}"
value="$add_prefix$(awk -v version="$value" "BEGIN {
if (match(version, /$extract/, vs)) { print vs[1] }
else { print version }
}")$add_suffix"
fi
local "$var"; upvar "$var" "$value"
}
function define_functions_env() { function define_functions_env() {
function setversion() { function setversion() {
[ -n "$SETVERSION_DONE" ] && return [ -n "$SETVERSION_DONE" ] && return