090fd4 - build.{sh,subr } cleanup including Cygwin compatibility fixes and [gs]et_var_dyn().

Authored and Committed by Lucio Andrés Illanes Albornoz (arab, vxp) 9 years ago
    - 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.
    
        
file modified
+39 -20
build.sh CHANGED
@@ -1,23 +1,36 @@
1
1
#!/bin/sh
2
2
#
3
+
3
4
{
4
5
. ./build.subr;
5
- parse_args_into_vars "${0}" build-scripts,build-steps,help,tarball "${@}";
6
- [ -n "${ARG_HELP}" ] && { exec cat build.usage; } || . ./build.vars;
6
+ while getopts hr:t CURRENT_ARG; do
7
+ case ${CURRENT_ARG} in
8
+ r) ARG_BUILD_SCRIPTS="${OPTARG%%:*}";
9
+ [ -z "${ARG_BUILD_STEPS:="${ARG_BUILD_SCRIPTS##*:}"}" ] &&\
10
+ ARG_BUILD_STEPS=ALL; ;;
11
+ t) ARG_TARBALL=1; ;;
12
+ h|\?) exec cat build.usage; ;;
13
+ esac; done; shift $((${OPTIND} - 1));
14
+ while [ ${#} -gt 0 ]; do
15
+ if [ "x${1#*=*}" != "x${1}" ]; then
16
+ set_var_unsafe "$(get_prefix_lrg "${1}" =)" \
17
+ "$(get_postfix "${1}" =)"; shift;
18
+ fi;
19
+ done; . ./build.vars;
7
20
clear_env_with_except HOME PATH SHELL TERM USER;
8
21
check_path_vars PREFIX PREFIX_NATIVE WORKDIR;
9
22
check_prereqs git make mktemp openssl sed sort tar tr wget;
10
23
log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE:=$(date %Y-%m-%d-%H-%M-%S)}.";
11
- touch ${PREFIX}/BUILD_IN_PROGRESS;
12
24
log_env_vars ${LOG_ENV_VARS};
13
25
(mkdir -p ${PREFIX} ${PREFIX_NATIVE} ${PREFIX_TARGET} ${WORKDIR};
26
+ touch BUILD_IN_PROGRESS ${BUILD_PROGRESS_FNAME:=${PREFIX}/BUILD_STARTED_AT_${BUILD_DATE}};
14
27
BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
15
28
BUILD_SECS=$(command date +%s);
16
29
for BUILD_LVL in 0 1 2 3; do
17
30
for BUILD_SCRIPT_FNAME in ${BUILD_LVL}[0-9][0-9].*.build; do
18
- if [ -n "${ARG_BUILD_SCRIPTS}" ]\
19
- && [ "${ARG_BUILD_SCRIPTS}" != "ALL" ]\
20
- && ! match_list "${ARG_BUILD_SCRIPTS}" \
31
+ if [ -n "${ARG_BUILD_SCRIPTS}" ] \
32
+ && [ "${ARG_BUILD_SCRIPTS}" != "ALL" ] \
33
+ && ! match_list "${ARG_BUILD_SCRIPTS}" \
21
34
, "${BUILD_SCRIPT_FNAME}"; then
22
35
log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (--build-scripts policy.)";
23
36
continue;
@@ -31,7 +44,7 @@ for BUILD_LVL in 0 1 2 3; do
31
44
log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (already built.)";
32
45
: $((BUILD_NSKIP+=1)); BUILD_SCRIPT_RC=0; continue;
33
46
fi;
34
- log_msg info "Invoking build script${ARG_BUILD_SCRIPTS:+ (forcibly)} \`${BUILD_SCRIPT_FNAME}'${ARG_BUILD_STEPS:+ at build step(s) ${ARG_BUILD_STEPS}}.";
47
+ log_msg info "Invoking build script${ARG_BUILD_SCRIPTS:+ (forcibly)} \`${BUILD_SCRIPT_FNAME}'${ARG_BUILD_STEPS:+ at build step ${ARG_BUILD_STEPS}}.";
35
48
(set -o errexit -- $(split . ${BUILD_SCRIPT_FNAME%%.build*}); \
36
49
SCRIPT_FNAME=${BUILD_SCRIPT_FNAME}; \
37
50
SCRIPT_NAME=${SCRIPT_FNAME%%.build*}; \
@@ -40,7 +53,7 @@ for BUILD_LVL in 0 1 2 3; do
40
53
_PWD=$(pwd); cd ${WORKDIR}; \
41
54
for SCRIPT_SOURCE in build.subr ${SCRIPT_NAME}.vars \
42
55
${BUILD_SCRIPT_FNAME}; do \
43
- [ -r ${_PWD}/${SCRIPT_SOURCE} ] && \
56
+ [ -f ${_PWD}/${SCRIPT_SOURCE} ] && \
44
57
. ${_PWD}/${SCRIPT_SOURCE}; \
45
58
done);
46
59
case ${BUILD_SCRIPT_RC:=${?}} in
@@ -61,7 +74,12 @@ log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL
61
74
: $((BUILD_MINUTES=(${BUILD_SECS}%3600)/60));
62
75
: $((BUILD_SECS=(${BUILD_SECS}%3600)%60));
63
76
log_msg info "Build time: ${BUILD_HOURS} hour(s), ${BUILD_MINUTES} minute(s), and ${BUILD_SECS} second(s).";
64
- if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ]\
77
+ [ -f ${BUILD_PROGRESS_FNAME} ] && rm -f ${BUILD_PROGRESS_FNAME};
78
+ touch ${BUILD_FINISH_FNAME:=${PREFIX}/BUILD_FINISHED_AT_$(date %Y-%m-%d-%H-%M-%S)} \
79
+ ${TARBALL_PROGRESS_FNAME:=${PREFIX}/TARBALL_STARTED_AT_$(date %Y-%m-%d-%H-%M-%S)};
80
+ ln -sf ${BUILD_FINISH_FNAME} ${PREFIX}/BUILD_FINISHED_AT;
81
+ # rotate BUILD_FINISH_FNAME files
82
+ if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ] \
65
83
&& [ ${BUILD_NFAIL} -eq 0 ]\
66
84
&& [ ${ARG_TARBALL:-0} -eq 1 ]; then
67
85
log_msg info "Building distribution tarball.";
@@ -71,23 +89,24 @@ if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ]\
71
89
rm_if_exists -m ${PREFIX_BASENAME}/lib.bak; rm_if_exists ${DISTRIB_FNAME};
72
90
tar -C ${PREFIX_BASENAME}/lib -cpf - . | tar -C ${PREFIX_BASENAME}/lib.bak -xpf -;
73
91
(cd native/lib &&
74
- find . -maxdepth 1 -type l \
92
+ find . -maxdepth 1 -type l \
75
93
-exec sh -c 'dest=$(readlink -- "$0") && rm -- "$0" && ln -- "$dest" "$0"' {} \;);
76
94
wait;
77
- find . -maxdepth 2 -type d \
78
- -not -path . \
79
- -not -path ./src/midipix_build \
80
- -not -path ./src/midipix_build/\* \
81
- -not -path ./${WORKDIR_BASENAME} \
82
- -not -path ./${WORKDIR_BASENAME}/\* \
83
- -not -path ./${PREFIX_BASENAME} \
84
- -not -path ./${PREFIX_BASENAME}/lib.bak |\
95
+ find . -maxdepth 2 -type d \
96
+ -not -path . \
97
+ -not -path ./src/midipix_build \
98
+ -not -path ./src/midipix_build/\* \
99
+ -not -path ./${WORKDIR_BASENAME} \
100
+ -not -path ./${WORKDIR_BASENAME}/\* \
101
+ -not -path ./${PREFIX_BASENAME} \
102
+ -not -path ./${PREFIX_BASENAME}/lib.bak |\
85
103
tar -T - -cpf - | bzip2 -9c - > ${DISTRIB_FNAME}
86
104
rm -rf ${PREFIX_BASENAME}/lib;
87
105
mv ${PREFIX_BASENAME}/lib.bak ${PREFIX_BASENAME}/lib); wait;
106
+ # rotate tarballs
88
107
fi;
89
- [ -f ${PREFIX}/BUILD_IN_PROGRESS ] &&\
90
- rm -f ${PREFIX}/BUILD_IN_PROGRESS;
108
+ [ -f ${TARBALL_PROGRESS_FNAME} ] && rm -f ${TARBALL_PROGRESS_FNAME};
109
+ [ -f BUILD_IN_PROGRESS ] && rm -f BUILD_IN_PROGRESS;
91
110
exit ${BUILD_SCRIPT_RC})} 2>&1 | tee build.log;
92
111
93
112
# vim:filetype=sh
file modified
+14 -48
build.subr CHANGED
@@ -6,15 +6,16 @@
6
6
date() { command date +"${1:-${TIMESTAMP_FMT}}"; };
7
7
fetch_git() { [ -d ${1} ] && (cd ${1} && git pull origin main) || git clone ${3} ${2} ${1}; };
8
8
get_basename() { set -- $(get_name_without_slash ${1}); echo "${1##*/}"; };
9
- get_var() { eval echo \${${1}}; }; # XXX
10
- set_var() { eval ${1}=\"${2}\"; }; # XXX
9
+ get_var_dyn() { ${1}; };
10
+ get_var_unsafe() { eval echo \${${1}}; };
11
+ set_var_dyn() { eval ${1}\(\) \{ echo \"${2}\"\; \}; };
12
+ set_var_unsafe() { eval ${1}=\"${2}\"; };
11
13
get_name_without_slash() { while [ "x${1%/}" != "x${1}" ]; do set -- ${1%/}; done; echo ${1}; };
12
14
get_postfix_lrg() { echo "${1##*${2}}"; };
13
15
get_prefix_lrg() { echo "${1%%${2}*}"; };
14
16
get_postfix() { echo "${1#*${2}}"; };
15
17
get_prefix() { echo "${1%${2}*}"; };
16
18
match_any() { [ "x${1#*${2}*}" != "x${1}" ]; };
17
- match_start() { [ "x${1#${2}}" != "x${1}" ]; };
18
19
push_IFS() { _pI_IFS="${IFS}"; IFS="${1}"; };
19
20
pop_IFS() { IFS="${_pI_IFS}"; unset _pI_IFS; };
20
21
set_build_dir() { PKG_BUILD_DIR=${1}-${2}-${TARGET}; };
@@ -26,33 +27,19 @@ unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; };
26
27
export_vars_subst() {
27
28
_evs_pfx=${1}; _evs_pfx_new=${2}; shift 2;
28
29
while [ ${#} -gt 0 ]; do
29
- if [ -n "${_evs_vval:=$(get_var ${_evs_pfx}${1})}" ]; then
30
+ if [ -n "${_evs_vval:=$(get_var_unsafe ${_evs_pfx}${1})}" ]; then
30
31
export "${_evs_pfx_new}${1}=${_evs_vval}";
31
32
fi; unset _evs_vval; shift;
32
33
done; unset _evs_pfx _evs_pfx_new;
33
34
};
34
35
35
36
rm_if_exists() {
36
- set_flag_vars_from_args "$@"; shift ${_sfvfa_nshift:-0};
37
- [ -d ${1} ] && rm -rf ${1}; [ -f ${1} ] && rm -f ${1};
38
- [ ${_arg_m:-0} -eq 1 ] && mkdir ${1};
39
- [ ${_arg_c:-0} -eq 1 ] && cd ${1};
40
- unset_flag_vars_from_args;
41
- };
37
+ [ -z "${1#-m}" ] && { _rie_arg_m=1; shift; };
38
+ [ -z "${1#-c}" ] && { _rie_arg_c=1; shift; };
39
+ [ -d ${1} -o -f ${1} ] && rm -rf ${1};
40
+ [ ${_rie_arg_m:-0} -eq 1 ] && { mkdir ${1}; unset _rie_arg_m; };
41
+ [ ${_rie_arg_c:-0} -eq 1 ] && { cd ${1}; unset _rie_arg_c; };
42
+ return 0;
42
-
43
- set_flag_vars_from_args() {
44
- unset _sfvfa_flag_vars _sfvfa_nshift;
45
- while [ ${#} -gt 1 ]; do
46
- if [ "x${1%[a-z]}" = "x-" ]; then
47
- set_var _arg_${1#-} 1;
48
- _sfvfa_flag_vars="${_sfvfa_flag_vars:+${_sfvfa_flag_vars} }_arg_${1#-}";
49
- : $((_sfvfa_nshift+=1));
50
- fi; shift;
51
- done;
52
- };
53
- unset_flag_vars_from_args() {
54
- set -- ${_sfvfa_flag_vars}; while [ ${#} -gt 0 ]; do
55
- unset ${1}; shift; done; unset _sfvfa_flag_vars _sfvfa_nshift;
56
43
};
57
44
58
45
set_env_vars() {
@@ -78,7 +65,7 @@ apply_patches() {
78
65
# Check whether all supplied arguments contain non-empty valid values.
79
66
check_path_vars() {
80
67
while [ ${#} -gt 0 ]; do
81
- if [ -z "${_cpv_val:=$(get_var "${1}")}" ]; then
68
+ if [ -z "${_cpv_val:=$(get_var_unsafe "${1}")}" ]; then
82
69
log_msg failexit "Error: variable \`${1}' is empty or unset.";
83
70
elif match_any "${_cpv_val}" " "; then
84
71
log_msg failexit "Error: variable \`${1}' contains one or more whitespace characters.";
@@ -104,6 +91,7 @@ clear_env_with_except() {
104
91
_cewe_vfilter="${*}"; _cewe_unset_cmds="$(mktemp -q)";
105
92
export | while read _cewe_vspec; do
106
93
set -- ${_cewe_vspec}; shift;
94
+ [ "x${1#*[^\"\'=a-zA-Z0-9_]}" != "x${1}" ] && continue;
107
95
if ! match_list "${_cewe_vfilter}" " " \
108
96
$(get_prefix_lrg ${1} =); then
109
97
echo unset $(get_prefix_lrg ${1} =) >> ${_cewe_unset_cmds};
@@ -180,7 +168,7 @@ log_env_vars() {
180
168
while [ ${#} -gt 0 ]; do
181
169
log_msg info "$(printf \
182
170
"%${_lev_arg_len_max}.${_lev_arg_len_max}s=%s" \
183
- "${1%%=*}" "$(get_var ${1#*=})")";
171
+ "${1%%=*}" "$(get_var_unsafe ${1#*=})")";
184
172
shift;
185
173
done; unset _lev_arg_len_max;
186
174
};
@@ -208,28 +196,6 @@ match_list() {
208
196
done; unset _ml_cmp; return 1;
209
197
};
210
198
211
- parse_args_into_vars() {
212
- _paiv_arg0="${1}"; _paiv_args_valid="${2}"; shift 2;
213
- while [ $# -gt 0 ]; do
214
- case "${1}" in
215
- --*) _paiv_aname="${1#--}";
216
- if ! match_list "${_paiv_args_valid}" , "${_paiv_aname%%=*}"; then
217
- log_msg failexit "Unknown parameter --${_paiv_aname%%=*} specified.";
218
- elif match_start "${_paiv_aname}" "*="; then
219
- _paiv_aval="$(get_postfix "${_paiv_aname}" =)";
220
- _paiv_aname="$(get_prefix_lrg "${_paiv_aname}" =)";
221
- else
222
- _paiv_aval=1;
223
- fi;
224
- set_var $(echo arg_${_paiv_aname} | tr a-z- A-Z_) "${_paiv_aval}";
225
- shift; ;;
226
- *=*) set_var "$(get_prefix_lrg "${1}" =)"\
227
- "$(get_postfix "${1}" =)"; shift; ;;
228
- *) log_msg failexit "Invalid or unknown command line argument \`${1}'."; ;;
229
- esac;
230
- done; unset _paiv_arg0 _paiv_args_valid _paiv_aname _paiv_aval;
231
- };
232
-
233
199
parse_with_pkg_name() {
234
200
PKG_LVL=${1}; PKG_NAME=${2}; shift 2;
235
201
while [ ${#} -ge 0 ]; do
file modified
+17 -19
build.usage CHANGED
@@ -1,22 +1,20 @@
1
- usage: ./build.sh
2
- [--build-scripts=ALL|fname[,fname...]] [--build-steps=ALL|step[,step...]]
3
- [--help] [--tarball] [VAR=VAL...]
4
- --build-scripts=... Only invoke all or the specified build script(s).
5
- --build-steps=... Forcibly invoke build scripts at all or only the
6
- specified build steps. Currently defined build steps
7
- are: fetch extract patch configure clean build install
8
- configure1 configure2 build1 build2 install1 install2
9
- install3 finish.
10
- --help Show this screen.
1
+ usage: ./build.sh [-r ALL|name[:step]] [-h] [-t]
2
+ -r ALL|name[:step] Restart all or the specified build script(s) completely
3
+ or at the optionally specified build step. Currently defined
4
+ build steps are: fetch extract patch configure clean build
5
+ install configure1 configure2 build1 build2 install1 install2
6
+ install3.
7
+ -h Show this screen.
8
+ -t Produce a distribution tarball containing $PREFIX
9
+ sans $WORKDIR and $PREFIX/src/midipix_build at the end of a
10
+ build with zero failures.
11
- --tarball Produce a distribution tarball containing $PREFIX
12
- sans $WORKDIR at the end of a build with zero failures.
13
11
14
- Packages that are built by pkg.build will apply local patches in $WORKDIR
15
- named ${PKG_SUBDIR}.local.patch.
12
+ Packages that are built by pkg.build will apply local patches in $WORKDIR
13
+ named ${PKG_SUBDIR}.local.patch.
16
14
17
- Examples:
18
- ./build.sh GITROOT_HEAD=... --build-scripts=204.psxscl.build --build-steps=ALL PKG_PSXSCL_CFLAGS=-DPSX_INTERNAL_STRACE
19
- Build psxscl from the internal repository with strace enabled.
15
+ Examples:
16
+ ./build.sh -r psxscl -- GITROOT_HEAD=... PKG_PSXSCL_CFLAGS=-DPSX_INTERNAL_STRACE
17
+ Build psxscl from the internal repository with strace enabled.
20
18
21
- ./build.sh GITROOT_HEAD=... --build-scripts=ALL --build-steps=ALL
22
- Forcibly rebuild everything.
19
+ ./build.sh -r ALL -- GITROOT_HEAD=...
20
+ Forcibly rebuild everything.