diff options
Diffstat (limited to 'subr/build_init.subr')
-rw-r--r-- | subr/build_init.subr | 274 |
1 files changed, 116 insertions, 158 deletions
diff --git a/subr/build_init.subr b/subr/build_init.subr index eeeaf60b..91784f83 100644 --- a/subr/build_init.subr +++ b/subr/build_init.subr @@ -3,87 +3,117 @@ # buildp_init_args() { - local _last_pkg=""; _status=""; - if [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\ + local _group="" _last_pkg="" _pkg_names_unknown="" _rc=0; _status=""; + if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\ + && [ "${ARG_RELAXED:-0}" -eq 1 ]; then + _rc=1; _status="Error: --dump-on-abort excludes -R."; + elif [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\ && [ -e "${PREFIX}/build.gitref" ]\ && [ "$(git rev-parse HEAD)" = "$(cat "${PREFIX}/build.gitref")" ]; then - _status="Git repository has not changed since last build and --as-needed was specified."; - fi; - if [ -n "${ARG_RESTART}" ]; then - if [ "${ARG_RESTART#\*\*\*}" != "${ARG_RESTART}" ]; then - ARG_RESTART="${ARG_RESTART#\*\*\*}"; ARG_RESTART_RECURSIVE=3; - elif [ "${ARG_RESTART#\*\*}" != "${ARG_RESTART}" ]; then - ARG_RESTART="${ARG_RESTART#\*\*}"; ARG_RESTART_RECURSIVE=2; - elif [ "${ARG_RESTART#\*}" != "${ARG_RESTART}" ]; then - ARG_RESTART="${ARG_RESTART#\*}"; ARG_RESTART_RECURSIVE=1; - fi; - fi; - case "${ARG_RESTART}" in - ALL) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=2; ;; - LAST) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=0; ;; - "") ;; - *:*) ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="$(rtl_llift "${ARG_RESTART%%:*}" "," " ")"; ;; - *) ARG_RESTART="$(rtl_llift "${ARG_RESTART}" "," " ")"; ARG_RESTART_AT=ALL; ;; - esac; - if [ "${ARG_RESTART}" = "LAST" ]; then - if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\ - && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then - _last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")"; - rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; - rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}"; - ARG_RESTART="${_last_pkg}"; + _rc=0; _status="Git repository has not changed since last build and --as-needed was specified."; + else case "${ARG_PARALLEL}" in + auto) if ! ARG_PARALLEL="$(rtl_get_cpu_count)"; then + _rc=1; _status="Error: failed to get CPU count."; + else + ARG_PARALLEL=$((${ARG_PARALLEL}/2)); + fi; ;; + "") ARG_PARALLEL=1; ;; + *) if ! rtl_isnumber "${ARG_PARALLEL}"; then + _rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'."; + fi; ;; + esac; + if [ "${_rc:-0}" -eq 0 ]; then + DEFAULT_BUILD_CPUS="${ARG_PARALLEL}"; + case "${ARG_FETCH_FORCE}" in + ipv4) DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; + DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; ;; + ipv6) DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; + DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; ;; + esac; + case "${ARG_RESTART}" in + \*\*\*[a-zA-Z]*) + ARG_RESTART="${ARG_RESTART#\*\*\*}"; ARG_RESTART_RECURSIVE=3; ;; + \*\*[a-zA-Z]*) ARG_RESTART="${ARG_RESTART#\*\*}"; ARG_RESTART_RECURSIVE=2; ;; + \*[a-zA-Z]*) ARG_RESTART="${ARG_RESTART#\*}"; ARG_RESTART_RECURSIVE=1; ;; + ALL) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=2; ;; + LAST) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=0; + if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\ + && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then + _last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")"; + rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; + rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}"; + ARG_RESTART="${_last_pkg}"; + else + _rc=1; _status="Error: cannot rebuild last failed package."; + fi; ;; + esac; + if [ "${_rc:-0}" -eq 0 ]; then + case "${ARG_RESTART}" in + *:*) ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="$(rtl_llift "${ARG_RESTART%%:*}" "," " ")"; ;; + *) ARG_RESTART="$(rtl_llift "${ARG_RESTART}" "," " ")"; ARG_RESTART_AT=ALL; ;; + esac; + if ! ex_pkg_load_groups; then + _rc=1; _status="Error: failed to load build groups."; + else if ! rtl_lmatch "${ARG_DIST}" "rpm" ","; then + EX_PKG_BUILD_GROUPS="$(rtl_lfilter "${EX_PKG_BUILD_GROUPS}" "host_deps_rpm")"; + fi; + if [ -z "${BUILD_GROUPS}" ]; then + BUILD_GROUPS="${EX_PKG_BUILD_GROUPS}"; + else for _group in ${BUILD_GROUPS}; do + if ! rtl_lmatch "${EX_PKG_BUILD_GROUPS}" "${_group}"; then + _rc=1; _status="Error: unknown build group \`${_group}'."; break; + fi; + done; + fi; + if [ "${_rc:-0}" -eq 0 ]; then + if [ -n "${ARG_DIST}" ]; then + BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")"; + fi; + if [ -n "${ARG_RESTART}" ]; then + for _pkg_name in ${ARG_RESTART}; do + if ! ex_pkg_find_package "${BUILD_GROUPS}" "${_pkg_name}" >/dev/null; then + _pkg_names_unknown="$(rtl_lconcat "${_pkg_names_unknown}" "${_pkg_name}")"; + fi; + done; + case "$(rtl_llength "${_pkg_names_unknown}")" in + 0) ;; + 1) _rc=1; _status="Error: unknown package \`${_pkg_names_unknown}'."; ;; + *) _rc=1; _status="Error: unknown packages: $(rtl_subst "${_pkg_names_unknown}" " " ", ")"; ;; + esac; + fi; + if [ "${_rc}" -eq 0 ]; then + case "${ARG_VERBOSE:-0}" in + 0) rtl_fileop_set_log 0; rtl_log_set_lvl 0; ;; + 1) rtl_fileop_set_log 0; rtl_log_set_lvl 2; ;; + 2) rtl_fileop_set_log 0; rtl_log_set_lvl 2; ;; + 3) rtl_fileop_set_log 0; rtl_log_set_lvl 2; ;; + 4) rtl_fileop_set_log 1; rtl_log_set_lvl 3; ;; + *) _rc=1; _status="Error: invalid verbosity level (max. -vvvv)"; ;; + esac; + fi; + fi; + fi; + fi; fi; - fi; - rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}"; - case "${ARG_FETCH_FORCE}" in - ipv4) DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; - DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; ;; - ipv6) DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; - DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; ;; - esac; - return 0; -}; - -buildp_init_defaults() { - local _rc=0; _status=""; - - # Command-line arguments - : ${ARCH:="nt64"}; : ${BUILD:="debug"}; - ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DUMP_IN=""; - ARG_DUMP_ON_ABORT=0; ARG_DIST=""; ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; - ARG_RESTART=""; ARG_VERBOSE=0; - - # Build parameters & state - BUILD_HNAME=""; BUILD_IS_PARENT=1; BUILD_GROUPS=""; BUILD_GROUPS_INHIBIT_DEPS=0; - BUILD_TARGET=""; BUILD_USER=""; MIDIPIX_BUILD_PWD=""; - - # Global defaults - DEFAULT_BUILD_CPUS=1; - DEFAULT_BUILD_LAST_FAILED_PKG_FNAME="" - DEFAULT_BUILD_LOG_FNAME=""; - DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME=""; - DEFAULT_BUILD_STEPS=""; - DEFAULT_BUILD_VARS=""; - DEFAULT_CLEAR_PREFIX_PATHS=""; - DEFAULT_GIT_ARGS=""; - DEFAULT_GITROOT_HEAD=""; - DEFAULT_LOG_ENV_VARS=""; - DEFAULT_TARGET=""; - DEFAULT_WGET_ARGS=""; - - return "${_rc}"; + fi; return "${_rc}"; }; buildp_init_env() { local _fname="" _rc=0; _status=""; - if ! umask 022; then - printf "Error: failed to setup environment.\n"; exit 1; + if ! cd "${0%/*}"; then + printf "Error: failed to change working directory to \`${0%/*}'." >&2; exit 1; + elif ! umask 022; then + printf "Error: failed to set umask(2).\n" >&2; exit 1; + elif ! BUILD_HNAME="$(hostname)"; then + _rc=1; _status="Error: failed to obtain hostname."; + elif ! BUILD_USER="$(id -nu)"; then + _rc=1; _status="Error: failed to obtain username."; else for _fname in $(find subr -name *.subr); do if ! . "${_fname}"; then printf "Error: failed to source \`%s'.\n" "${_fname}"; exit 1; fi; - done; fi; - return "${_rc}"; + done; + fi; return "${_rc}"; }; buildp_init_files() { @@ -107,7 +137,7 @@ buildp_init_files() { rtl_fileop mv "${DEFAULT_BUILD_LOG_FNAME}" "${_log_last_fname}"; rtl_fileop ln_symbolic "${_log_last_fname}" "${DEFAULT_BUILD_LOG_LAST_FNAME}"; fi; - rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; + rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; rtl_log_set_fname "${DEFAULT_BUILD_LOG_FNAME}"; if rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then rtl_log_msg info "-C prefix specified, cleaning prefix..."; for _pname in ${DEFAULT_CLEAR_PREFIX_PATHS}; do @@ -123,6 +153,10 @@ buildp_init_files() { buildp_init_getopts() { local _arg="" _opt="" _rc=0 _shiftfl=0 OPTIND=0; _status=""; + : ${ARCH:="nt64"}; : ${BUILD:="debug"}; + ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST=1; ARG_DUMP_IN=""; + ARG_DUMP_ON_ABORT=0; ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESTART=""; + ARG_VERBOSE=0; while [ "${#}" -gt 0 ]; do case "${1}" in --as-needed) ARG_AS_NEEDED=1; _shiftfl=1; ;; @@ -161,13 +195,10 @@ buildp_init_getopts() { break; fi; done; - if [ "${_rc}" -eq 0 ]; then - if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\ - && [ "${ARG_RELAXED:-0}" -eq 1 ]; then - _rc=1; _status="Error: --dump-on-abort excludes -R."; - else while [ ${#} -gt 0 ]; do - if [ "${1#\*}" != "${1}" ]; then - BUILD_GROUPS_INHIBIT_DEPS=1; _arg="${1#\*}"; + if [ "${_rc:-0}" -eq 0 ]; then + while [ ${#} -gt 0 ]; do + if [ "${1#=}" != "${1}" ]; then + BUILD_GROUPS_INHIBIT_DEPS=1; _arg="${1#=}"; else _arg="${1}"; fi; @@ -176,56 +207,17 @@ buildp_init_getopts() { [^a-zA-Z]*) _rc=1; _status="Error: build group names must start with [a-zA-Z] (in argument \`${_arg}'.)"; ;; *[^_a-zA-Z]*) _rc=1; _status="Error: build group names must not contain [^_a-zA-Z] (in argument \`${_arg}'.)"; ;; *) BUILD_GROUPS="$(rtl_lconcat "${BUILD_GROUPS}" "${_arg}")"; ;; - esac; shift; done; - fi; + esac; shift; + done; fi; return "${_rc}"; }; -buildp_init_groups() { - local _default_build_groups="" _fname="" _group="" _groups="" _rc=0; _status=""; - 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 - _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")"; - fi; - unset GROUP_AUTO; - else - _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")"; - fi; - fi; - done; - _default_build_groups="$(rtl_uniq "${_default_build_groups}")"; - if ! rtl_lmatch "${ARG_DIST}" "rpm" ","; then - _default_build_groups="$(rtl_lfilter "${_default_build_groups}" "host_deps_rpm")"; - fi; - if [ -z "${BUILD_GROUPS}" ]; then - BUILD_GROUPS="${_default_build_groups}"; - fi; - if [ -n "${ARG_DIST}" ]; then - BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")"; - fi; - for _group in ${BUILD_GROUPS}; do - if ! rtl_lmatch "${_groups}" "${_group}"; then - _rc=1; _status="Error: unknown build group \`${_group}'."; break; - fi; - done; - return "${_rc}"; -}; - buildp_init_prereqs() { local _cmd="" _cmds_missing="" _rc=0; _status=""; for _cmd in \ awk bunzip2 bzip2 cat chmod cmake cp date find flock \ - g++ gcc git grep gunzip gzip hostname install kill \ + g++ gcc git grep gunzip gzip hostname id install kill \ ln lzip make mkdir mkfifo mktemp mv paste patch perl \ pgrep pkill printf readlink rm sed sha256sum sort \ tail tar test touch tr uniq wget xz zip; do @@ -242,50 +234,16 @@ buildp_init_prereqs() { return "${_rc}"; }; -buildp_init_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}'."; - elif [ -n "${ARG_PARALLEL}" ] && [ "${ARG_PARALLEL}" != "auto" ]\ - && ! rtl_isnumber "${ARG_PARALLEL}"; then - _rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'."; - else case "${ARCH}" in - nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; - nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; - esac; - if DEFAULT_BUILD_CPUS="$(rtl_get_cpu_count)"; then - if [ "${ARG_PARALLEL}" = "auto" ]\ - && [ "${DEFAULT_BUILD_CPUS}" -gt 1 ]; then - ARG_PARALLEL=$((${DEFAULT_BUILD_CPUS}/2)); - fi; - 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; - fi; return "${_rc}"; -}; - build_init() { - local _fname="" _rc=0 _status=""; + local _rc=0; _status=""; if ! buildp_init_env \ - || ! buildp_init_defaults \ || ! buildp_init_getopts "${@}" \ || ! buildp_init_prereqs \ - || ! buildp_init_vars \ - || ! buildp_init_groups \ + || ! ex_pkg_load_vars \ || ! buildp_init_args \ || ! buildp_init_files; then - _rc="${?}"; rtl_log_msg fail "${_status}"; exit "${_rc}"; - elif [ -n "${_status}" ]; then - rtl_log_msg info "${_status}"; exit 0; - else - return "${_rc}"; - fi; + _rc=1; _status="${_status}"; + fi; return "${_rc}"; }; # vim:filetype=sh |