Add sanity checking for variants.

Any variant name can be specified on the command line, but only
certain variants will be supported by a given package. Detect which
are valid for a given package and exit with an error if a request is
made for an invalid variant.
This commit is contained in:
Simon Howard 2016-06-15 19:13:57 -04:00
parent ca536950f8
commit f0bd215fb5
2 changed files with 24 additions and 7 deletions

View file

@ -71,6 +71,25 @@ dependencies_for_native() {
done
}
variant() {
local for_variant=$1; shift
if [ "$PACKAGE_VARIANT" = "$for_variant" ]; then
"$@"
fi
ALL_VARIANTS+=("$for_variant")
}
# Check if the given variant was declared in the package file.
valid_variant() {
local for_variant=$1
for v in "${ALL_VARIANTS[@]}"; do
if [ "$v" = "$for_variant" ]; then
return 0
fi
done
false
}
# Given a package name, find the pkgdef file associated with it, source
# the contents of the file and set various variables.
configure_for_package() {
@ -97,6 +116,7 @@ configure_for_package() {
PACKAGE_DESCRIPTION="Package $package"
DEPENDENCIES=""
PACKAGE_DIR_NAME=$package
ALL_VARIANTS=(stable)
local pkg_file="$CHOCPKG_ROOT/pkgdef/$package.sh"
if [ ! -e "$pkg_file" ]; then
@ -104,6 +124,10 @@ configure_for_package() {
fi
. "$pkg_file"
if ! valid_variant "$PACKAGE_VARIANT"; then
error_exit "Unknown variant $PACKAGE_VARIANT for package $package."
fi
# We set up build differently depending on the package type: some packages
# are for the target we're building for; others are native tools to run on
# the build machine as part of the build process.

View file

@ -5,13 +5,6 @@ install_module() {
${module_name}::init "$@"
}
variant() {
local for_variant=$1; shift
if [ "$PACKAGE_VARIANT" = "$for_variant" ]; then
"$@"
fi
}
package_group() {
install_module package_group "$@"
}