forked from kiss-community/kiss
kiss: sources improvements
- Moved download code to function. Can now explore supporting different download tools (to remove hard curl lock-in). - Added two hooks, pre-source and post-source. These hooks allow for obtainment of verbatim and resolved sources (as well as absolute paths to sources on disk). - Other small improvements.
This commit is contained in:
parent
387a1dc30f
commit
c2aa4b4ab6
46
kiss
46
kiss
@ -332,6 +332,8 @@ pkg_source_resolve() {
|
|||||||
# path to the source if it already exists, error if not.
|
# path to the source if it already exists, error if not.
|
||||||
ok "${2##\#*}" || { _res=; return; }
|
ok "${2##\#*}" || { _res=; return; }
|
||||||
|
|
||||||
|
unset _des
|
||||||
|
|
||||||
# Surround each replacement with substitutions to handled escaped markers.
|
# Surround each replacement with substitutions to handled escaped markers.
|
||||||
# First substitution turns '\MARKER' into ' ' (can't appear in sources as
|
# First substitution turns '\MARKER' into ' ' (can't appear in sources as
|
||||||
# they're already split on whitespace), second replaces 'MARKER' with its
|
# they're already split on whitespace), second replaces 'MARKER' with its
|
||||||
@ -392,31 +394,49 @@ pkg_source() {
|
|||||||
[ -f "$repo_dir/sources" ] || return 0
|
[ -f "$repo_dir/sources" ] || return 0
|
||||||
|
|
||||||
log "$1" "Reading sources"
|
log "$1" "Reading sources"
|
||||||
mkcd "$src_dir/$1"
|
|
||||||
|
|
||||||
while read -r src dest || ok "$src"; do
|
while read -r src dest || ok "$src"; do
|
||||||
pkg_source_resolve "$1" "$src" "$dest" "$2"
|
pkg_source_resolve "$1" "$src" "$dest" "$2"
|
||||||
|
|
||||||
case $_res in url+*)
|
# arg1: pre-source
|
||||||
log "$1" "Downloading ${_res##url+}"
|
# arg2: package name
|
||||||
mkdir -p "$PWD/$dest"
|
# arg3: verbatim source
|
||||||
|
# arg4: resolved source
|
||||||
|
run_hook pre-source "$1" "$src" "$_fnr"
|
||||||
|
|
||||||
curl -fLo "$_des" "${_res##url+}" || {
|
case $_res in url+*)
|
||||||
rm -f "$_des"
|
# Create directory structure in source cache. This prevents cache
|
||||||
die "$1" "Failed to download ${_res##url+}"
|
# conflicts between identical sources with differing dests.
|
||||||
}
|
mkcd "${_des%/*}"
|
||||||
|
|
||||||
|
pkg_source_get "${_res##url+}" "$_des"
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# arg1: post-source
|
||||||
|
# arg2: package name
|
||||||
|
# arg3: verbatim source
|
||||||
|
# arg4: resolved source
|
||||||
|
run_hook post-source "$1" "$src" "${_des:-"$_res"}"
|
||||||
done < "$repo_dir/sources"
|
done < "$repo_dir/sources"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pkg_source_get() {
|
||||||
|
log "$repo_name" "Downloading $1"
|
||||||
|
|
||||||
|
curl -fLo "$2" "$1" || {
|
||||||
|
rm -f "$2"
|
||||||
|
die "$repo_name" "Failed to download $1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pkg_source_git() {
|
pkg_source_git() {
|
||||||
# This magic will shallow clone branches, commits or the
|
# This magic will shallow clone branches, commits or the
|
||||||
# regular repository. It correctly handles cases where a
|
# regular repository. It correctly handles cases where a
|
||||||
# shallow clone is not possible.
|
# shallow clone is not possible.
|
||||||
log "$repo_name" "Cloning ${1##git+}"
|
log "$repo_name" "Cloning $1"
|
||||||
|
|
||||||
# Split the source into URL + OBJECT (branch or commit).
|
# Split the source into URL + OBJECT (branch or commit).
|
||||||
url=${1##git+} com=${url##*[@#]} com=${com#${url%[#@]*}}
|
url=$1 com=${url##*[@#]} com=${com#${url%[#@]*}}
|
||||||
|
|
||||||
git init
|
git init
|
||||||
git remote add origin "${url%[#@]*}"
|
git remote add origin "${url%[#@]*}"
|
||||||
@ -424,7 +444,7 @@ pkg_source_git() {
|
|||||||
git -c advice.detachedHead=0 checkout "${com:-FETCH_HEAD}"
|
git -c advice.detachedHead=0 checkout "${com:-FETCH_HEAD}"
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_source_tar_hack() {
|
pkg_source_tar() {
|
||||||
# This is a portable shell implementation of GNU tar's
|
# This is a portable shell implementation of GNU tar's
|
||||||
# '--strip-components 1'. Use of this function denotes a
|
# '--strip-components 1'. Use of this function denotes a
|
||||||
# performance penalty.
|
# performance penalty.
|
||||||
@ -494,11 +514,11 @@ pkg_extract() {
|
|||||||
|
|
||||||
case $_res in
|
case $_res in
|
||||||
git+*)
|
git+*)
|
||||||
pkg_source_git "$_res"
|
pkg_source_git "${_res##git+}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*.tar|*.tar.??|*.tar.???|*.tar.????|*.t?z)
|
*.tar|*.tar.??|*.tar.???|*.tar.????|*.t?z)
|
||||||
pkg_source_tar_hack "$_res"
|
pkg_source_tar "$_res"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*.zip)
|
*.zip)
|
||||||
|
Loading…
Reference in New Issue
Block a user