[Fuego] [PATCH 4/9] functions: fix preference order when unpacking or cloning
Bird, Timothy
Tim.Bird at sony.com
Wed Nov 8 04:31:52 UTC 2017
This one's going to take me a bit more time to review and test.
I don't want to commit something in the core without more
thorough testing than I have time for right now.
I'll try to get this in tomorrow (or give feedback on it.)
-- Tim
> -----Original Message-----
> From: fuego-bounces at lists.linuxfoundation.org [mailto:fuego-
> bounces at lists.linuxfoundation.org] On Behalf Of Daniel Sangorrin
> Sent: Monday, November 06, 2017 11:21 PM
> To: fuego at lists.linuxfoundation.org
> Subject: [Fuego] [PATCH 4/9] functions: fix preference order when
> unpacking or cloning
>
> In the previous implementation the preference was
> spec tarball > fuego_test tarball > spec gitrepo > fuego_test gitrepo
>
> This patch changes it to
> spec gitrepo > spec tarball > fuego_test gitrepo > fuego_test tarball
>
> Therefore, spec.json gitrepo/tarball variables take precedence over
> fuego_test.sh variables. And if, for some reason, gitrepo and
> tarball variables are defined at the same time, then gitrepo will
> take precedence. This case is not supposed to happen though.
>
> Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
> ---
> engine/scripts/functions.sh | 137 ++++++++++++++++++++++++++----------
> --------
> 1 file changed, 82 insertions(+), 55 deletions(-)
>
> diff --git a/engine/scripts/functions.sh b/engine/scripts/functions.sh
> index da3415b..fe27b0c 100755
> --- a/engine/scripts/functions.sh
> +++ b/engine/scripts/functions.sh
> @@ -38,72 +38,99 @@ trap signal_handler SIGTERM SIGHUP SIGALRM
> SIGINT EXIT
> # cause ERR trap setting to be visible inside functions
> set -o errtrace
>
> -# Unpacks/clones the test source code into the current directory.
> -#
> -# Tarball or git variables can be in the spec or directly in fuego_test.sh
> -# Variables in the spec have preference.
> -#
> -# Tarball variables
> -# - tarball: tarball file name (e.g. bc-script.tar.gz)
> -# Git variables
> -# - gitrepo: git repository (e.g. https://github.com/torvalds/linux.git)
> -# - gitref: git branch, tag or commit id (optional, default: master)
> -function unpack {
> - # Tarballs
> - upName=`echo "${TESTDIR^^}"| tr '.' '_'`
> - spec_tarball="${upName}_TARBALL"
> -
> - if [ ! -z "${!spec_tarball}" ]; then
> - tarball=${!spec_tarball}
> +# Clones a git repository into the current folder
> +# $1 (gitrepo): git repository URL
> +# $2 (gitref): branch, tag or commit id (optional, default: master)
> +# FIXTHIS: add commit id information to the json output
> +function git_clone {
> + local gitrepo=${1}
> + local gitref=${2}
> +
> + is_empty "$gitrepo"
> +
> + if [ -z "$gitref" ]; then
> + gitref="master"
> fi
>
> - if [ ! -z ${tarball+x} ]; then
> - echo "Unpacking $tarball"
> - case ${tarball/*./} in
> - gz|tgz) key=z ;;
> - bz2) key=j ;;
> - tar) key= ;;
> - *) echo "Unknown $tarball file format. Not unpacking."; return 1;;
> - esac
> - tar ${key}xf $TEST_HOME/$tarball --strip-components=1
> - return
> + local is_namedref=$(git ls-remote $gitrepo $gitref)
> +
> + if [ "$is_namedref" = "" ]; then
> + echo "Clone repository $gitrepo."
> + git clone -n $gitrepo fuego_git_repo
> + else
> + echo "Clone repository $gitrepo."
> + git clone -n --depth=1 --branch=$gitref $gitrepo fuego_git_repo
> fi
>
> - # GIT repositories
> - spec_gitrepo="${upName}_GITREPO"
> - spec_gitref="${upName}_GITREF"
> + # equivalent to tarball's --strip-components=1
> + mv fuego_git_repo/.git .git
> + rm -rf fuego_git_repo
>
> - if [ ! -z "${!spec_gitrepo}" ]; then
> - gitrepo=${!spec_gitrepo}
> - fi
> + echo "Checkout branch/tag/commit id $gitref."
> + git checkout $gitref
> +}
>
> - if [ ! -z "${!spec_gitref}" ]; then
> - gitref=${!spec_gitref}
> - fi
> +# Untars a tarball in the current folder
> +# $1 (tarball): file to untar
> +function untar {
> + local tarball=${1}
>
> - # FIXTHIS: add commit id information to the json output
> - if [ ! -z ${gitrepo+x} ]; then
> - if [ -z ${gitref+x} ]; then
> - gitref="master"
> - fi
> + is_empty "$tarball"
>
> - is_namedref=$(git ls-remote $gitrepo $gitref)
> + echo "Unpacking $tarball"
> + case ${tarball/*./} in
> + gz|tgz) key=z ;;
> + bz2) key=j ;;
> + tar) key= ;;
> + *) echo "Unknown $tarball file format. Not unpacking."; return 1;;
> + esac
> + tar ${key}xf $TEST_HOME/$tarball --strip-components=1
> +}
>
> - if [ "$is_namedref" = "" ]; then
> - echo "Clone repository $gitrepo."
> - git clone -n $gitrepo fuego_git_repo
> +# Unpacks/clones the test source code into the current directory.
> +#
> +# The following tarball and git variables can be specified in the test's
> +# spec.json or fuego_test.sh.
> +# - Tarball variables
> +# - tarball: tarball file name (e.g. bc-script.tar.gz)
> +# - Git variables
> +# - gitrepo: git repository (e.g. https://github.com/torvalds/linux.git)
> +# - gitref: git branch, tag or commit id (optional, default: master)
> +#
> +# tarball and git variables follow the next preference rule:
> +# spec gitrepo > spec tarball > fuego_test gitrepo > fuego_test tarball
> +function unpack {
> + # prepare variables
> + upName=`echo "${TESTDIR^^}"| tr '.' '_'`
> + spec_gitrepo="${upName}_GITREPO"
> + spec_gitref="${upName}_GITREF"
> + spec_tarball="${upName}_TARBALL"
> + # 1) spec gitrepo
> + if [ ! -z "${!spec_gitrepo}" ]; then
> + gitrepo=${!spec_gitrepo}
> + if [ ! -z "${!spec_gitref}" ]; then
> + gitref=${!spec_gitref}
> else
> - echo "Clone repository $gitrepo."
> - git clone -n --depth=1 --branch=$gitref $gitrepo fuego_git_repo
> + # gitref could have been defined by fuego_test.sh
> + gitref="master"
> fi
> -
> - # equivalent to tarball's --strip-components=1
> - mv fuego_git_repo/.git .git
> - rm -rf fuego_git_repo
> -
> - echo "Checkout branch/tag/commit id $gitref."
> - git checkout $gitref
> -
> + git_clone "$gitrepo" "$gitref"
> + return
> + fi
> + # 2) spec tarball
> + if [ ! -z "${!spec_tarball}" ]; then
> + tarball=${!spec_tarball}
> + untar "$tarball"
> + return
> + fi
> + # 3) fuego_test gitrepo
> + if [ ! -z "$gitrepo" ]; then
> + git_clone "$gitrepo" "$gitref"
> + return
> + fi
> + # 4) fuego_test tarball
> + if [ ! -z "$tarball" ]; then
> + untar "$tarball"
> return
> fi
>
> --
> 2.7.4
>
>
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego
More information about the Fuego
mailing list