From f6f7f2f65712e6fa114f5751a72ad26cd893e92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=ADa=20Andrea=20Illanes=20Albornoz?= Date: Sun, 19 Feb 2023 07:19:26 +0100 Subject: Reject empty variables from the command line. --- build.sh | 10 +++++++--- pkgtool.sh | 13 ++++++++++--- subr.ex/ex_pkg.subr | 25 +++++++++++++++---------- subr.rtl/rtl_platform.subr | 16 ++++++++++++++++ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/build.sh b/build.sh index 5235f48f..0733a4f8 100755 --- a/build.sh +++ b/build.sh @@ -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}"; diff --git a/pkgtool.sh b/pkgtool.sh index 6b0ad0f3..65a4a84a 100755 --- a/pkgtool.sh +++ b/pkgtool.sh @@ -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=""; -- cgit v1.2.3