@@ -8,15 +8,15 @@ 
 ################################################################################
 
 # Download method commands
-export CURL := $(call qstrip,$(BR2_CURL))
-export WGET := $(call qstrip,$(BR2_WGET))
-export SVN := $(call qstrip,$(BR2_SVN))
-export CVS := $(call qstrip,$(BR2_CVS))
-export BZR := $(call qstrip,$(BR2_BZR))
-export GIT := $(call qstrip,$(BR2_GIT))
-export HG := $(call qstrip,$(BR2_HG))
-export SCP := $(call qstrip,$(BR2_SCP))
-export SFTP := $(call qstrip,$(BR2_SFTP))
+CURL := $(call qstrip,$(BR2_CURL))
+WGET := $(call qstrip,$(BR2_WGET))
+SVN := $(call qstrip,$(BR2_SVN))
+CVS := $(call qstrip,$(BR2_CVS))
+BZR := $(call qstrip,$(BR2_BZR))
+GIT := $(call qstrip,$(BR2_GIT))
+HG := $(call qstrip,$(BR2_HG))
+SCP := $(call qstrip,$(BR2_SCP))
+SFTP := $(call qstrip,$(BR2_SFTP))
 export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
 
 # Version of the format of the archives we generate in the corresponding
@@ -132,6 +132,15 @@  define DOWNLOAD
 		$(if $($(PKG)_GIT_SUBMODULES),-r) \
 		$(if $($(PKG)_GIT_LFS),-l) \
 		$(foreach uri,$(call DOWNLOAD_URIS,$(1),$(PKG)),-u $(uri)) \
+		-C '$(CURL)' \
+		-C '$(WGET)' \
+		-C '$(SVN)' \
+		-C '$(CVS)' \
+		-C '$(BZR)' \
+		-C '$(GIT)' \
+		-C '$(HG)' \
+		-C '$(SCP)' \
+		-C '$(SFTP)' \
 		$(2) \
 		$(QUIET) \
 		-- \
@@ -11,9 +11,7 @@  set -e
 #   -u URI      Clone from repository at URI.
 #   -c CSET     Use changeset (or revision) CSET.
 #   -n NAME     Use basename NAME.
-#
-# Environment:
-#   BZR      : the bzr command to call
+#   -C          The bzr command to call.
 
 
 quiet=
@@ -24,6 +22,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     u)  uri="${OPTARG}";;
     c)  cset="${OPTARG}";;
     n)  basename="${OPTARG}";;
+    C)  BZR="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -10,9 +10,7 @@  set -e
 #   -o FILE     Save into file FILE.
 #   -f FILENAME The filename of the tarball to get at URL
 #   -u URL      Download file at URL.
-#
-# Environment:
-#   CURL     : the curl command to call
+#   -C          The curl command to call.
 
 quiet=
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
@@ -21,6 +19,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     o)  output="${OPTARG}";;
     f)  filename="${OPTARG}";;
     u)  url="${OPTARG}";;
+    C)  CURL="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -12,9 +12,7 @@  set -e
 #   -c REV      Use revision REV.
 #   -N RAWNAME  Use rawname (aka module name) RAWNAME.
 #   -n NAME     Use basename NAME.
-#
-# Environment:
-#   CVS      : the cvs command to call
+#   -C          The cvs command to call.
 
 quiet=
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
@@ -25,6 +23,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     c)  rev="${OPTARG}";;
     N)  rawname="${OPTARG}";;
     n)  basename="${OPTARG}";;
+    C)  CVS="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -20,17 +20,34 @@  set -e
 # shellcheck source=helpers source-path=SCRIPTDIR
 . "${0%/*}/helpers"
 
-export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:lru:qf:e"
+export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:C:N:H:lru:qf:e"
+
+dl_cmd() {
+    local match_cmd="$1"
+    shift
+    local cmds=("$@")
+
+    for cmd in "${cmds[@]}"; do
+        _cmd=$(echo "$cmd" | awk '{print $1}')
+        if [[ "$_cmd" == "$match_cmd" ]]; then
+            echo "$cmd"
+            return 0
+        fi
+    done
+
+    return 1
+}
 
 main() {
     local OPT OPTARG
-    local backend output large_file recurse quiet rc
-    local -a uris hfiles backend_opts post_process_opts
+    local backend backend_dl_cmd output large_file recurse quiet rc
+    local -a uris hfiles backend_opts post_process_opts dl_cmds
 
     # Parse our options; anything after '--' is for the backend
-    while getopts ":c:d:D:o:n:N:H:lrf:u:qp:P:" OPT; do
+    while getopts ":c:d:D:o:n:C:N:H:lrf:u:qp:P:" OPT; do
         case "${OPT}" in
         c)  cset="${OPTARG}";;
+        C)  dl_cmds+=( "${OPTARG}" );;
         d)  dl_dir="${OPTARG}";;
         D)  old_dl_dir="${OPTARG}";;
         o)  output="${OPTARG}";;
@@ -101,6 +118,7 @@  main() {
         esac
         uri=${uri#*+}
 
+        backend_dl_cmd=$(dl_cmd "${backend}" "${dl_cmds[@]}")
         urlencode=${backend_urlencode#*|}
         # urlencode must be "urlencode"
         [ "${urlencode}" != "urlencode" ] && urlencode=""
@@ -134,6 +152,7 @@  main() {
         # cleanup and exit.
         if ! "${OLDPWD}/support/download/${backend}" \
                 -c "${cset}" \
+                -C "${backend_dl_cmd}" \
                 -d "${dl_dir}" \
                 -n "${raw_base_name}" \
                 -N "${base_name}" \
@@ -17,9 +17,7 @@  set -e
 #   -u URI      Clone from repository at URI.
 #   -c CSET     Use changeset CSET.
 #   -n NAME     Use basename NAME.
-#
-# Environment:
-#   GIT      : the git command to call
+#   -C          The git command to call.
 
 # shellcheck disable=SC1090 # Only provides mk_tar_gz()
 # shellcheck disable=SC1091
@@ -65,6 +63,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     c)  cset="${OPTARG}";;
     d)  dl_dir="${OPTARG}";;
     n)  basename="${OPTARG}";;
+    C)  GIT="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -11,9 +11,7 @@  set -e
 #   -u URI      Clone from repository at URI.
 #   -c CSET     Use changeset (or revision) CSET.
 #   -n NAME     Use basename NAME.
-#
-# Environment:
-#   HG       : the hg command to call
+#   -C          The hg command to call.
 
 quiet=
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
@@ -23,6 +21,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     u)  uri="${OPTARG}";;
     c)  cset="${OPTARG}";;
     n)  basename="${OPTARG}";;
+    C)  HG="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -10,9 +10,7 @@  set -e
 #   -o FILE     Copy to local file FILE.
 #   -f FILE     Copy from remote file FILE.
 #   -u URI      Download file at URI.
-#
-# Environment:
-#   SCP       : the scp command to call
+#   -C          The scp command to call.
 
 quiet=
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
@@ -21,6 +19,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     o)  output="${OPTARG}";;
     f)  filename="${OPTARG}";;
     u)  uri="${OPTARG}";;
+    C)  SCP="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -10,9 +10,7 @@  set -e
 #   -o FILE     Copy to local file FILE.
 #   -f FILE     Copy from remote file FILE.
 #   -u URI      Download file at URI.
-#
-# Environment:
-#   SFTP      : the sftp command to call
+#   -C          The sftp command to call.
 
 quiet=
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
@@ -21,6 +19,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     o)  output="${OPTARG}";;
     f)  filename="${OPTARG}";;
     u)  uri="${OPTARG}";;
+    C)  SFTP="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -17,9 +17,7 @@  set -e
 #   -c REV      Use revision REV.
 #   -n NAME     Use basename NAME.
 #   -r          Recursive, i.e. use externals
-#
-# Environment:
-#   SVN      : the svn command to call
+#   -C          The svn command to call.
 
 # shellcheck disable=SC1090 # Only provides mk_tar_gz()
 # shellcheck disable=SC1091
@@ -35,6 +33,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     c)  rev="${OPTARG}";;
     n)  basename="${OPTARG}";;
     r)  externals=;;
+    C)  SVN="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
@@ -11,9 +11,7 @@  set -e
 #   -f FILENAME The filename of the tarball to get at URL
 #   -u URL      Download file at URL.
 #   -e ENCODE   Tell wget to urlencode the filename passed to it
-#
-# Environment:
-#   WGET     : the wget command to call
+#   -C          The wget command to call.
 
 quiet=
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
@@ -23,6 +21,7 @@  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     f)  filename="${OPTARG}";;
     u)  url="${OPTARG}";;
     e)  encode="-e";;
+    C)  WGET="${OPTARG}";;
     :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
     \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
     esac
 
  
Exporting the download variables can cause unfortunate name clashes, as occurred with the SCP variable used by Binman for compiling U-Boot [1]. The patch removes the global export of the variables containing the commands used for downloading the packages and passes them as parameters, using the new -C option, to the dl-wrapper, which in turn passes the appropriate download command to the specific script under the support/download directory. [1] https://lore.kernel.org/buildroot/a023971c7c8bfa4826a9a8721500c7ff@free.fr/T/ Cc: Julien Olivain <ju.o@free.fr> Suggested-by: Peter Korsgaard <peter@korsgaard.com> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> --- package/pkg-download.mk | 27 ++++++++++++++++++--------- support/download/bzr | 5 ++--- support/download/curl | 5 ++--- support/download/cvs | 5 ++--- support/download/dl-wrapper | 27 +++++++++++++++++++++++---- support/download/git | 5 ++--- support/download/hg | 5 ++--- support/download/scp | 5 ++--- support/download/sftp | 5 ++--- support/download/svn | 5 ++--- support/download/wget | 5 ++--- 11 files changed, 59 insertions(+), 40 deletions(-)