summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz <lucio@lucioillanes.de>2021-04-06 11:26:11 +0100
committerLucio Andrés Illanes Albornoz <lucio@lucioillanes.de>2021-04-06 11:26:11 +0100
commit2c5ce2e826a8af69d14429ea4da158bf94d31ca7 (patch)
tree97c90e082a90c8c617960cdae71a6e3dffbdfc97
parent360eb692689993886cc8c5e471e73c76dcfaa123 (diff)
downloadmidipix_build-2c5ce2e826a8af69d14429ea4da158bf94d31ca7.tar.bz2
midipix_build-2c5ce2e826a8af69d14429ea4da158bf94d31ca7.tar.xz
pkgtool.sh:pkgtoolp_mirror_fetch(): call pkg_fetch_download_clean_dlcache() post-{archive,Git} mirroring.
pkgtool.sh:pkgtoolp_mirror_fetch(): mirror both archive as well as Git URL(s). subr/pkg_configure_patch.subr:pkg_configure_patch(): apply patches from within ${PKG_BASE_DIR} given both ${PKG_FNAME} and ${PKG_URLS_GIT}. subr.rtl/rtl_fetch.subr:rtl_fetch_mirror_urls_git(): ignore all but last component in ${_subdir}. subr.rtl/rtl_fetch.subr:rtl_fetch_mirror_urls_git(): create prerequisite directories. subr.rtl/rtl_fetch.subr:rtlp_fetch_url_git(): ignore all but last component in ${_subdir} wrt. ${_cache_dlname}. subr.rtl/rtl_fetch.subr:rtlp_fetch_url_git(): create prerequisite directories wrt. ${_tgtdir}. subr/ex_pkg_env.subr:exp_pkg_env_defaults(): reject absence of ${PKG_SUBDIR} given both ${PKG_FNAME} and ${PKG_URLS_GIT}. subr/pkg_fetch_download.subr:pkg_fetch_download_clean_dlcache(): initial implementation. subr/pkg_fetch_download.subr:pkg_fetch_download(): call pkg_fetch_download_clean_dlcache() post-{archive,Git} download.
-rwxr-xr-xpkgtool.sh28
-rw-r--r--subr.rtl/rtl_fetch.subr32
-rw-r--r--subr/ex_pkg_env.subr5
-rw-r--r--subr/pkg_configure_patch.subr11
-rw-r--r--subr/pkg_fetch_download.subr35
5 files changed, 71 insertions, 40 deletions
diff --git a/pkgtool.sh b/pkgtool.sh
index 1b4da524..950595ed 100755
--- a/pkgtool.sh
+++ b/pkgtool.sh
@@ -79,7 +79,8 @@ pkgtoolp_mirror() {
pkgtoolp_mirror_fetch() {
local _mirror_dname="${1}" _mirror_dname_git="${2}" _pkg_name="${3}" _pkg_name_real="${4}"\
- _fname="" _pkg_disabled=0 _pkg_fname="" _pkg_sha256sum="" _pkg_url="" _rc=0;
+ _fname="" _pkg_disabled=0 _pkg_fname="" _pkg_sha256sum="" _pkg_url="" _pkg_urls_git=""\
+ _rc=0;
if _pkg_disabled="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_DISABLED")"\
&& [ "${_pkg_disabled:-0}" -eq 1 ]; then
@@ -103,35 +104,34 @@ pkgtoolp_mirror_fetch() {
|| ! rtl_fetch_url_wget "${_pkg_url}" "${_pkg_sha256sum}" "${_mirror_dname}/${_pkg_name}" "${_pkg_fname}" "${_pkg_name_real}" ""; then
_rc=1; rtl_log_msg warning "Failed to mirror package \`%s', skipping." "${_pkg_name}";
else
- for _fname in $(find \
- "${_mirror_dname}/${_pkg_name}" \
- -type f \
- -not -name "${_pkg_fname}" \
- -not -name "${_pkg_fname}.fetched"); do
- rtl_log_msg notice "Deleting redundant file \`%s' for package \`%s'." "${_fname}" "${_pkg_name}";
- rtl_fileop rm "${_fname}";
- done;
+ pkg_fetch_download_clean_dlcache "${_mirror_dname}" "${_pkg_name}" "${_pkg_fname}" "${_pkg_urls_git}";
fi;
fi;
- elif _pkg_url="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_URLS_GIT")"; then
+ fi;
+ if _pkg_urls_git="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_URLS_GIT")"; then
if [ -z "${_mirror_dname_git}" ]; then
_rc=0; rtl_log_msg notice "Git URL(s) mirroring disabled, skipping \`%s'." "${_pkg_name}";
elif [ "$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_MIRRORS_GIT")" = "skip" ]; then
_rc=0; rtl_log_msg notice "Package \`%s' specifies to skip Git URL(s) mirroring, skipping." "${_pkg_name}";
elif [ "${_pkg_name}" != "${_pkg_name_real}" ]; then
- rtl_log_msg info "Mirroring package \`%s' (parent package: \`%s'), Git URL(s): \`%s'..." "${_pkg_name}" "${_pkg_name_real}" "${_pkg_url}";
+ rtl_log_msg info "Mirroring package \`%s' (parent package: \`%s'), Git URL(s): \`%s'..." "${_pkg_name}" "${_pkg_name_real}" "${_pkg_urls_git}";
if ! rtl_fileop ln_symbolic "${_pkg_name_real}" "${_mirror_dname_git}/${_pkg_name}"; then
_rc=1; rtl_log_msg warning "Failed to create symbolic link \`%s' for package \`%s' w/ parent package \`%s'."\
"${_mirror_dname_git}/${_pkg_name}" "${_pkg_name}" "${_pkg_name_real}";
fi;
else
- rtl_log_msg info "Mirroring package \`%s', Git URL(s): \`%s'..." "${_pkg_name}" "${_pkg_url}";
+ rtl_log_msg info "Mirroring package \`%s', Git URL(s): \`%s'..." "${_pkg_name}" "${_pkg_urls_git}";
if ! rtl_fileop mkdir "${_mirror_dname_git}/${_pkg_name}"\
- || ! rtl_fetch_mirror_urls_git "${DEFAULT_GIT_ARGS}" "${_mirror_dname_git}/${_pkg_name}" ${_pkg_url}; then
+ || ! rtl_fetch_mirror_urls_git "${DEFAULT_GIT_ARGS}" "${_mirror_dname_git}/${_pkg_name}" ${_pkg_urls_git}; then
_rc=1; rtl_log_msg warning "Failed to mirror package \`%s', skipping." "${_pkg_name}";
+ else
+ pkg_fetch_download_clean_dlcache "${_mirror_dname_git}" "${_pkg_name}" "${_pkg_fname}" "${_pkg_urls_git}";
fi;
fi;
- else
+ fi;
+ if [ -z "${_pkg_url}" ]\
+ && [ -z "${_pkg_sha256sum}" ]\
+ && [ -z "${_pkg_urls_git}" ]; then
_rc=0; rtl_log_msg notice "Package \`%s' has neither archive nor Git URL(s), skipping." "${_pkg_name}";
fi;
fi; return "${_rc}";
diff --git a/subr.rtl/rtl_fetch.subr b/subr.rtl/rtl_fetch.subr
index 1b230b9d..f5410e30 100644
--- a/subr.rtl/rtl_fetch.subr
+++ b/subr.rtl/rtl_fetch.subr
@@ -6,8 +6,12 @@ rtl_fetch_mirror_urls_git() {
local _git_args="${1}" _tgtdir="${2}" _rc=0 _repo_dname="" _subdir="" _url="" _url_spec=""; shift 2;
for _url_spec in "${@}"; do
- _subdir="${_url_spec%=*}"; _url="${_url_spec#*=}"; _url="${_url%@*}";
+ _subdir="${_url_spec%=*}"; _subdir="${_subdir##*/}"; _url="${_url_spec#*=}"; _url="${_url%@*}";
_repo_dname="${_url##*/}"; [ "${_repo_dname%.git}" = "${_repo_dname}" ] && _repo_dname="${_repo_dname}.git";
+
+ if [ ! -e "$(rtl_dirname "${_tgtdir}")" ]; then
+ rtl_fileop mkdir "$(rtl_dirname "${_tgtdir}")";
+ fi;
(set -o errexit -o noglob -o nounset;
rtl_flock_acquire 4 || exit "${?}";
trap "rm -f \"${_tgtdir}/.fetching\"" EXIT;
@@ -23,22 +27,23 @@ rtl_fetch_mirror_urls_git() {
rtlp_fetch_url_git() {
local _cache_dname="${1}" _git_args="${2}" _git_branch="${3}" _mirrors="${4}" _pkg_name="${5}"\
- _subdir="${6}" _tgtdir="${7}" _url="${8}" _clonefl=0 _oldpwd="" _url_base="";
+ _subdir="${6}" _tgtdir="${7}" _url="${8}" _cache_dname_full="" _clonefl=0 _oldpwd="" _url_base="";
+ _cache_dname_full="${_cache_dname}/${_subdir##*/}";
(set -o errexit -o noglob -o nounset;
rtl_flock_acquire 4 || exit "${?}";
- trap "rm -f \"${_cache_dname}/${_subdir%%[/]}.fetching\"" EXIT;
- if [ -e "${_cache_dname}/${_subdir}" ]; then
- (rtl_fileop cd "${_cache_dname}/${_subdir}" &&\
+ trap "rm -f \"${_cache_dname_full%%[/]}.fetching\"" EXIT;
+ if [ -e "${_cache_dname_full}" ]; then
+ (rtl_fileop cd "${_cache_dname_full}" &&\
git pull ${_git_args} origin "${_git_branch:-main}") || return 1;
- (rtl_fileop cd "${_cache_dname}/${_subdir}" &&\
+ (rtl_fileop cd "${_cache_dname_full}" &&\
git submodule update) || return 1;
- else if git clone ${_git_args} -b "${_git_branch:-main}" "${_url}" "${_cache_dname}/${_subdir}"; then
+ else if git clone ${_git_args} -b "${_git_branch:-main}" "${_url}" "${_cache_dname_full}"; then
_clonefl=1;
elif [ "${_mirrors}" = "skip" ]; then
return 1;
else for _url_base in ${_mirrors}; do
- if git clone ${_git_args} -b "${_git_branch:-main}" "${_url_base}/${_pkg_name}/${_url##*/}" "${_cache_dname}/${_subdir}"; then
+ if git clone ${_git_args} -b "${_git_branch:-main}" "${_url_base}/${_pkg_name}/${_url##*/}" "${_cache_dname_full}"; then
_clonefl=1; break;
fi;
done;
@@ -46,19 +51,22 @@ rtlp_fetch_url_git() {
if [ "${_clonefl}" -eq 0 ]; then
return 1;
else if [ -n "${_git_branch}" ]; then
- (rtl_fileop cd "${_cache_dname}/${_subdir}" &&\
+ (rtl_fileop cd "${_cache_dname_full}" &&\
git checkout "${_git_branch}") || return 1;
fi;
- (rtl_fileop cd "${_cache_dname}/${_subdir}" &&\
+ (rtl_fileop cd "${_cache_dname_full}" &&\
git submodule update --init) || return 1;
fi;
fi;
if [ "${_cache_dname}" != "${_tgtdir}" ]; then
_oldpwd="${PWD}"; rtl_fileop cd "${_tgtdir}" || return 1;
rtl_fileop rm "${_tgtdir}/${_subdir}" || return 1;
- rtl_fileop cp "${_cache_dname}/${_subdir}" "${_tgtdir}" || return 1;
+ if [ ! -e "$(rtl_dirname "${_tgtdir}/${_subdir}")" ]; then
+ rtl_fileop mkdir "$(rtl_dirname "${_tgtdir}/${_subdir}")";
+ fi;
+ rtl_fileop cp "${_cache_dname_full}" "${_tgtdir}/${_subdir}" || return 1;
rtl_fileop cd "${_oldpwd}" || return 1;
- fi) 4<>"${_cache_dname}/${_subdir%%[/]}.fetching";
+ fi) 4<>"${_cache_dname_full%%[/]}.fetching";
if [ "${?}" -eq 0 ]; then
cd "$(pwd)";
diff --git a/subr/ex_pkg_env.subr b/subr/ex_pkg_env.subr
index ff2338e1..ebfb8f46 100644
--- a/subr/ex_pkg_env.subr
+++ b/subr/ex_pkg_env.subr
@@ -24,7 +24,10 @@ exp_pkg_env_defaults() {
: ${PKG_FNAME:="${PKG_URL##*/}"};
fi;
if [ -z "${PKG_SUBDIR:-}" ]; then
- if [ -n "${PKG_URLS_GIT:-}" ]; then
+ if [ -n "${PKG_URLS_GIT:-}" ]\
+ && [ -n "${PKG_FNAME:-}" ]; then
+ rtl_log_msg fatalexit "Error: \${PKG_SUBDIR} must be specified given both \${PKG_FNAME} and \${PKG_URLS_GIT}.";
+ elif [ -n "${PKG_URLS_GIT:-}" ]; then
PKG_SUBDIR="${PKG_URLS_GIT%%=*}";
else case "${PKG_FNAME:-}" in
*.t*) PKG_SUBDIR="${PKG_FNAME%%.t*}"; ;;
diff --git a/subr/pkg_configure_patch.subr b/subr/pkg_configure_patch.subr
index 6b4bcdd3..b789a80e 100644
--- a/subr/pkg_configure_patch.subr
+++ b/subr/pkg_configure_patch.subr
@@ -3,8 +3,15 @@
#
pkg_configure_patch() {
- local _patch_dir="${MIDIPIX_BUILD_PWD}/patches" _patch_fname="" \
+ local _patch_cwd="" _patch_dir="${MIDIPIX_BUILD_PWD}/patches" _patch_fname=""\
_patches_done="" _pkg_name_full="${PKG_NAME}${PKG_VERSION:+-${PKG_VERSION}}";
+
+ if [ -n "${PKG_FNAME}" ]\
+ && [ -n "${PKG_URLS_GIT}" ]; then
+ _patch_cwd="${PKG_BASE_DIR}";
+ else
+ _patch_cwd="${PKG_BASE_DIR}/${PKG_SUBDIR}";
+ fi;
set +o noglob;
for _patch_fname in \
"${_patch_dir}/${_pkg_name}/"*.patch \
@@ -13,7 +20,7 @@ pkg_configure_patch() {
${PKG_PATCHES_EXTRA:-}; do
if [ -r "${_patch_fname}" ]\
&& ! rtl_lmatch "${_patches_done}" "${_patch_fname}"; then
- if ! patch -b -d "${PKG_BASE_DIR}/${PKG_SUBDIR}" -p1 < "${_patch_fname}"; then
+ if ! patch -b -d "${_patch_cwd}" -p1 < "${_patch_fname}"; then
set -o noglob; return 1;
else
_patches_done="$(rtl_lconcat "${_patches_done}" "${_patch_fname}")";
diff --git a/subr/pkg_fetch_download.subr b/subr/pkg_fetch_download.subr
index 188c7f7b..2b94d720 100644
--- a/subr/pkg_fetch_download.subr
+++ b/subr/pkg_fetch_download.subr
@@ -2,6 +2,29 @@
# set +o errexit -o noglob -o nounset is assumed.
#
+pkg_fetch_download_clean_dlcache() {
+ local _dlcachedir="${1}" _pkg_name="${2}" _pkg_fname="${3}" _pkg_urls_git="${4}"\
+ _fname="" _pkg_urls_git_dname="";
+
+ if [ -n "${_pkg_urls_git}" ]; then
+ _pkg_urls_git_dname="${_pkg_urls_git%%=*}";
+ _pkg_urls_git_dname="${_pkg_urls_git_dname##*/}";
+ fi;
+ for _fname in $(cd "${_dlcachedir}/${_pkg_name}" && find \
+ -mindepth 1 \
+ -not -name "${_pkg_fname}" \
+ -not -name "${_pkg_fname}.fetched" \
+ ${_pkg_urls_git_dname:+ \
+ -not -path "./${_pkg_urls_git_dname}" \
+ -not -path "./${_pkg_urls_git_dname}/*" \
+ -not -path "./${_pkg_urls_git_dname}.git" \
+ -not -path "./${_pkg_urls_git_dname}.git/*"}); do
+ _fname="${_dlcachedir}/${_pkg_name}/${_fname#./}"
+ rtl_log_msg notice "Deleting redundant file \`%s' for package \`%s'." "${_fname}" "${_pkg_name}";
+ rtl_fileop rm "${_fname}";
+ done;
+};
+
pkg_fetch_download_dlcache_subdir() {
if [ -n "${PKG_INHERIT_FROM:-}" ]\
&& ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\
@@ -17,8 +40,6 @@ pkg_fetch_download_dlcache_subdir() {
};
pkg_fetch_download() {
- local _fname="";
-
if [ "${ARG_FETCH_FORCE:-}" != "offline" ]; then
if [ -n "${PKG_URL:-}" ]; then
if ! pkg_fetch_download_dlcache_subdir; then
@@ -27,15 +48,6 @@ pkg_fetch_download() {
"${PKG_URL}" "${PKG_SHA256SUM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"\
"${PKG_FNAME}" "${PKG_NAME}" "${PKG_MIRRORS:-}"; then
return 1;
- else
- for _fname in $(find \
- "${BUILD_DLCACHEDIR}/${PKG_NAME}" \
- -type f \
- -not -name "${PKG_FNAME}" \
- -not -name "${PKG_FNAME}.fetched"); do
- rtl_log_msg notice "Deleting redundant file \`%s' for package \`%s'." "${_fname}" "${PKG_NAME}";
- rtl_fileop rm "${_fname}";
- done;
fi;
fi;
if [ -n "${PKG_URLS_GIT:-}" ]; then
@@ -47,6 +59,7 @@ pkg_fetch_download() {
return 1;
fi;
fi;
+ pkg_fetch_download_clean_dlcache "${BUILD_DLCACHEDIR}" "${PKG_NAME}" "${PKG_FNAME}" "${PKG_URLS_GIT}";
fi;
};