From 0661c748809e0f87b717ab4b2292ed7ca644d926 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 2 Jul 2018 15:59:24 -0700 Subject: [PATCH] build-system: add travis_wait shell functions These come originally from https://github.com/travis-ci/travis-build and are available when running on Travis, but not when running inside a Docker container on Travis as we do in order to build for Android. The goal is to provide a quasi heart-beat on STDOUT during very long running commands - without this the wget to download Qt often times out, so that's where we are going to use this. Signed-off-by: Dirk Hohndel --- scripts/travis-wait.sh | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/travis-wait.sh diff --git a/scripts/travis-wait.sh b/scripts/travis-wait.sh new file mode 100644 index 000000000..b1b0f1d81 --- /dev/null +++ b/scripts/travis-wait.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# SPDX-Copyright: Copyright (c) 2016 Travis CI GmbH +# +# this is based on code from https://github.com/travis-ci/travis-build + +travis_wait() { + local timeout=$1 + + if [[ $timeout =~ ^[0-9]+$ ]]; then + # looks like an integer, so we assume it is a timeout + shift + else + # default value + timeout=20 + fi + + local cmd="$@" + local log_file=travis_wait_$$.log + + $cmd &>$log_file & + local cmd_pid=$! + + travis_jigger $! $timeout $cmd & + local jigger_pid=$! + local result + + { + wait $cmd_pid 2>/dev/null + result=$? + ps -p$jigger_pid &>/dev/null && kill $jigger_pid + } + + if [ $result -eq 0 ]; then + echo -e "\nThe command $cmd exited with $result." + else + echo -e "\nThe command $cmd exited with $result." + fi + + echo -e "\nLog:\n" + cat $log_file + + return $result +} + +travis_jigger() { + # helper method for travis_wait() + local cmd_pid=$1 + shift + local timeout=$1 # in minutes + shift + local count=0 + + # clear the line + echo -e "\n" + + while [ $count -lt $timeout ]; do + count=$(($count + 1)) + echo -ne "Still running ($count of $timeout): $@\r" + sleep 60 + done + + echo -e "\nTimeout (${timeout} minutes) reached. Terminating \"$@\"\n" + kill -9 $cmd_pid +}