# opkbuild
# lib/deps
# Functions for parsing dependency field values.
#
# Copyright (C) 2012 Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
[ -n "${_OB_DEPS_SM}" ] && return 0
_OB_DEPS_SM='true'
ob_use metadata
ob_parse_dep()
{
local opt=
local pkg_var=
local archqual_var=
local rel_var=
local ver_var=
local arches_var=
local plats_var=
local host_arch=
local host_plat=
local dep=
local pkgarchqual=
local pkg=
local archqual=
local relver=
local rel=
local ver=
local arches=
local plats=
local comp=
local comp_var=
while getopts 'p:q:r:v:A:l:a:P:' opt; do
case "${opt}" in
p)
pkg_var="${OPTARG}"
if ! _ob_validate_var_name "${pkg_var}"; then
return 125
fi
;;
q)
archqual_var="${OPTARG}"
if ! _ob_validate_var_name "${archqual_var}"; then
return 125
fi
;;
r)
rel_var="${OPTARG}"
if ! _ob_validate_var_name "${rel_var}"; then
return 125
fi
;;
v)
ver_var="${OPTARG}"
if ! _ob_validate_var_name "${ver_var}"; then
return 125
fi
;;
A)
arches_var="${OPTARG}"
if ! _ob_validate_var_name "${arches_var}"; then
return 125
fi
;;
l)
plats_var="${OPTARG}"
if ! _ob_validate_var_name "${plats_var}"; then
return 125
fi
;;
a)
host_arch="${OPTARG}"
;;
P)
host_plat="${OPTARG}"
;;
?)
return 125
;;
esac
done
shift $(($OPTIND - 1))
if [ ${#} -eq 1 ]; then
dep="$(printf '%s\n' "${1}" | sed -n '
H; # Store each input line in the hold space.
${
g; # Restore everything to the pattern space.
s/[\t\n]/ /g; # Replace tabs and newlines with spaces.
s/ *\([(\[<]\) */ \1/g; # One space before "(", "[", and "<".
s/ *\([)\]>]\) */\1 /g; # One space after "(", "[", and "<".
s/ *\(<[<=]\) */\1 /g; # One space after "<<" and "<=".
s/ *\(>[>=]\) */\1 /g; # One space after ">>" and ">=".
s/ *\(=\) */\1 /g; # One space after "=".
s/^ *//; # Remove leading spaces.
s/ *$//; # Remove trailing spaces.
s/ */ /g; # Remove duplicate spaces.
p; # Print the pattern space.
};
')"
else
return 125
fi
# pkg[:archqual] [(rel ver)] [\[arches\]] []
pkgarchqual="${dep%% *}"
dep=" ${dep#* }"
pkg="${pkgarchqual%:*}"
if [ "${pkg}" != "${pkgarchqual}" ]; then
archqual="${pkgarchqual##*:}"
fi
if [ "${dep# (*)}" != "${dep}" ]; then
relver="${dep# (}"
relver="${relver%%)*}"
dep="${dep# (*)}"
rel="${relver% *}"
ver="${relver##* }"
fi
if [ "${dep# \[*\]}" != "${dep}" ]; then
arches="${dep# \[}"
arches="${arches%%\]*}"
dep="${dep# \[*\]}"
fi
if [ "${dep# <*>}" != "${dep}" ]; then
plats="${dep# <}"
plats="${plats%%>*}"
dep="${dep# <*>}"
fi
# Set the specified variables.
for comp in pkg archqual rel ver arches plats; do
comp_var="$(eval echo \"\$\{${comp}_var\}\")"
[ -z "${comp_var}" ] && continue
eval ${comp_var}=\"\$\{${comp}\}\"
done
if [ -n "${host_arch}" ] && ! ob_arch_is_concerned \
"${host_arch}" "${arches}"; then
return 0
fi
if [ -n "${host_plat}" ] && ! ob_plat_is_concerned \
"${host_plat}" "${plats}"; then
return 0
fi
printf '%s' "${pkg}"
[ -n "${archqual}" ] && printf ':%s' "${archqual}"
[ -n "${ver}" ] && printf ' (%s %s)' "${rel}" "${ver}"
[ -z "${host_arch}" -a -n "${arches}" ] && \
printf ' [%s]' "${arches}"
[ -z "${host_plat}" -a -n "${plats}" ] && \
printf ' [%s]' "${plats}"
printf '\n'
return 0
}
ob_reduce_deps()
{
local opt=
local host_arch=
local host_plat=
local deps=
local dep_and=
local dep_or=
local dep_list=
local dep_or_list=
local dep=
union='false'
while getopts 'a:P:u' opt; do
case "${opt}" in
a)
host_arch="${OPTARG}"
;;
P)
host_plat="${OPTARG}"
;;
u)
union='true'
;;
?)
return 125
;;
esac
done
shift $(($OPTIND - 1))
if [ ${#} -eq 1 ]; then
deps="${1}"
else
return 125
fi
IFS=','
for dep_and in ${deps}; do
unset IFS
if ! ${union}; then
IFS='|'
dep_or_list=
for dep_or in ${dep_and}; do
unset IFS
dep="$(ob_parse_dep -a "${host_arch}" \
-P "${host_plat}" "${dep_or}")"
if [ -n "${dep}" ]; then
if [ -n "${dep_or_list}" ]; then
dep_or_list="${dep_or_list} | "
fi
dep_or_list="${dep_or_list}${dep}"
fi
done
if [ -n "${dep_or_list}" ]; then
if [ -n "${dep_list}" ]; then
dep_list="${dep_list}, "
fi
dep_list="${dep_list}${dep_or_list}"
fi
else
dep="$(ob_parse_dep -a "${host_arch}" \
-P "${host_plat}" "${dep_and}")"
if [ -n "${dep}" ]; then
if [ -n "${dep_list}" ]; then
dep_list="${dep_list}, "
fi
dep_list="${dep_list}${dep}"
fi
fi
done
unset IFS
echo "${dep_list}"
return 0
}