From 090fd4b1f036d6de90dd4c63f4e1250bccc8781c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz=20=28arab=2C=20vx?= =?UTF-8?q?p=29?= Date: Sat, 27 Feb 2016 10:05:05 +0000 Subject: - build.{sh,subr } cleanup including Cygwin compatibility fixes and [gs]et_var_dyn(). - Replaced --build-{scripts,steps} w/ -r, --tarball w/ -t, and --help w/ -h. - Create BUILD_{FINISHED,STARTED}_AT_..., BUILD_IN_PROGRESS, and TARBALL_STARTED_AT files and BUILD_FINISHED_AT symlink in $PREFIX whenever appropriate. --- build.sh | 59 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index 717de7c8..0a3823db 100755 --- a/build.sh +++ b/build.sh @@ -1,23 +1,36 @@ #!/bin/sh # + { . ./build.subr; -parse_args_into_vars "${0}" build-scripts,build-steps,help,tarball "${@}"; -[ -n "${ARG_HELP}" ] && { exec cat build.usage; } || . ./build.vars; +while getopts hr:t CURRENT_ARG; do +case ${CURRENT_ARG} in +r) ARG_BUILD_SCRIPTS="${OPTARG%%:*}"; + [ -z "${ARG_BUILD_STEPS:="${ARG_BUILD_SCRIPTS##*:}"}" ] &&\ + ARG_BUILD_STEPS=ALL; ;; +t) ARG_TARBALL=1; ;; +h|\?) exec cat build.usage; ;; +esac; done; shift $((${OPTIND} - 1)); +while [ ${#} -gt 0 ]; do + if [ "x${1#*=*}" != "x${1}" ]; then + set_var_unsafe "$(get_prefix_lrg "${1}" =)" \ + "$(get_postfix "${1}" =)"; shift; + fi; +done; . ./build.vars; clear_env_with_except HOME PATH SHELL TERM USER; check_path_vars PREFIX PREFIX_NATIVE WORKDIR; check_prereqs git make mktemp openssl sed sort tar tr wget; log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE:=$(date %Y-%m-%d-%H-%M-%S)}."; -touch ${PREFIX}/BUILD_IN_PROGRESS; log_env_vars ${LOG_ENV_VARS}; (mkdir -p ${PREFIX} ${PREFIX_NATIVE} ${PREFIX_TARGET} ${WORKDIR}; +touch BUILD_IN_PROGRESS ${BUILD_PROGRESS_FNAME:=${PREFIX}/BUILD_STARTED_AT_${BUILD_DATE}}; BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}}; BUILD_SECS=$(command date +%s); for BUILD_LVL in 0 1 2 3; do for BUILD_SCRIPT_FNAME in ${BUILD_LVL}[0-9][0-9].*.build; do - if [ -n "${ARG_BUILD_SCRIPTS}" ]\ - && [ "${ARG_BUILD_SCRIPTS}" != "ALL" ]\ - && ! match_list "${ARG_BUILD_SCRIPTS}" \ + if [ -n "${ARG_BUILD_SCRIPTS}" ] \ + && [ "${ARG_BUILD_SCRIPTS}" != "ALL" ] \ + && ! match_list "${ARG_BUILD_SCRIPTS}" \ , "${BUILD_SCRIPT_FNAME}"; then log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (--build-scripts policy.)"; continue; @@ -31,7 +44,7 @@ for BUILD_LVL in 0 1 2 3; do log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (already built.)"; : $((BUILD_NSKIP+=1)); BUILD_SCRIPT_RC=0; continue; fi; - log_msg info "Invoking build script${ARG_BUILD_SCRIPTS:+ (forcibly)} \`${BUILD_SCRIPT_FNAME}'${ARG_BUILD_STEPS:+ at build step(s) ${ARG_BUILD_STEPS}}."; + log_msg info "Invoking build script${ARG_BUILD_SCRIPTS:+ (forcibly)} \`${BUILD_SCRIPT_FNAME}'${ARG_BUILD_STEPS:+ at build step ${ARG_BUILD_STEPS}}."; (set -o errexit -- $(split . ${BUILD_SCRIPT_FNAME%%.build*}); \ SCRIPT_FNAME=${BUILD_SCRIPT_FNAME}; \ SCRIPT_NAME=${SCRIPT_FNAME%%.build*}; \ @@ -40,7 +53,7 @@ for BUILD_LVL in 0 1 2 3; do _PWD=$(pwd); cd ${WORKDIR}; \ for SCRIPT_SOURCE in build.subr ${SCRIPT_NAME}.vars \ ${BUILD_SCRIPT_FNAME}; do \ - [ -r ${_PWD}/${SCRIPT_SOURCE} ] && \ + [ -f ${_PWD}/${SCRIPT_SOURCE} ] && \ . ${_PWD}/${SCRIPT_SOURCE}; \ done); case ${BUILD_SCRIPT_RC:=${?}} in @@ -61,7 +74,12 @@ log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL : $((BUILD_MINUTES=(${BUILD_SECS}%3600)/60)); : $((BUILD_SECS=(${BUILD_SECS}%3600)%60)); log_msg info "Build time: ${BUILD_HOURS} hour(s), ${BUILD_MINUTES} minute(s), and ${BUILD_SECS} second(s)."; -if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ]\ +[ -f ${BUILD_PROGRESS_FNAME} ] && rm -f ${BUILD_PROGRESS_FNAME}; +touch ${BUILD_FINISH_FNAME:=${PREFIX}/BUILD_FINISHED_AT_$(date %Y-%m-%d-%H-%M-%S)} \ + ${TARBALL_PROGRESS_FNAME:=${PREFIX}/TARBALL_STARTED_AT_$(date %Y-%m-%d-%H-%M-%S)}; +ln -sf ${BUILD_FINISH_FNAME} ${PREFIX}/BUILD_FINISHED_AT; +# rotate BUILD_FINISH_FNAME files +if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ] \ && [ ${BUILD_NFAIL} -eq 0 ]\ && [ ${ARG_TARBALL:-0} -eq 1 ]; then log_msg info "Building distribution tarball."; @@ -71,23 +89,24 @@ if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ]\ rm_if_exists -m ${PREFIX_BASENAME}/lib.bak; rm_if_exists ${DISTRIB_FNAME}; tar -C ${PREFIX_BASENAME}/lib -cpf - . | tar -C ${PREFIX_BASENAME}/lib.bak -xpf -; (cd native/lib && - find . -maxdepth 1 -type l \ + find . -maxdepth 1 -type l \ -exec sh -c 'dest=$(readlink -- "$0") && rm -- "$0" && ln -- "$dest" "$0"' {} \;); wait; - find . -maxdepth 2 -type d \ - -not -path . \ - -not -path ./src/midipix_build \ - -not -path ./src/midipix_build/\* \ - -not -path ./${WORKDIR_BASENAME} \ - -not -path ./${WORKDIR_BASENAME}/\* \ - -not -path ./${PREFIX_BASENAME} \ - -not -path ./${PREFIX_BASENAME}/lib.bak |\ + find . -maxdepth 2 -type d \ + -not -path . \ + -not -path ./src/midipix_build \ + -not -path ./src/midipix_build/\* \ + -not -path ./${WORKDIR_BASENAME} \ + -not -path ./${WORKDIR_BASENAME}/\* \ + -not -path ./${PREFIX_BASENAME} \ + -not -path ./${PREFIX_BASENAME}/lib.bak |\ tar -T - -cpf - | bzip2 -9c - > ${DISTRIB_FNAME} rm -rf ${PREFIX_BASENAME}/lib; mv ${PREFIX_BASENAME}/lib.bak ${PREFIX_BASENAME}/lib); wait; + # rotate tarballs fi; -[ -f ${PREFIX}/BUILD_IN_PROGRESS ] &&\ - rm -f ${PREFIX}/BUILD_IN_PROGRESS; +[ -f ${TARBALL_PROGRESS_FNAME} ] && rm -f ${TARBALL_PROGRESS_FNAME}; +[ -f BUILD_IN_PROGRESS ] && rm -f BUILD_IN_PROGRESS; exit ${BUILD_SCRIPT_RC})} 2>&1 | tee build.log; # vim:filetype=sh -- cgit v1.2.3