libmakepkg: implement extendable source protocols

Lookup the existence of matching functions for each protocol, and
fallback on the generic file handler. New source protocols can then be
added via thirdparty libmakepkg drop-ins without requiring modifications
to source.sh

Fixes FS#49076

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Eli Schwartz 2018-05-28 23:30:29 -04:00 committed by Allan McRae
parent ac0e21a6df
commit 9c817b6549
5 changed files with 30 additions and 37 deletions

View file

@ -59,26 +59,11 @@ download_sources() {
pushd "$SRCDEST" &>/dev/null pushd "$SRCDEST" &>/dev/null
local proto=$(get_protocol "$netfile") local proto=$(get_protocol "$netfile")
case "$proto" in if declare -f download_$proto > /dev/null; then
local) download_$proto "$netfile"
download_local "$netfile" else
;; download_file "$netfile"
bzr) fi
(( get_vcs )) && download_bzr "$netfile"
;;
git)
(( get_vcs )) && download_git "$netfile"
;;
hg)
(( get_vcs )) && download_hg "$netfile"
;;
svn)
(( get_vcs )) && download_svn "$netfile"
;;
*)
download_file "$netfile"
;;
esac
popd &>/dev/null popd &>/dev/null
done done
@ -92,22 +77,10 @@ extract_sources() {
for netfile in "${all_sources[@]}"; do for netfile in "${all_sources[@]}"; do
local file=$(get_filename "$netfile") local file=$(get_filename "$netfile")
local proto=$(get_protocol "$netfile") local proto=$(get_protocol "$netfile")
case "$proto" in if declare -f extract_$proto > /dev/null; then
bzr) extract_$proto "$netfile"
extract_bzr "$netfile" else
;; extract_file "$file"
git) fi
extract_git "$netfile"
;;
hg)
extract_hg "$netfile"
;;
svn)
extract_svn "$netfile"
;;
*)
extract_file "$file"
;;
esac
done done
} }

View file

@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh"
download_bzr() { download_bzr() {
# abort early if parent says not to fetch
if declare -p get_vcs > /dev/null 2>&1; then
(( get_vcs )) || return
fi
local netfile=$1 local netfile=$1
local url=$(get_url "$netfile") local url=$(get_url "$netfile")

View file

@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh"
download_git() { download_git() {
# abort early if parent says not to fetch
if declare -p get_vcs > /dev/null 2>&1; then
(( get_vcs )) || return
fi
local netfile=$1 local netfile=$1
local dir=$(get_filepath "$netfile") local dir=$(get_filepath "$netfile")

View file

@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh"
download_hg() { download_hg() {
# abort early if parent says not to fetch
if declare -p get_vcs > /dev/null 2>&1; then
(( get_vcs )) || return
fi
local netfile=$1 local netfile=$1
local dir=$(get_filepath "$netfile") local dir=$(get_filepath "$netfile")

View file

@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh"
download_svn() { download_svn() {
# abort early if parent says not to fetch
if declare -p get_vcs > /dev/null 2>&1; then
(( get_vcs )) || return
fi
local netfile=$1 local netfile=$1
local fragment=${netfile#*#} local fragment=${netfile#*#}