diff options
author | Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de> | 2023-02-19 07:19:26 +0100 |
---|---|---|
committer | Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de> | 2023-02-19 07:19:26 +0100 |
commit | f6f7f2f65712e6fa114f5751a72ad26cd893e92f (patch) | |
tree | 28c2a2fed19f853670059a2d1d243dda6c7e8273 | |
parent | 703de4a1f2032064f1505eb50f1aac63f3c3cfab (diff) | |
download | midipix_build-f6f7f2f65712e6fa114f5751a72ad26cd893e92f.tar.bz2 midipix_build-f6f7f2f65712e6fa114f5751a72ad26cd893e92f.tar.xz |
Reject empty variables from the command line.
-rwxr-xr-x | build.sh | 10 | ||||
-rwxr-xr-x | pkgtool.sh | 13 | ||||
-rw-r--r-- | subr.ex/ex_pkg.subr | 25 | ||||
-rw-r--r-- | subr.rtl/rtl_platform.subr | 16 |
4 files changed, 48 insertions, 16 deletions
@@ -75,7 +75,7 @@ buildp_init() { "${_bi_rstatus}" "buildp_init_getopts_fn" \ "${_bi_optstring}" "${@}" \ || ! ex_init_logging "${_bi_rstatus}" \$ARG_VERBOSE_TAGS "${ARG_VERBOSE}" \ - || ! ex_pkg_load_vars "${_bi_rstatus}" \ + || ! ex_pkg_load_vars "${_bi_rstatus}" \$ARCH \$BUILD_KIND \$PREFIX \ || ! ex_init_prereqs "${_bi_rstatus}" "${DEFAULT_PREREQS}" \ || ! buildp_init_args "${_bi_rstatus}" \ || ! ex_init_files \ @@ -266,7 +266,8 @@ buildp_init_getopts_fn() { ;; nonopt) - local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}"; + local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}" \ + _bpigf_vname="" _bpigf_vval=""; shift 2; if rtl_match "${1}" "=*"; then @@ -276,7 +277,9 @@ buildp_init_getopts_fn() { fi; case "${_bpigf_arg}" in - *=*) rtl_set_var_unsafe "${_bpigf_arg%%=*}" "${_bpigf_arg#*=}"; ;; + *=*) rtl_set_var_from_cmdline "${_bpigf_rstatus}" "${_bpigf_arg}"; + _bpigf_rc="${?}"; + ;; [!a-zA-Z]*) _bpigf_rc=1; rtl_setrstatus "${_bpigf_rstatus}" 'build group names must start with [a-zA-Z] (in argument \`'"${_bpigf_arg}"''\''.)'; @@ -472,6 +475,7 @@ build() { if ! buildp_init \$_status "${@}"; then _rc=0; + _status="Error: ${_status}"; else buildp_time_init; rtl_log_msg "build_begin" "${MSG_build_begin}" "${BUILD_USER}" "${BUILD_HNAME}" "${BUILD_DATE_START}"; @@ -29,7 +29,8 @@ pkgtoolp_init() { "${_pi_rstatus}" "pkgtoolp_init_getopts_fn" \ "${_pi_optstring}" "${@}" \ || ! ex_init_prereqs "${_pi_rstatus}" "${_pi_prereqs}" \ - || ! ex_pkg_load_vars "${_pi_rstatus}" \ + || ! ex_pkg_load_vars \ + "${_pi_rstatus}" \$ARCH \$BUILD_KIND \$PREFIX \ || ! pkgtoolp_init_args "${_pi_rstatus}"; then _pi_rc=1; @@ -112,10 +113,16 @@ pkgtoolp_init_getopts_fn() { shift 2; case "${1}" in - *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; + *=*) rtl_set_var_from_cmdline "${_ppigf_rstatus}" "${1}"; + _ppigf_rc="${?}"; ;; *) PKGTOOL_PKG_NAME="${1}"; ;; esac; - _ppigf_shiftfl=1; + + if [ "${_ppigf_rc}" -ne 0 ]; then + return "${_ppigf_rc}"; + else + _ppigf_shiftfl=1; + fi; ;; done) diff --git a/subr.ex/ex_pkg.subr b/subr.ex/ex_pkg.subr index 6a5670be..f88836a9 100644 --- a/subr.ex/ex_pkg.subr +++ b/subr.ex/ex_pkg.subr @@ -100,22 +100,27 @@ ex_pkg_get_packages() { # # ex_pkg_load_vars() - load build variables -# @_rstatus: out reference to status string +# @_rstatus: out reference to status string +# @_rbuild_arch: in reference to build architecture +# @_rbuild_kind: in reference to build kind +# @_rprefix: in reference to absolute pathname to top-level prefix # # Return: zero (0) on success, non-zero (>0) on failure, build variables post-return on success. # ex_pkg_load_vars() { - local _eplv_rstatus="${1#\$}" \ - _eplv_rc=0 _eplv_fname=""; + local _eplv_rstatus="${1#\$}" _eplv_rbuild_arch="${2#\$}" \ + _eplv_rbuild_kind="${3#\$}" _eplv_rprefix="${4#\$}" \ + _eplv_build_arch="" _eplv_rc=0 _eplv_fname=""; - if ! rtl_lmatch \$ARCH "nt32 nt64"; then + if ! rtl_lmatch "${_eplv_rbuild_arch}" "nt32 nt64"; then _eplv_rc=1; - rtl_setrstatus "${_eplv_rstatus}" 'Error: invalid architecture \`'"${ARCH}"''\''.'; - elif ! rtl_lmatch \$BUILD_KIND "debug release"; then + rtl_setrstatus "${_eplv_rstatus}" 'invalid architecture \`${'"${_eplv_rbuild_arch}"'}'\''.'; + elif ! rtl_lmatch "${_eplv_rbuild_kind}" "debug release"; then _eplv_rc=1; - rtl_setrstatus "${_eplv_rstatus}" 'Error: unknown build type \`'"${BUILD_KIND}"''\''.'; + rtl_setrstatus "${_eplv_rstatus}" 'unknown build type \`${'"${_eplv_rbuild_kind}"'}'\''.'; else - case "${ARCH}" in + eval _eplv_build_arch="\${${_eplv_rbuild_arch}}"; + case "${_eplv_build_arch}" in nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; esac; @@ -131,9 +136,9 @@ ex_pkg_load_vars() { fi; done; - if [ "${PREFIX:+1}" != 1 ]; then + if eval [ \"\${${_eplv_rprefix}:+1}\" != 1 ]; then _eplv_rc=1; - rtl_setrstatus "${_eplv_rstatus}" 'Error: ${PREFIX} empty or unset.'; + rtl_setrstatus "${_eplv_rstatus}" '\${PREFIX} empty or unset.'; fi; fi; diff --git a/subr.rtl/rtl_platform.subr b/subr.rtl/rtl_platform.subr index 365d09eb..c5027d5f 100644 --- a/subr.rtl/rtl_platform.subr +++ b/subr.rtl/rtl_platform.subr @@ -144,6 +144,22 @@ rtl_run_cmd_unsplit() { return ${_rrcu_rc}; }; +rtl_set_var_from_cmdline() { + local _rsvfc_rstatus="${1#\$}" _rsvfc_arg="${2}" \ + _rsvfc_rc=0 _rsvfc_vname="" _rsvfc_vval=""; + + _rsvfc_vname="${_rsvfc_arg%%=*}"; + _rsvfc_vval="${_rsvfc_arg#*=}"; + + if [ "${_rsvfc_vval:+1}" != 1 ]; then + _rsvfc_rc=1; + rtl_setrstatus "${_rsvfc_rstatus}" 'empty value specified for \${'"${_rsvfc_vname}"'}.'; + else + rtl_set_var_unsafe "${_rsvfc_vname}" "${_rsvfc_vval}"; + fi; + return "${_rsvfc_rc}"; +}; + rtl_set_vars() { local _rsv_vars_set_vname="${1}" _rsv_vname_dst="${2}" _rsv_vname_src_tmpls="${3}" \ _rsv_vars_set_old="" _rsv_vars_set_tmp="" _rsv_vname_src="" _rsv_vnames_src=""; |