config_post_main: sanity checks for RELEASE (vs ARCH) and RELEASE+DESKTOP_ENVIRONMENT (vs ARCH)

- the interactive menus didn't allow interactive users to select invalid combinations...
- ... but if specified directly on cmdline, no checks were done at all.
- introduce `exit_with_target_not_supported_error()`, which is just `exit_with_error` (code 43) but with code 44
  - this way the targets pipeline can just warn instead of break;
  - sometimes it's easier multiplying matrixes and skipping the few that can't be built
This commit is contained in:
Ricardo Pardini 2023-08-23 14:02:26 +02:00 committed by Igor
parent 1eaf25ad3d
commit a9d5969f21
2 changed files with 72 additions and 0 deletions

View File

@ -194,3 +194,19 @@ function exit_with_error() {
exit 43
}
# terminate build with a specific error code (44), meaning "target not supported".
# this is exactly like exit_with_error, but will be handled differently by the build pipeline.
function exit_with_target_not_supported_error() {
# Log the error and exit.
# Everything else will be done by shared trap handling, above.
local _file="${BASH_SOURCE[1]}"
local _function=${FUNCNAME[1]}
local _line="${BASH_LINENO[0]}"
display_alert "target not supported! " "${1} ${2}" "err"
overlayfs_wrapper "cleanup"
exit 44
}

View File

@ -274,6 +274,9 @@ function config_post_main() {
declare -g ARMBIAN_WILL_BUILD_UBOOT=no
fi
# Do some sanity checks for userspace stuff, if RELEASE/DESKTOP_ENVIRONMENT is set.
check_config_userspace_release_and_desktop
display_alert "Extensions: finish configuration" "extension_finish_config" "debug"
call_extension_method "extension_finish_config" <<- 'EXTENSION_FINISH_CONFIG'
*allow extensions a last chance at configuration just before it is done*
@ -299,6 +302,59 @@ function set_distribution_status() {
return 0 # due to last stmt above being a shortcircuit conditional
}
function check_config_userspace_release_and_desktop() {
# Do some sanity checks for userspace stuff.
# If RELEASE is set, it must be a valid release.
# We'll also check that the RELEASE supports the ARCH.
# Then we'll do the same for RELEASE+DESKTOP_ENVIRONMENT and the ARCH.
if [[ "${RELEASE}" != "" ]]; then
declare release_distro_dir="${SRC}/config/distributions/${RELEASE}"
declare release_distro_arches_file="${release_distro_dir}/architectures"
if [[ ! -d "${release_distro_dir}" ]]; then
exit_with_target_not_supported_error "RELEASE '${RELEASE}' is not supported; there is no '${release_distro_dir}' directory."
fi
if [[ ! -f "${release_distro_arches_file}" ]]; then
exit_with_target_not_supported_error "RELEASE '${RELEASE}' does not have file ${release_distro_arches_file}"
fi
if grep -q "${ARCH}" "${release_distro_arches_file}"; then
display_alert "RELEASE '${RELEASE}' supports ARCH '${ARCH}'" "RELEASE=${RELEASE} ARCH=${ARCH}; see ${release_distro_arches_file}" "debug"
else
exit_with_target_not_supported_error "RELEASE '${RELEASE}' does not support ARCH '${ARCH}'; see ${release_distro_arches_file}"
fi
# Desktop sanity checks, in the same vein.
if [[ "${DESKTOP_ENVIRONMENT}" != "" ]]; then
# If DESKTOP_ENVIRONMENT is set, but BUILD_DESKTOP is not, then we have a problem.
if [[ "${BUILD_DESKTOP}" != "yes" ]]; then
exit_with_error "DESKTOP_ENVIRONMENT is set, but BUILD_DESKTOP is not ==yes - please fix your parameters."
fi
declare desktop_release_distro_dir="${SRC}/config/desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}"
declare desktop_release_distro_arches_file="${release_distro_dir}/architectures"
if [[ ! -d "${desktop_release_distro_dir}" ]]; then
exit_with_target_not_supported_error "RELEASE '${RELEASE}' and Desktop Environment '${DESKTOP_ENVIRONMENT}' combination is not supported; there is no '${desktop_release_distro_dir}' directory."
fi
if [[ ! -f "${desktop_release_distro_arches_file}" ]]; then
exit_with_target_not_supported_error "RELEASE '${RELEASE}' and Desktop Environment '${DESKTOP_ENVIRONMENT}' combination is not supported; there is no '${desktop_release_distro_arches_file}' file."
fi
if grep -q "${ARCH}" "${desktop_release_distro_arches_file}"; then
display_alert "RELEASE '${RELEASE}' and Desktop Environment '${DESKTOP_ENVIRONMENT}' combination is supported" "RELEASE=${RELEASE} ARCH=${ARCH}; see ${desktop_release_distro_arches_file}" "debug"
else
exit_with_target_not_supported_error "RELEASE '${RELEASE}' and Desktop Environment '${DESKTOP_ENVIRONMENT}' combination is not supported; see ${desktop_release_distro_arches_file}"
fi
fi
fi
return 0
}
# Some utility functions
function branch2dir() {
[[ "${1}" == "head" ]] && echo "HEAD" || echo "${1##*:}"