[Fuego] [PATCH] Add a core function: assert_has_program().
Tim.Bird at sony.com
Tim.Bird at sony.com
Wed Oct 17 21:30:37 UTC 2018
Thanks for working on this.
This was a bit more complicated of an solution that I expected.
Some feedback below...
> -----Original Message-----
> From: Wang Mingyu
>
> This function is used to combine the code that check whether a program or
> file exists, from 2 lines into a single function call.
> Called like so:
> assert_has_program expect
>
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
> engine/scripts/functions.sh | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/engine/scripts/functions.sh b/engine/scripts/functions.sh
> index ff7b272..fe236c4 100644
> --- a/engine/scripts/functions.sh
> +++ b/engine/scripts/functions.sh
> @@ -961,3 +961,28 @@ function is_on_sdk {
> export $2=$LOCATION
> rm -f $tmpfile
> }
> +
> +# check for a program or file on the target, and send message if the
> program or file is missing
> +# $1 - file, dir or program on target
It looks like what you've done is copied is_on_target, (which is OK), but
it would have been better, IMHO to just re-use is_on_target_path (without copying it).
> +function assert_has_program {
> + # FIXTHIS: race condition
> + tmpfile=$(mktemp /tmp/found_loc.XXXXXX)
> + cmd "touch $tmpfile"
> + if [ -z "$PATH" ] ; then
$PATH is the path on the host, not on the board.
> + safe_cmd "find / -name \"$1\" | head -n 1 >$tmpfile"
> + else
> + # split search path on colon
> + for d in $(echo "$PATH" | tr ":" "\n") ; do
> + # execute a command on the target to detect $d/$1
> + cmd "if [ -z \"\$(cat $tmpfile)\" -a -e \"$d/$1\" ] ; then echo \"$d/$1\"
> >$tmpfile ; fi"
> + done
> + fi
> + get $tmpfile $tmpfile
> + varname=$(cat $tmpfile)
> + cmd "rm $tmpfile"
> + rm -f $tmpfile # -f for tests running on the host
> + if [ -z "$varname" ]
> + then
> + abort_job "$1 is not defined. Missing '$1' program on target board"
> + fi
> +}
> --
> 1.8.3.1
I think this can be simplified to something like this:
I haven't tested this.
#$1 has the program that is required on the target board
# this has the side effect of defining PROGRAM_$1 (uppercased)
# with the value as the directory where $1 is found on the board.
function assert_has_program {
upName="$(echo "$1" | tr '.' '_')"
progVar="PROGRAM_${upName}"
is_on_target_path $1 ${!progVAR}
assert_define ${!progVar} "Missing '$1' program on target board"
}
Can you try this approach and let me know if it works?
-- Tim
More information about the Fuego
mailing list