root/build-tools/build-wheels/utils.sh
Don Penney f36db7e207 Fix use of 'let -i' in scripts
Unlike "declare -i" and "local -i", the bash "let" does not support a
"-i" option. Rather, it takes it as a variable reference. If no "i"
variable is defined in scope, it does not cause an issue. If "i" has
been defined somewhere, however, it may cause a syntax issue, as the i
is evaluated.

A recent update to build-stx-images.sh added a loop that defines an
"i" variable without limiting its scope. In a current image build,
this loop ends with having "i" defined as a URL. As a result, a
"syntax error in expression" occurs, causing the "with_retries"
function to fail to increment the counter. Should a build error occur,
the "with_retries" will never hit the retry limit, looping until it
has a successful result.

This update removes the -i from all "let -i" occurrences in the build
scripts.

Change-Id: I34ad49f8872a81659ff4caf8087b256ea9fb3d32
Closes-Bug: 1891189
Signed-off-by: Don Penney <don.penney@windriver.com>
2020-08-11 10:36:43 -04:00

45 lines
960 B
Bash

#!/bin/bash
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Image and wheel build utility functions
#
#
# Function to call a command, with support for retries
#
function with_retries {
local max_attempts=$1
local cmd=$2
# Pop the first two arguments off the list,
# so we can pass additional args to the command safely
shift 2
local -i attempt=0
while :; do
let attempt++
echo "Running: ${cmd} $@"
${cmd} "$@"
if [ $? -eq 0 ]; then
return 0
fi
echo "Command (${cmd}) failed, attempt ${attempt} of ${max_attempts}."
if [ ${attempt} -lt ${max_attempts} ]; then
local delay=5
echo "Waiting ${delay} seconds before retrying..."
sleep ${delay}
continue
else
echo "Max command attempts reached. Aborting..."
return 1
fi
done
}