From 03a6372afeb96419da89a8100c95366f9ebe68cc 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: Wed, 1 Feb 2017 00:35:43 +0000 Subject: subr/{pkg,pkg_fetch}.subr: merges fetch{,_git}() into pkg_fetch.subr and introduces ${PKG_URLS_GIT}. subr/pkg_extract.subr: only extract if ${PKG_URL} is set. var/build.vars: updated to use ${PKG_URLS_GIT}. vars/{cparser,gcc,libfirm,musl,perl}.vars: updated to call pkg_fetch() instead of fetch{,_git}(). vars/gcc.vars: cleanup pkgp_gcc_setup_env() and pkg_gcc_stage1_all(). --- subr/pkg.subr | 58 +++++++------------------------------- subr/pkg_extract.subr | 3 +- subr/pkg_fetch.subr | 78 ++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 83 insertions(+), 56 deletions(-) (limited to 'subr') diff --git a/subr/pkg.subr b/subr/pkg.subr index da36f35e..2130feb5 100644 --- a/subr/pkg.subr +++ b/subr/pkg.subr @@ -3,59 +3,20 @@ # See warning at the top of build.vars. # -# N.B. URLs ($1) may contain `?' or '&' characters. -fetch() { - _f_url="${1}"; _f_sha256sum_src="${2}"; - _f_url_dst="${DLCACHEDIR}/$(basename "${_f_url}")"; - if [ ${ARG_OFFLINE:-0} -eq 1 ]\ - || [ -e ${_f_url_dst}.fetched ]; then - unset _f_url _f_sha256sum_src _f_url_dst; - return 0; - else - wget ${WGET_ARGS} -c -O ${_f_url_dst} "${_f_url}"; - fi; - if [ -n "${_f_sha256sum_src}" ]; then - set -- $(openssl dgst -sha256 ${_f_url_dst}); shift $((${#}-1)); - if [ "${_f_sha256sum_dst:=${1}}" != "${_f_sha256sum_src}" ]; then - if [ ${ARG_IGNORE_SHA256SUMS:-0} -eq 0 ]; then - log_msg failexit "Error: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)"; - else - log_msg warn "Warning: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)"; - fi; - fi; - fi; - touch ${_f_url_dst}.fetched; - unset _f_url _f_url_dst _f_sha256sum_src _f_sha256sum_dst; -}; - -fetch_git() { - _fg_subdir="${1}"; _fg_url="${2}"; _fg_branch="${3}"; - if [ ${ARG_OFFLINE:-0} -eq 0 ]; then - if [ -e "${DLCACHEDIR}/${_fg_subdir}" ]; then - cd ${DLCACHEDIR}/${_fg_subdir} &&\ - git pull origin ${_fg_branch:-main} && cd ${OLDPWD}; +is_build_script_done() { + if [ "${1}" = "clean" ]; then + if match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC} \ + && [ -n "${ARG_RESTART_AT}" ] \ + && match_list "${ARG_RESTART_AT}" , "${1}"; then + return 1; # Build else - git clone ${_fg_url} ${DLCACHEDIR}/${_fg_subdir}; - if [ -n "${_fg_branch}" -a \ - \( -z "${_fg_branch#main}" \) -a \ - \( -z "${_fg_branch#master}" \) ]; then - cd ${DLCACHEDIR}/${_fg_subdir} &&\ - git checkout -b ${_fg_branch} && cd ${OLDPWD}; - fi; + return 0; # Skip fi; - fi; - secure_rm ${_fg_subdir}; - cp -pr ${DLCACHEDIR}/${_fg_subdir} .; -}; - -is_build_script_done() { - if [ "${1}" != "clean" ]\ - && [ "${ARG_RESTART}" = "ALL" ]; then + elif [ "${ARG_RESTART}" = "ALL" ]; then return 1; # Build elif match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC}; then if [ -n "${ARG_RESTART_AT}" ]; then - if [ "${1}" != "clean" ]\ - && [ "${ARG_RESTART_AT}" = "ALL" ]; then + if [ "${ARG_RESTART_AT}" = "ALL" ]; then return 1; # Build elif match_list "${ARG_RESTART_AT}" , "${1}"; then return 1; # Build @@ -93,6 +54,7 @@ parse_with_pkg_name() { PKG_NAME=${1}; shift; _pwpn_pkg_name_uc=$(echo ${PKG_NAME} | tr a-z A-Z); if [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URL)" ]\ + && [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URLS_GIT)" ]\ && [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_VERSION)" ]; then unset _pwpn_pkg_name_uc; log_msg failexit "Error: package \`${PKG_NAME}' missing in build.vars."; diff --git a/subr/pkg_extract.subr b/subr/pkg_extract.subr index 1bee8835..2b7d4fd4 100644 --- a/subr/pkg_extract.subr +++ b/subr/pkg_extract.subr @@ -4,7 +4,8 @@ # pkg_extract() { - if [ "${PKG_URL_TYPE:-wget}" = wget ]; then + if [ -n "${PKG_URL}" ]\ + && [ "${PKG_URL_TYPE:-wget}" = wget ]; then secure_rm ${PKG_SUBDIR}; if [ ${PKG_SUBDIR_CREATE:-0} -eq 1 ]; then insecure_mkdir ${PKG_SUBDIR}; diff --git a/subr/pkg_fetch.subr b/subr/pkg_fetch.subr index 705e4936..f2653754 100644 --- a/subr/pkg_fetch.subr +++ b/subr/pkg_fetch.subr @@ -3,16 +3,80 @@ # See warning at the top of build.vars. # -pkg_fetch() { - if [ "${PKG_URL_TYPE:-wget}" = wget ]; then - fetch "${PKG_URL}" ${PKG_SHA256SUM}; +# N.B. URLs ($1) may contain `?' or '&' characters. +pkgp_fetch() { + _f_url="${1}"; _f_sha256sum_src="${2}"; + _f_url_dst="${DLCACHEDIR}/$(basename "${_f_url}")"; + if [ ${ARG_OFFLINE:-0} -eq 1 ]\ + || [ -e ${_f_url_dst}.fetched ]; then + unset _f_url _f_sha256sum_src _f_url_dst; + return 0; else - fetch_git ${PKG_SUBDIR} ${PKG_URL} ${PKG_GIT_BRANCH}; + wget ${WGET_ARGS} -c -O ${_f_url_dst} "${_f_url}"; + fi; + if [ -n "${_f_sha256sum_src}" ]; then + set -- $(openssl dgst -sha256 ${_f_url_dst}); shift $((${#}-1)); + if [ "${_f_sha256sum_dst:=${1}}" != "${_f_sha256sum_src}" ]; then + if [ ${ARG_IGNORE_SHA256SUMS:-0} -eq 0 ]; then + log_msg failexit "Error: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)"; + else + log_msg warn "Warning: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)"; + fi; + fi; + fi; + touch ${_f_url_dst}.fetched; + unset _f_url _f_url_dst _f_sha256sum_src _f_sha256sum_dst; +}; + +pkgp_fetch_git() { + _fg_subdir="${1}"; _fg_url="${2}"; _fg_branch="${3}"; + if [ ${ARG_OFFLINE:-0} -eq 0 ]; then + if [ -e "${DLCACHEDIR}/${_fg_subdir}" ]; then + cd ${DLCACHEDIR}/${_fg_subdir} &&\ + git pull origin ${_fg_branch:-main} && cd ${OLDPWD}; + else + git clone ${_fg_url} ${DLCACHEDIR}/${_fg_subdir}; + if [ -n "${_fg_branch}" -a \ + \( -z "${_fg_branch#main}" \) -a \ + \( -z "${_fg_branch#master}" \) ]; then + cd ${DLCACHEDIR}/${_fg_subdir} &&\ + git checkout -b ${_fg_branch} && cd ${OLDPWD}; + fi; + fi; fi; - if test_cmd pkg_${PKG_NAME}_fetch_post; then - pkg_${PKG_NAME}_fetch_post; + secure_rm ${_fg_subdir}; + cp -pr ${DLCACHEDIR}/${_fg_subdir} .; +}; + +pkgp_fetch_urls_git() { + for _ppfu_url_spec in ${1}; do + _ppfu_subdir=${_ppfu_url_spec%=*}; + _ppfu_url=${_ppfu_url_spec#*=}; + _ppfu_url=${_ppfu_url%@*}; + if [ "${_ppfu_url_spec#*@}" != "${_ppfu_url_spec}" ]; then + _ppfu_git_branch=${_ppfu_url_spec#*@}; + fi; + pkgp_fetch_git ${_ppfu_subdir} ${_ppfu_url} ${_ppfu_git_branch}; + done; + unset _ppfu_url_spec _ppfu_subdir _ppfu_url _ppfu_git_branch; +}; + +pkg_fetch() { + if [ -n "${1}" ]; then + if [ "${1}" = "-git" ]; then + shift; pkgp_fetch_urls_git ${1}; + else + pkgp_fetch ${1} ${2}; + fi; + else + if [ -n "${PKG_URL}" ]; then + pkgp_fetch ${PKG_URL} ${PKG_SHA256SUM}; + fi; + if [ -n "${PKG_URLS_GIT}" ]; then + pkgp_fetch_urls_git ${PKG_URLS_GIT}; + fi; + set_build_script_done fetch -extract; fi; - set_build_script_done fetch -extract; }; # vim:filetype=sh -- cgit v1.2.3