core/pkg-download: change all helpers to use common options

Currently all download helpers accepts the local output file, the remote
locations, the changesets and so on... as positional arguments.

This was well and nice when that's was all we needed.

But then we added an option to quiesce their verbosity, and that was
shoehorned with a trivial getopts, still keeping all the existing
positional arguments as... positional arguments.

Adding yet more options while keeping positional arguments will not be
very easy, even if we do not envision any new option in the foreseeable
future (but 640K ought to be enough for everyone, remember? ;-) ).

Change all helpers to accept a set of generic options (-q for quiet and
-o for the output file) as well as helper-specific options (like -r for
the repository, -c for a changeset...).

Maxime:
Changed -R to -r for recurse (only for the git backend)
Changed -r to -u for URI (for all backend)
Change -R to -c for cset (for CVS and SVN backend)
Add the export of the BR_BACKEND_DL_GETOPTS so all the backend wrapper
can use the same option easily
Now all the backends use the same common options.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Maxime Hadjinlian <maxime.hadjinlian@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
Yann E. MORIN 2018-04-02 10:14:22 +02:00 committed by Peter Korsgaard
parent f03cf639cf
commit 91e776b5af
10 changed files with 131 additions and 109 deletions

View File

@ -77,9 +77,9 @@ define DOWNLOAD_GIT
-H $(PKGDIR)/$($(PKG)_RAWNAME).hash \ -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
$(QUIET) \ $(QUIET) \
-- \ -- \
$($(PKG)_SITE) \ -u $($(PKG)_SITE) \
$($(PKG)_DL_VERSION) \ -c $($(PKG)_DL_VERSION) \
$($(PKG)_BASENAME_RAW) \ -n $($(PKG)_BASENAME_RAW) \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -88,9 +88,9 @@ define DOWNLOAD_BZR
-o $(DL_DIR)/$($(PKG)_SOURCE) \ -o $(DL_DIR)/$($(PKG)_SOURCE) \
$(QUIET) \ $(QUIET) \
-- \ -- \
$($(PKG)_SITE) \ -u $($(PKG)_SITE) \
$($(PKG)_DL_VERSION) \ -c $($(PKG)_DL_VERSION) \
$($(PKG)_BASENAME_RAW) \ -n $($(PKG)_BASENAME_RAW) \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -99,10 +99,10 @@ define DOWNLOAD_CVS
-o $(DL_DIR)/$($(PKG)_SOURCE) \ -o $(DL_DIR)/$($(PKG)_SOURCE) \
$(QUIET) \ $(QUIET) \
-- \ -- \
$(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) \ -u $(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) \
$($(PKG)_DL_VERSION) \ -c $($(PKG)_DL_VERSION) \
$($(PKG)_RAWNAME) \ -N $($(PKG)_RAWNAME) \
$($(PKG)_BASENAME_RAW) \ -n $($(PKG)_BASENAME_RAW) \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -111,9 +111,9 @@ define DOWNLOAD_SVN
-o $(DL_DIR)/$($(PKG)_SOURCE) \ -o $(DL_DIR)/$($(PKG)_SOURCE) \
$(QUIET) \ $(QUIET) \
-- \ -- \
$($(PKG)_SITE) \ -u $($(PKG)_SITE) \
$($(PKG)_DL_VERSION) \ -c $($(PKG)_DL_VERSION) \
$($(PKG)_BASENAME_RAW) \ -n $($(PKG)_BASENAME_RAW) \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -126,7 +126,7 @@ define DOWNLOAD_SCP
-H $(PKGDIR)/$($(PKG)_RAWNAME).hash \ -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
$(QUIET) \ $(QUIET) \
-- \ -- \
'$(call stripurischeme,$(call qstrip,$(1)))' \ -u '$(call stripurischeme,$(call qstrip,$(1)))' \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -135,9 +135,9 @@ define DOWNLOAD_HG
-o $(DL_DIR)/$($(PKG)_SOURCE) \ -o $(DL_DIR)/$($(PKG)_SOURCE) \
$(QUIET) \ $(QUIET) \
-- \ -- \
$($(PKG)_SITE) \ -u $($(PKG)_SITE) \
$($(PKG)_DL_VERSION) \ -c $($(PKG)_DL_VERSION) \
$($(PKG)_BASENAME_RAW) \ -n $($(PKG)_BASENAME_RAW) \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -147,7 +147,7 @@ define DOWNLOAD_WGET
-H $(PKGDIR)/$($(PKG)_RAWNAME).hash \ -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
$(QUIET) \ $(QUIET) \
-- \ -- \
'$(call qstrip,$(1))' \ -u '$(call qstrip,$(1))' \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef
@ -157,7 +157,7 @@ define DOWNLOAD_LOCALFILES
-H $(PKGDIR)/$($(PKG)_RAWNAME).hash \ -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
$(QUIET) \ $(QUIET) \
-- \ -- \
$(call stripurischeme,$(call qstrip,$(1))) \ -u $(call stripurischeme,$(call qstrip,$(1))) \
$($(PKG)_DL_OPTS) $($(PKG)_DL_OPTS)
endef endef

View File

@ -5,28 +5,31 @@ set -e
# Download helper for bzr, to be called from the download wrapper script # Download helper for bzr, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../bzr [-q] OUT_FILE REPO_URL REV BASENAME # -q Be quiet
# -o FILE Generate archive in FILE.
# -u URI Clone from repository at URI.
# -c CSET Use changeset (or revision) CSET.
# -n NAME Use basename NAME.
# #
# Environment: # Environment:
# BZR : the bzr command to call # BZR : the bzr command to call
verbose= verbose=
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-q;; q) verbose=-q;;
o) output="${OPTARG}";;
u) uri="${OPTARG}";;
c) cset="${OPTARG}";;
n) basename="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
repo="${2}"
rev="${3}"
basename="${4}"
shift 4 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)
@ -51,5 +54,5 @@ if [ ${bzr_version} -ge ${bzr_min_version} ]; then
fi fi
_bzr export ${verbose} --root="'${basename}/'" --format=tgz \ _bzr export ${verbose} --root="'${basename}/'" --format=tgz \
${timestamp_opt} - "${@}" "'${repo}'" -r "'${rev}'" \ ${timestamp_opt} - "${@}" "'${uri}'" -r "'${cset}'" \
>"${output}" >"${output}"

View File

@ -5,8 +5,10 @@ set -e
# Download helper for cp, to be called from the download wrapper script # Download helper for cp, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../cp [-q] OUT_FILE SRC_FILE # -q Be quiet.
# -o FILE Copy to file FILE.
# -u FILE Copy from file FILE.
# #
# Environment: # Environment:
# LOCALFILES: the cp command to call # LOCALFILES: the cp command to call
@ -17,18 +19,17 @@ set -e
# Make 'cp' verbose by default, so it behaves a bit like the others. # Make 'cp' verbose by default, so it behaves a bit like the others.
verbose=-v verbose=-v
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=;; q) verbose=;;
o) output="${OPTARG}";;
u) source="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
source="${2}"
shift 2 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)

View File

@ -5,28 +5,32 @@ set -e
# Download helper for cvs, to be called from the download wrapper script # Download helper for cvs, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../cvs [-q] OUT_FILE CVS_URL REV PKG_NAME BASENAME # -q Be quiet
# -o FILE Generate archive in FILE.
# -u URI Checkout from repository at URI.
# -c REV Use revision REV.
# -N RAWNAME Use rawname (aka module name) RAWNAME.
# -n NAME Use basename NAME.
# #
# Environment: # Environment:
# CVS : the cvs command to call # CVS : the cvs command to call
verbose= verbose=
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-Q;; q) verbose=-Q;;
o) output="${OPTARG}";;
u) uri="${OPTARG}";;
c) rev="${OPTARG}";;
N) rawname="${OPTARG}";;
n) basename="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
repo="${2}"
rev="${3}"
rawname="${4}"
basename="${5}"
shift 5 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)
@ -42,14 +46,14 @@ else
select="-r" select="-r"
fi fi
# The absence of an initial : on ${repo} means access method undefined # The absence of an initial : on ${uri} means access method undefined
if [[ ! "${repo}" =~ ^: ]]; then if [[ ! "${uri}" =~ ^: ]]; then
# defaults to anonymous pserver # defaults to anonymous pserver
repo=":pserver:anonymous@${repo}" uri=":pserver:anonymous@${uri}"
fi fi
export TZ=UTC export TZ=UTC
_cvs ${verbose} -z3 -d"'${repo}'" \ _cvs ${verbose} -z3 -d"'${uri}'" \
co "${@}" -d "'${basename}'" ${select} "'${rev}'" -P "'${rawname}'" co "${@}" -d "'${basename}'" ${select} "'${rev}'" -P "'${rawname}'"
tar czf "${output}" "${basename}" tar czf "${output}" "${basename}"

View File

@ -19,6 +19,8 @@
# We want to catch any unexpected failure, and exit immediately. # We want to catch any unexpected failure, and exit immediately.
set -e set -e
export BR_BACKEND_DL_GETOPTS=":hc:o:n:N:H:ru:q"
main() { main() {
local OPT OPTARG local OPT OPTARG
local backend output hfile recurse quiet rc local backend output hfile recurse quiet rc
@ -83,7 +85,10 @@ main() {
# If the backend fails, we can just remove the temporary directory to # If the backend fails, we can just remove the temporary directory to
# remove all the cruft it may have left behind. Then we just exit in # remove all the cruft it may have left behind. Then we just exit in
# error too. # error too.
if ! "${OLDPWD}/support/download/${backend}" ${quiet} ${recurse} "${tmpf}" "${@}"; then if ! "${OLDPWD}/support/download/${backend}" \
${quiet} ${recurse} \
-o "${tmpf}" "${@}"
then
rm -rf "${tmpd}" rm -rf "${tmpd}"
exit 1 exit 1
fi fi

View File

@ -5,32 +5,33 @@ set -e
# Download helper for git, to be called from the download wrapper script # Download helper for git, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../git [-q] [-r] OUT_FILE REPO_URL CSET BASENAME # -q Be quiet.
# # -r Clone and archive sub-modules.
# -q Be quiet. # -o FILE Generate archive in FILE.
# -r Clone and archive sub-modules. # -u URI Clone from repository at URI.
# -c CSET Use changeset CSET.
# -n NAME Use basename NAME.
# #
# Environment: # Environment:
# GIT : the git command to call # GIT : the git command to call
verbose= verbose=
recurse=0 recurse=0
while getopts :qr OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-q; exec >/dev/null;; q) verbose=-q; exec >/dev/null;;
r) recurse=1;; r) recurse=1;;
o) output="${OPTARG}";;
u) uri="${OPTARG}";;
c) cset="${OPTARG}";;
n) basename="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
repo="${2}"
cset="${3}"
basename="${4}"
shift 4 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)
@ -46,9 +47,9 @@ _git() {
# Messages for the type of clone used are provided to ease debugging in case of # Messages for the type of clone used are provided to ease debugging in case of
# problems # problems
git_done=0 git_done=0
if [ -n "$(_git ls-remote "'${repo}'" "'${cset}'" 2>&1)" ]; then if [ -n "$(_git ls-remote "'${uri}'" "'${cset}'" 2>&1)" ]; then
printf "Doing shallow clone\n" printf "Doing shallow clone\n"
if _git clone ${verbose} "${@}" --depth 1 -b "'${cset}'" "'${repo}'" "'${basename}'"; then if _git clone ${verbose} "${@}" --depth 1 -b "'${cset}'" "'${uri}'" "'${basename}'"; then
git_done=1 git_done=1
else else
printf "Shallow clone failed, falling back to doing a full clone\n" printf "Shallow clone failed, falling back to doing a full clone\n"
@ -56,7 +57,7 @@ if [ -n "$(_git ls-remote "'${repo}'" "'${cset}'" 2>&1)" ]; then
fi fi
if [ ${git_done} -eq 0 ]; then if [ ${git_done} -eq 0 ]; then
printf "Doing full clone\n" printf "Doing full clone\n"
_git clone ${verbose} "${@}" "'${repo}'" "'${basename}'" _git clone ${verbose} "${@}" "'${uri}'" "'${basename}'"
fi fi
pushd "${basename}" >/dev/null pushd "${basename}" >/dev/null

View File

@ -5,27 +5,30 @@ set -e
# Download helper for hg, to be called from the download wrapper script # Download helper for hg, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../hg [-q] OUT_FILE REPO_URL CSET BASENAME # -q Be quiet.
# -o FILE Generate archive in FILE.
# -u URI Clone from repository at URI.
# -c CSET Use changeset (or revision) CSET.
# -n NAME Use basename NAME.
# #
# Environment: # Environment:
# HG : the hg command to call # HG : the hg command to call
verbose= verbose=
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-q;; q) verbose=-q;;
o) output="${OPTARG}";;
u) uri="${OPTARG}";;
c) cset="${OPTARG}";;
n) basename="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
repo="${2}"
cset="${3}"
basename="${4}"
shift 4 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)
@ -33,7 +36,7 @@ _hg() {
eval ${HG} "${@}" eval ${HG} "${@}"
} }
_hg clone ${verbose} "${@}" --noupdate "'${repo}'" "'${basename}'" _hg clone ${verbose} "${@}" --noupdate "'${uri}'" "'${basename}'"
_hg archive ${verbose} --repository "'${basename}'" --type tgz \ _hg archive ${verbose} --repository "'${basename}'" --type tgz \
--prefix "'${basename}'" --rev "'${cset}'" \ --prefix "'${basename}'" --rev "'${cset}'" \

View File

@ -5,25 +5,26 @@ set -e
# Download helper for scp, to be called from the download wrapper script # Download helper for scp, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../scp [-q] OUT_FILE SRC_URL # -q Be quiet.
# -o FILE Copy to local file FILE.
# -u FILE Copy from remote file FILE.
# #
# Environment: # Environment:
# SCP : the scp command to call # SCP : the scp command to call
verbose= verbose=
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-q;; q) verbose=-q;;
o) output="${OPTARG}";;
u) uri="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
url="${2}"
shift 2 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)
@ -31,4 +32,4 @@ _scp() {
eval ${SCP} "${@}" eval ${SCP} "${@}"
} }
_scp ${verbose} "${@}" "'${url}'" "'${output}'" _scp ${verbose} "${@}" "'${uri}'" "'${output}'"

View File

@ -5,27 +5,30 @@ set -e
# Download helper for svn, to be called from the download wrapper script # Download helper for svn, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../svn [-q] OUT_FILE REPO_URL REV BASNAME # -q Be quiet.
# -o FILE Generate archive in FILE.
# -u URI Checkout from repository at URI.
# -c REV Use revision REV.
# -n NAME Use basename NAME.
# #
# Environment: # Environment:
# SVN : the svn command to call # SVN : the svn command to call
verbose= verbose=
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-q;; q) verbose=-q;;
o) output="${OPTARG}";;
u) uri="${OPTARG}";;
c) rev="${OPTARG}";;
n) basename="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
repo="${2}"
rev="${3}"
basename="${4}"
shift 4 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)
@ -33,6 +36,6 @@ _svn() {
eval ${SVN} "${@}" eval ${SVN} "${@}"
} }
_svn export ${verbose} "${@}" "'${repo}@${rev}'" "'${basename}'" _svn export ${verbose} "${@}" "'${uri}@${rev}'" "'${basename}'"
tar czf "${output}" "${basename}" tar czf "${output}" "${basename}"

View File

@ -5,25 +5,26 @@ set -e
# Download helper for wget, to be called from the download wrapper script # Download helper for wget, to be called from the download wrapper script
# #
# Call it as: # Options:
# .../wget [-q] OUT_FILE URL # -q Be quiet.
# -o FILE Save into file FILE.
# -u URL Download file at URL.
# #
# Environment: # Environment:
# WGET : the wget command to call # WGET : the wget command to call
verbose= verbose=
while getopts :q OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) verbose=-q;; q) verbose=-q;;
o) output="${OPTARG}";;
u) url="${OPTARG}";;
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
esac esac
done done
shift $((OPTIND-1))
output="${1}" shift $((OPTIND-1)) # Get rid of our options
url="${2}"
shift 2 # Get rid of our options
# Caller needs to single-quote its arguments to prevent them from # Caller needs to single-quote its arguments to prevent them from
# being expanded a second time (in case there are spaces in them) # being expanded a second time (in case there are spaces in them)