aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Bo ├śrsted Andresen <bo.andresen@zlin.dk> 2009-02-10 10:19:39 +0100
committerAvatar Bo ├śrsted Andresen <bo.andresen@zlin.dk> 2009-02-11 21:37:58 +0100
commit1098fbd8cc2de00ace465a1d9679b1020b057f7f (patch)
tree3b2cbe151eeccaeb630cb66c69510321aae6ed76
parent56373094bb2cf6ae8f2d664c57b8ede3fca498d0 (diff)
downloadpaludis-1098fbd8cc2de00ace465a1d9679b1020b057f7f.tar.gz
paludis-1098fbd8cc2de00ace465a1d9679b1020b057f7f.tar.xz
Declare explicitly if we want a scalar or an array with myexparam.
-rw-r--r--paludis/repositories/e/e_repository_TEST_exlibs.cc2
-rwxr-xr-xpaludis/repositories/e/e_repository_TEST_exlibs_setup.sh28
-rw-r--r--paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash42
3 files changed, 57 insertions, 15 deletions
diff --git a/paludis/repositories/e/e_repository_TEST_exlibs.cc b/paludis/repositories/e/e_repository_TEST_exlibs.cc
index 4c6e31a..8ac1b8a 100644
--- a/paludis/repositories/e/e_repository_TEST_exlibs.cc
+++ b/paludis/repositories/e/e_repository_TEST_exlibs.cc
@@ -176,5 +176,7 @@ namespace test_cases
ExlibsTest test_exarray_default_spaces("exarray-default-spaces", success);
ExlibsTest test_noarray("noarray", success);
ExlibsTest test_noarray_bad("noarray-bad", throws_UnsupportedActionError);
+ ExlibsTest test_scalar_required("scalar-required", throws_UnsupportedActionError);
+ ExlibsTest test_array_required("array-required", throws_UnsupportedActionError);
}
diff --git a/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh b/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh
index 4b1d53a..b25158b 100755
--- a/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh
+++ b/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh
@@ -207,7 +207,7 @@ pkg_setup() {
END
mkdir -p "packages/cat/exarray"
cat <<'END' > packages/cat/exarray/foo.exlib || exit 1
-myexparam bar
+myexparam bar[]
check_foo() {
exparam bar[#] | grep -q ^3$ || die "Bad bar[#]"
@@ -233,7 +233,7 @@ pkg_setup() {
END
mkdir -p "packages/cat/exarray-spaces"
cat <<'END' > packages/cat/exarray-spaces/foo.exlib || exit 1
-myexparam bar
+myexparam bar[]
check_foo() {
exparam bar[#] | grep -q ^3$ || die "Bad bar[#]"
@@ -333,6 +333,30 @@ pkg_setup() {
[[ ${SUMMARY} == "[" ]] || die "Bad SUMMARY"
}
END
+mkdir -p "packages/cat/scalar-required"
+cat <<'END' > packages/cat/scalar-required/foo.exlib || exit 1
+myexparam bar
+SUMMARY=$(exparam bar)
+END
+cat <<'END' > packages/cat/scalar-required/scalar-required-1.ebuild || exit 1
+require foo [ bar=[ baz ] ]
+
+pkg_setup() {
+ [[ ${SUMMARY} == "baz" ]] || die "Bad SUMMARY"
+}
+END
+mkdir -p "packages/cat/array-required"
+cat <<'END' > packages/cat/array-required/foo.exlib || exit 1
+myexparam bar[]
+SUMMARY=$(exparam bar)
+END
+cat <<'END' > packages/cat/array-required/array-required-1.ebuild || exit 1
+require foo [ bar=baz ]
+
+pkg_setup() {
+ [[ ${SUMMARY} == "baz" ]] || die "Bad SUMMARY"
+}
+END
cd ..
cd ..
diff --git a/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash b/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash
index 9d09b2e..571fd57 100644
--- a/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash
+++ b/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash
@@ -43,9 +43,9 @@ exparam_var_name()
exparam_internal()
{
local v=$(exparam_var_name ${1})__ALLDECLS__
- has ${2%\[*} ${!v} || die "${1}.exlib has no ${2%\[*} parameter"
if [[ ${2} == *\[*\] ]]; then
[[ ${#} -eq 2 ]] || die "exparam with an index requires exactly one argument"
+ has "${2%\[*}[]" ${!v} || die "${1}.exlib has no ${2%\[*} array"
v=$(exparam_var_name ${1})_${2%\[*}
local i=${2%\]}
i=${i#*\[}
@@ -60,6 +60,11 @@ exparam_internal()
fi
else
[[ ${#} -eq 2 || ${#} -eq 3 ]] || die "exparam requires exactly one or two arguments"
+ if [[ ${#} -eq 3 ]]; then
+ has "${2%\[*}[]" ${!v} || die "${1}.exlib has no ${2%\[*} array"
+ else
+ has ${2%\[*} ${!v} || die "${1}.exlib has no ${2%\[*} parameter"
+ fi
v=$(exparam_var_name ${1})_${2}
if [[ -n ${3} ]]; then
eval "${3}=( \"\${${v}[@]}\" )"
@@ -73,10 +78,11 @@ myexparam()
{
[[ -z "${CURRENT_EXLIB}" ]] && die "myexparam called but CURRENT_EXLIB undefined"
- local v="$(exparam_var_name ${CURRENT_EXLIB})__ALLDECLS__"
- printf -v "${v}" "%s %s" "${!v}" "${1%%=*}"
+ local v=${1%%=*} a_v="$(exparam_var_name ${CURRENT_EXLIB})__ALLDECLS__"
+ [[ ${1} == *=\[ && ${#} -gt 1 ]] && v+="[]"
+ printf -v "${a_v}" "%s %s" "${!a_v}" "${v}"
- v=$(exparam_var_name ${CURRENT_EXLIB})_${1%%=*}
+ v=$(exparam_var_name ${CURRENT_EXLIB})_${v%\[\]}
if [[ -z ${!v+set} && ${1} == *=* ]]; then
if [[ ${1} == *=\[ && ${#} -gt 1 ]]; then
shift
@@ -96,7 +102,7 @@ myexparam()
require()
{
ebuild_notice "debug" "Command 'require ${@}', using EXLIBSDIRS '${EXLIBSDIRS}'"
- local exlibs e ee p a=() location v v_qa
+ local exlibs e ee p a=() location v a_v v_qa
# parse exlib parameters
while [[ -n $@ ]]; do
if [[ ${1} == +(\[) ]]; then
@@ -104,10 +110,9 @@ require()
p=${1}
shift
while [[ -n ${1} && ${1} != ${p//\[/\]} ]]; do
- v="$(exparam_var_name ${e})__ALL__"
- printf -v "${v}" "%s %s" "${!v}" "${1%%=*}"
+ v="${1%%=*}"
if [[ ${1#*=} == ${p} ]]; then
- v=${1%%=*}
+ v+="[]"
a=()
shift
while [[ -n ${1} && ${1} != ${p//\[/\]} ]]; do
@@ -115,10 +120,12 @@ require()
shift
done
[[ ${1} == ${p//\[/\]} ]] || die "\"${p}\" encountered with no closing \"${p//[/]}\" for array ${v}"
- eval "$(exparam_var_name ${e})_${v}=( \"\${a[@]}\" )"
+ eval "$(exparam_var_name ${e})_${v%\[\]}=( \"\${a[@]}\" )"
else
printf -v "$(exparam_var_name ${e})_${1%%=*}" "%s" "${1#*=}"
fi
+ a_v="$(exparam_var_name ${e})__ALL__"
+ printf -v "${a_v}" "%s %s" "${!a_v}" "${v}"
shift
done
[[ ${1} == ${p//\[/\]} ]] || die "\"${p}\" encountered with no closing \"${p//[/]}\""
@@ -185,11 +192,20 @@ require()
fi
done
- # die on required exlib parameters that hasn't been supplied
- local a_v=$(exparam_var_name ${CURRENT_EXLIB})__ALLDECLS__ c_v v
+ # die on required exlib parameters that haven't been supplied
+ local c_v v
+ a_v=$(exparam_var_name ${CURRENT_EXLIB})__ALLDECLS__
for v in ${!a_v}; do
- c_v=$(exparam_var_name ${CURRENT_EXLIB})_${v}
- [[ -n ${!c_v+set} ]] || die "${CURRENT_EXLIB}.exlib requires a ${v} parameter"
+ c_v=$(exparam_var_name ${CURRENT_EXLIB})_${v%\[\]}
+ if [[ -n ${!c_v+set} ]]; then
+ if [[ $(eval "declare -p ${c_v}") == declare\ -a\ ${c_v}=* ]]; then
+ [[ ${v} == *\[\] ]] || die "${CURRENT_EXLIB}.exlib requires a scalar ${v} parameter but got an array"
+ else
+ [[ ${v} != *\[\] ]] || die "${CURRENT_EXLIB}.exlib requires an array ${v} but got a scalar"
+ fi
+ else
+ die "${CURRENT_EXLIB}.exlib requires a ${v} parameter"
+ fi
done
# die on supplied exlib parameters which haven't been declared