From 0724e525c8f3144b7fc689e5762ee04202dbd715 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 14:33:13 +0000 Subject: - Implements -c (clean) and -nd (no download (unless necessary.)) - General cleanup; consistent build status files in $PREFIX, LICENSE -> LICENCE., fix libelf's pkg_libelf_install_post(), rotate status files and tarballs. --- build.subr | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'build.subr') diff --git a/build.subr b/build.subr index 9f7f540e..b696a285 100644 --- a/build.subr +++ b/build.subr @@ -4,7 +4,6 @@ # date() { command date +"${1:-${TIMESTAMP_FMT}}"; }; -fetch_git() { [ -d ${1} ] && (cd ${1} && git pull origin main) || git clone ${3} ${2} ${1}; }; get_basename() { set -- $(get_name_without_slash ${1}); echo "${1##*/}"; }; get_var_dyn() { ${1}; }; get_var_unsafe() { eval echo \${${1}}; }; @@ -24,6 +23,22 @@ test_cmd() { command -v "${1}" >/dev/null; }; unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; }; +build_times_init() { BUILD_TIMES_SECS=$(command date +%s); }; +build_times_get() { + : $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS})); + : $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600)); + : $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60)); + : $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60)); +}; + +clean_prefix() { + log_msg info "-c specified, cleaning prefix..."; + set -- bin include lib lib64 libexec native share x86_64-nt64-midipix; + while [ ${#} -gt 0 ]; do rm -rf ${PREFIX}/${1}; shift; done; + find ${PREFIX}/tmp -mindepth 1 -maxdepth 1 -not -iname \*.tar\* -exec rm -rf {} \; + find ${PREFIX}/tmp -mindepth 1 -maxdepth 1 -type f -iname .\* -exec rm -rf {} \; +}; + export_vars_subst() { _evs_pfx=${1}; _evs_pfx_new=${2}; shift 2; while [ ${#} -gt 0 ]; do @@ -33,6 +48,12 @@ export_vars_subst() { done; unset _evs_pfx _evs_pfx_new; }; +fetch_git() { + rm_if_exists ${1}; + [ -d ${1} ] && (cd ${1} && git pull origin main)\ + || git clone ${3} ${2} ${1}; +}; + rm_if_exists() { [ -z "${1#-m}" ] && { _rie_arg_m=1; shift; }; [ -z "${1#-c}" ] && { _rie_arg_c=1; shift; }; @@ -42,6 +63,14 @@ rm_if_exists() { return 0; }; +rotate_files() { + set -- $(find ${PREFIX} -mindepth 1 -maxdepth 1 -type f -iname "${1}" |\ + sort | sed -n $((${2}+1)),\$p); + while [ ${#} -gt 0 ]; do + rm -f "${1}"; shift; + done; +}; + set_env_vars() { _sev_val_new="${1}"; shift; while [ ${#} -gt 1 ]; do @@ -101,6 +130,8 @@ clear_env_with_except() { }; fetch() { + [ ${ARG_NO_DOWNLOAD:-0} -eq 0 ] &&\ + rm_if_exists $(get_basename ${1}); wget ${WGET_ARGS} ${1}; if [ ${#} -eq 2 ]; then set -- $(get_basename ${1}) "$(compare_hash $(get_basename ${1}) ${2})" ${2}; @@ -129,7 +160,10 @@ compare_hash_manifest() { is_build_script_done() { if [ -n "${ARG_RESTART_SCRIPT_AT}" ]; then - if [ "${1}" = "finish" ]\ + if [ "${1}" = clean ]\ + && [ -z "${ARG_RESTART_SCRIPT_AT#ALL}" ]; then + return 0; # Skip + elif [ "${1}" = finish ]\ || [ -z "${ARG_RESTART_SCRIPT_AT#ALL}" ]; then return 1; # Build elif ! match_list ${ARG_RESTART_SCRIPT_AT} , ${1}; then @@ -222,4 +256,32 @@ run_cmd_unsplit() { unset _rcu_cmd _rcu_cmdline; return ${_rcu_rc}; }; +update_build_status() { + while [ ${#} -gt 0 ]; do + case ${1} in + build_start) + touch ${BUILD_STATUS_IN_PROGRESS_FNAME}; + touch ${BUILD_STATUS_PROGRESS_FNAME:=${PREFIX}/BUILD_STARTED_AT_${BUILD_DATE_START:=$(date %Y-%m-%d-%H-%M-%S)}}; + ;; + build_finish) + [ -f ${BUILD_STATUS_PROGRESS_FNAME} ] &&\ + rm -f ${BUILD_STATUS_PROGRESS_FNAME}; + touch ${BUILD_STATUS_FINISHED_AT_FNAME:=${PREFIX}/BUILD_FINISHED_AT_$(date ${TIMESTAMP_FMT_STATUS_FILES})}; + rotate_files BUILD_FINISHED_AT_\* 8; + ln -sf ${BUILD_STATUS_FINISHED_AT_FNAME}\ + ${BUILD_STATUS_FINISHED_AT_CURRENT_FNAME}; ;; + tarball_start) + rotate_files midipix.\*.tar.bz2 8; + touch ${BUILD_STATUS_TARBALL_PROGRESS_FNAME:=${PREFIX}/TARBALL_STARTED_AT_$(date ${TIMESTAMP_FMT_STATUS_FILES})}; + ;; + tarball_finish) + [ -f ${BUILD_STATUS_TARBALL_PROGRESS_FNAME} ] &&\ + rm -f ${BUILD_STATUS_TARBALL_PROGRESS_FNAME}; ;; + finish) + [ -f ${BUILD_STATUS_IN_PROGRESS_FNAME} ] &&\ + rm -f ${BUILD_STATUS_IN_PROGRESS_FNAME}; ;; + esac; shift; + done; +}; + # vim:filetype=sh -- cgit v1.2.3