From b6a9a1a3c8b98077cce47d579069c42080d17da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 15 Mar 2020 09:14:23 +0000 Subject: General cleanup. --- subr/ex_pkg.subr | 132 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 104 insertions(+), 28 deletions(-) (limited to 'subr/ex_pkg.subr') diff --git a/subr/ex_pkg.subr b/subr/ex_pkg.subr index 497e89ce..3dcfbc7e 100644 --- a/subr/ex_pkg.subr +++ b/subr/ex_pkg.subr @@ -4,31 +4,27 @@ # # ex_pkg_check_depends() - check single named package for unsatisfied dependencies +# @_checkfl: enable (1) or inhibit (0) dependency expansion # @_pkg_disabled: list of disabled packages # @_pkg_finished: list of finished packages # @_pkg_name: single package name # @_pkg_wait: list of in-progress packages -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # # Return: zero (0) given no outstanding dependencies, non-zero (>0) otherwise # ex_pkg_check_depends() { - local _pkg_disabled="${1}" _pkg_finished="${2}" _pkg_name="${3}" \ - _pkg_wait="${4}" _restart_recursive="${5}" \ - _pkg_depends="" _pkg_name_depend="" _dependfl=0; - if _pkg_depends="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS")))"\ - && [ -n "${_pkg_depends}" ]; then - if [ -z "${_restart}" ]\ - || [ "${_restart_recursive:-0}" -ge 1 ]; then - for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do - if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name_depend}"\ - && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name_depend}"; then - _dependfl=1; break; - elif rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then - _dependfl=1; break; - fi; - done; - fi; + local _checkfl="${1}" _pkg_disabled="${2}" _pkg_finished="${3}" _pkg_name="${4}" _pkg_wait="${5}"\ + _dependfl=0 _pkg_depends="" _pkg_name_depend=""; + if [ "${_checkfl:-0}" -eq 1 ]\ + && _pkg_depends="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS")))"; then + for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do + if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name_depend}"\ + && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name_depend}"; then + _dependfl=1; break; + elif rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then + _dependfl=1; break; + fi; + done; fi; return "${_dependfl}"; }; @@ -41,7 +37,7 @@ ex_pkg_check_depends() { # Return: zero (0) on success, non-zero (>0) if package not found, group name on stdout if package was found. # ex_pkg_find_package() { - local _group_names="${1}" _pkg_name="${2}" _group_name="" _pkg_names=""; + local _group_names="${1}" _pkg_name="${2}" _foundfl=0 _group_name="" _pkg_names=""; for _group_name in ${_group_names}; do if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ && [ -n "${_pkg_names}" ]\ @@ -51,7 +47,7 @@ ex_pkg_find_package() { done; case "${_foundfl:-0}" in 0) return 1; ;; - 1) echo "${_group_name}"; return 0; ;; + 1) printf "%s" "${_group_name}"; return 0; ;; esac; }; @@ -65,32 +61,113 @@ ex_pkg_get_packages() { local _group_name="${1}" _pkg_names=""; if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ && [ -n "${_pkg_names}" ]; then - echo "${_pkg_names}"; return 0; + printf "%s" "${_pkg_names}"; return 0; else return 1; fi; }; +# +# ex_pkg_load_dump() - load package dump +# @_pkg_name: package name +# +# Return: zero (0) on success, non-zero (>0) on failure, package dump post-return on success. +# +ex_pkg_load_dump() { + local _pkg_name="${1}" _workdir="${2}" _rc=0; _status=""; + if [ ! -e "${_workdir}/${_pkg_name}.dump" ]; then + rtl_log_msg warn "Warning: failed to locate environment dump for package \`%s' in \`%s'." "${_pkg_name}" "${_workdir}"; + rtl_log_msg info "Re_building package \`%s' w/ --dump-in _build..." "${_pkg_name}"; + (export ARCH BUILD BUILD_DLCACHEDIR BUILD_WORKDIR \ + PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ + PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; + ./build.sh --dump-in _build -P -r "${_pkg_name}" -v); + if [ ! -e "${_workdir}/${_pkg_name}.dump" ]; then + _rc=1; _status="Error: failed to locate environment dump for package \`${_pkg_name}' in \`${_workdir}'."; + fi; + else + _rc=0; + fi; + if [ "${_rc:-0}" -eq 0 ]\ + && ! . "${_workdir}/${_pkg_name}.dump"; then + _rc=1; _status="Error: failed to source environment dump for package \`${_pkg_name}' from \`${_workdir}'."; + elif [ "${_rc:-0}" -eq 0 ]\ + && ! rtl_fileop cd "${PKG_BUILD_DIR}"; then + _rc=1; _status="Error: failed to change working directory to \`${PKG_BUILD_DIR}'."; + fi; return "${_rc}"; +}; + +# +# ex_pkg_load_vars() - load build variables +# +# Return: zero (0) on success, non-zero (>0) on failure, build variables post-return on success. +# +ex_pkg_load_vars() { + local _rc=0; _status=""; + if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then + _rc=1; _status="Error: invalid architecture \`${ARCH}'."; + elif ! rtl_lmatch "${BUILD}" "debug release"; then + _rc=1; _status="Error: unknown build type \`${BUILD}'."; + else case "${ARCH}" in + nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; + nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; + esac; + rtl_fileop source_opt \ + "${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars" \ + ../midipix_build.vars ./midipix.env; + if [ -z "${PREFIX}" ]; then + _rc=1; _status="Error: \${PREFIX} empty or unset."; + fi; + fi; return "${_rc}"; +}; + +# +# ex_pkg_load_groups() - load all available build groups +# +# Return: zero (0) on success, non-zero (>0) on failure, build groups loaded and ${EX_PKG_BUILD_GROUPS} set post-return. +# +ex_pkg_load_groups() { + local _build_groups="" _fname="" _group="" _groups=""; + for _fname in $(find ./groups -name *.group | sort); do + rtl_fileop source_opt "${_fname}"; + if [ -n "${GROUP_TARGET}" ]; then + _group="${GROUP_TARGET}"; unset GROUP_TARGET; + else + _group="${_fname##*/}"; _group="${_group%.group}"; _group="${_group#*.}"; + fi; + if ! rtl_lmatch "${_groups}" "${_group}"; then + _groups="$(rtl_lconcat "${_groups}" "${_group}")"; + if [ -n "${GROUP_AUTO}" ]; then + if [ "${GROUP_AUTO:-0}" -ne 0 ]; then + _build_groups="$(rtl_lconcat "${_build_groups}" "${_group}")"; + fi; + unset GROUP_AUTO; + else + _build_groups="$(rtl_lconcat "${_build_groups}" "${_group}")"; + fi; + fi; + done; + EX_PKG_BUILD_GROUPS="$(rtl_uniq "${_build_groups}")"; +}; + # # ex_pkg_unfold_depends() - unfold list of package names into dependency-expanded set of complete, disabled, finished, and outstanding package names +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages # @_group_name: build group name # @_pkg_names: list of package names # @_restart: optional whitespace-separated list of package names to rebuild -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_test_finished: only exclude disabled packages from ${EX_PKG_NAMES} (0,) split finished packages into ${EX_PKG_FINISHED} # # Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. # ex_pkg_unfold_depends() { - local _group_name="${1}" _pkg_names="${2}" _restart="${3}" \ - _restart_recursive="${4}" _test_finished="${5}" \ + local _checkfl="${1}" _forcefl="${2}" _group_name="${3}" _pkg_names="${4}" _restart="${5}" _test_finished="${6}"\ _pkg_name="" _restartfl=0; if [ -n "${_restart}" ] && ! rtl_lmatch "${_restart}" "ALL LAST"; then _pkg_names="$(rtl_lsearch "${_pkg_names}" "${_restart}")"; fi; - if [ -n "${_restart}" ]\ - && [ "${_restart_recursive:-0}" -ge 1 ]\ - && [ "${_restart_recursive:-0}" -le 2 ]; then + if [ -n "${_restart}" ] && [ "${_checkfl:-0}" -eq 1 ]; then _pkg_names="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' ${_pkg_names}))"; fi; for _pkg_name in ${_pkg_names}; do @@ -106,7 +183,7 @@ ex_pkg_unfold_depends() { elif [ "${_test_finished:-1}" -eq 1 ]\ && ex_pkg_state_test "${_pkg_name}" finish\ && [ "${_restartfl:-0}" -eq 0 ]\ - && [ "${_restart_recursive:-0}" -ne 2 ]\ + && [ "${_forcefl:-0}" -ne 1 ]\ && [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]; then EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name}")"; _pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; @@ -122,7 +199,6 @@ ex_pkg_unfold_depends() { # @_group_name: build group name # @_pkg_names: list of package names # @_restart: optional whitespace-separated list of package names to rebuild -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_test_finished: only exclude disabled packages from ${EX_PKG_NAMES} (0,) split finished packages into ${EX_PKG_FINISHED} # # Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. -- cgit v1.2.3