summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de>2017-11-21 18:02:50 +0000
committerLucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de>2017-11-21 18:02:50 +0000
commitf6a5cb3531f9333cfdf4b061e671a84a7ef6c530 (patch)
tree2f2c8bcea6f18294671979cf5cbbaf4f6ea2a7f2
parentd9d263760e07616bd8864d1ae296d2052da611d1 (diff)
downloadmidipix_build-f6a5cb3531f9333cfdf4b061e671a84a7ef6c530.tar.bz2
midipix_build-f6a5cb3531f9333cfdf4b061e671a84a7ef6c530.tar.xz
{build.sh,subr/pre_setup_args.subr}: split.
subr/pre_setup_env.subr: set -o noglob.
-rwxr-xr-xbuild.sh52
-rw-r--r--subr/pre_setup_args.subr67
-rw-r--r--subr/pre_setup_env.subr5
3 files changed, 74 insertions, 50 deletions
diff --git a/build.sh b/build.sh
index 45944e9a..60c78aba 100755
--- a/build.sh
+++ b/build.sh
@@ -2,48 +2,9 @@
# Copyright (c) 2016, 2017 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
#
-#
-#
-#
-for __ in subr/*.subr; do . "${__}"; done;
-set -o noglob;
-while [ ${#} -gt 0 ]; do
-case ${1} in
--4) ARG_IPV4_ONLY=1; ;;
--6) ARG_IPV6_ONLY=1; ;;
--c) ARG_CLEAN=1; ;;
--N) ARG_OFFLINE=1; ;;
--i) ARG_IGNORE_SHA256SUMS=1; ;;
--R) ARG_RELAXED=1; ;;
---debug-minipix)
- ARG_DEBUG_MINIPIX=1; ;;
--t*) ARG_TARBALL=1; [ "${1#-t.}" != "${1}" ] && TARBALL_SUFFIX="${1#-t.}"; ;;
--v) ARG_VERBOSE=1; ;;
--x) ARG_XTRACE=1; set -o xtrace; ;;
--a) [ -z "${2}" ] && exec cat etc/build.usage || ARCH="${2}"; shift; ;;
--b) [ -z "${2}" ] && exec cat etc/build.usage || BUILD="${2}"; shift; ;;
--r) if [ -z "${2}" ]; then
- exec cat build.usage;
- elif [ "${2%:*}" = "${2}" ]; then
- ARG_RESTART="${2}";
- else
- ARG_RESTART="${2%:*}"; ARG_RESTART_AT="${2#*:}";
- fi;
- BUILD_PACKAGES_RESTART="$(echo ${ARG_RESTART} | sed "s/,/ /g")";
- shift; ;;
-*=*) set_var_unsafe "${1%%=*}" "${1#*=}"; ;;
-*) if lmatch "${1}" " " "${ALL_TARGETS}"; then
- BUILD_TARGETS_META="${BUILD_TARGETS_META:+${BUILD_TARGETS_META} }${1}";
- else
- exec cat etc/build.usage;
- fi; ;;
-esac; shift; done;
-pre_setup_env; pre_check; pre_subdirs; build_files_init;
-
-#
-#
-#
-{(
+for __ in $(find subr -name *.subr); do . "${__}"; done;
+pre_setup_args "${@}"; pre_setup_env; pre_check; pre_subdirs;
+build_files_init; {(
log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}.";
log_env_vars "build (global)" ${LOG_ENV_VARS};
for BUILD_TARGET_LC in $(subst_tgts invariants ${BUILD_TARGETS_META:-world}); do
@@ -71,8 +32,7 @@ for BUILD_TARGET_LC in $(subst_tgts invariants ${BUILD_TARGETS_META:-world}); do
if [ "${BUILD_SCRIPT_RC:-0}" -ne 0 ]; then
break;
fi;
-done;
-build_files_fini;
+done; build_files_fini;
log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL} failed builds in ${BUILD_NBUILT} build script(s).";
log_msg info "Build time: ${BUILD_TIMES_HOURS} hour(s), ${BUILD_TIMES_MINUTES} minute(s), and ${BUILD_TIMES_SECS} second(s).";
if [ ${ARG_RELAXED:-0} -eq 1 ]\
@@ -80,10 +40,10 @@ if [ ${ARG_RELAXED:-0} -eq 1 ]\
log_msg info "Build script failure(s) in: ${BUILD_PKGS_FAILED}.";
fi;
exit "${BUILD_SCRIPT_RC:-0}")} 2>&1 | tee "${BUILD_LOG_FNAME}" & TEE_PID="${!}";
+
trap "rm -f ${BUILD_STATUS_IN_PROGRESS_FNAME}; \
log_msg fail \"Build aborted.\"; \
echo kill ${TEE_PID}; \
- kill ${TEE_PID}" HUP INT TERM USR1 USR2;
-wait;
+ kill ${TEE_PID}" HUP INT TERM USR1 USR2; wait;
# vim:filetype=sh
diff --git a/subr/pre_setup_args.subr b/subr/pre_setup_args.subr
new file mode 100644
index 00000000..e9c10a50
--- /dev/null
+++ b/subr/pre_setup_args.subr
@@ -0,0 +1,67 @@
+BUILD_ARGS_SPEC="
+ ARG_IPV4_ONLY:-4
+ ARG_IPV6_ONLY:-6
+ ARCH:arg:-a
+ BUILD:arg:-b
+ ARG_CLEAN:-c
+ ARG_DEBUG_MINIPIX:--debug-minipix
+ ARG_IGNORE_SHA256SUMS:-i
+ ARG_OFFLINE:-N
+ ARG_RELAXED:-R
+ ARG_RESTART:arg:-r
+ ARG_TARBALL:selfarg:-t
+ ARG_TARBALL:selfarg:-t.bz2
+ ARG_TARBALL:selfarg:-t.gz
+ ARG_TARBALL:selfarg:-t.xz
+ ARG_VERBOSE:-v
+ ARG_XTRACE:-x";
+
+pre_setup_args() {
+ local _spec="${BUILD_ARGS_SPEC}" _spec_arg _found;
+ while [ ${#} -gt 0 ]; do
+ if [ "${1#-}" = "${1}" ]; then
+ break;
+ fi;
+ for _spec_arg in ${_spec}; do
+ case "${_spec_arg}" in
+ *:${1}) case "${_spec_arg#*:}" in
+ arg:*)
+ set_var_unsafe "${_spec_arg%%:*}" "${2}"; shift; ;;
+ selfarg:*)
+ set_var_unsafe "${_spec_arg%%:*}" "${1}"; ;;
+ *)
+ set_var_unsafe "${_spec_arg%%:*}" 1; ;;
+ esac; _found=1; break; ;;
+ *) _found=0; ;;
+ esac;
+ done;
+ if [ "${_found:-0}" -eq 0 ]; then
+ exec cat etc/build.usage;
+ else
+ shift;
+ fi;
+ done;
+ if [ -n "${ARG_TARBALL}" ]; then
+ if [ "${ARG_TARBALL#-t.}" != "${ARG_TARBALL}" ]; then
+ TARBALL_SUFFIX="${ARG_TARBALL#-t.}";
+ else
+ TARBALL_SUFFIX=xz;
+ fi;
+ fi;
+ if [ "${ARG_XTRACE:-0}" -eq 1 ]; then
+ set -o xtrace;
+ fi;
+ if [ -n "${ARG_RESTART}" ]; then
+ if [ "${ARG_RESTART%:*}" != "${ARG_RESTART}" ]; then
+ ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="${ARG_RESTART%:*}";
+ fi;
+ BUILD_PACKAGES_RESTART="$(echo ${ARG_RESTART} | sed "s/,/ /g")";
+ fi;
+ while [ ${#} -gt 0 ]; do
+ case "${1}" in
+ *=*) set_var_unsafe "${1%%=*}" "${1#*=}"; ;;
+ *) BUILD_TARGETS_META="${BUILD_TARGETS_META:+${BUILD_TARGETS_META} }${1}"; ;;
+ esac; shift; done;
+};
+
+# vim:filetype=sh
diff --git a/subr/pre_setup_env.subr b/subr/pre_setup_env.subr
index 0f22fdbe..c1876d31 100644
--- a/subr/pre_setup_env.subr
+++ b/subr/pre_setup_env.subr
@@ -1,9 +1,6 @@
-#
-# set -o errexit -o noglob are assumed.
-#
-
pre_setup_env() {
local __;
+ set -o noglob;
if [ -z "${DEFAULT_BUILD_CPUS}" ]\
&& [ -e /proc/cpuinfo ]; then
DEFAULT_BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);