summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-02 15:59:24 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-03 14:24:18 -0700
commit0661c748809e0f87b717ab4b2292ed7ca644d926 (patch)
tree8a56087c8f8a59f6ef37e4fb5511a1ab7664b141
parentf5659439ba44b33e802104e488880c0146d8a82d (diff)
downloadsubsurface-0661c748809e0f87b717ab4b2292ed7ca644d926.tar.gz
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 <dirk@hohndel.org>
-rw-r--r--scripts/travis-wait.sh65
1 files changed, 65 insertions, 0 deletions
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 <contact@travis-ci.org>
+#
+# 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
+}