]> git.lizzy.rs Git - rust.git/blob - src/ci/shared.sh
4a49f3441a41db2d78d5aaa3038db4382ebf6f3e
[rust.git] / src / ci / shared.sh
1 #!/bin/false
2
3 # This file is intended to be sourced with `. shared.sh` or
4 # `source shared.sh`, hence the invalid shebang and not being
5 # marked as an executable file in git.
6
7 # See http://unix.stackexchange.com/questions/82598
8 function retry {
9   echo "Attempting with retry:" "$@"
10   local n=1
11   local max=5
12   while true; do
13     "$@" && break || {
14       if [[ $n -lt $max ]]; then
15         sleep $n  # don't retry immediately
16         ((n++))
17         echo "Command failed. Attempt $n/$max:"
18       else
19         echo "The command has failed after $n attempts."
20         return 1
21       fi
22     }
23   done
24 }
25
26 if ! declare -F travis_fold; then
27   if [ "${TRAVIS-false}" = 'true' ]; then
28     # This is a trimmed down copy of
29     # https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh
30     travis_fold() {
31       echo -en "travis_fold:$1:$2\r\033[0K"
32     }
33     travis_time_start() {
34       travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
35       travis_start_time=$(travis_nanoseconds)
36       echo -en "travis_time:start:$travis_timer_id\r\033[0K"
37     }
38     travis_time_finish() {
39       travis_end_time=$(travis_nanoseconds)
40       local duration=$(($travis_end_time-$travis_start_time))
41       local msg="travis_time:end:$travis_timer_id"
42       echo -en "\n$msg:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r\033[0K"
43     }
44     if [ $(uname) = 'Darwin' ]; then
45       travis_nanoseconds() {
46         date -u '+%s000000000'
47       }
48     else
49       travis_nanoseconds() {
50         date -u '+%s%N'
51       }
52     fi
53   else
54     travis_fold() { return 0; }
55     travis_time_start() { return 0; }
56     travis_time_finish() { return 0; }
57   fi
58 fi