]> git.lizzy.rs Git - rust.git/blob - src/ci/shared.sh
Rollup merge of #61121 - RalfJung:miri-value-printing, r=oli-obk
[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 # Duplicated in docker/dist-various-2/shared.sh
9 function retry {
10   echo "Attempting with retry:" "$@"
11   local n=1
12   local max=5
13   while true; do
14     "$@" && break || {
15       if [[ $n -lt $max ]]; then
16         sleep $n  # don't retry immediately
17         ((n++))
18         echo "Command failed. Attempt $n/$max:"
19       else
20         echo "The command has failed after $n attempts."
21         return 1
22       fi
23     }
24   done
25 }
26
27 function isCI {
28   [ "$CI" = "true" ] || [ "$TRAVIS" = "true" ] || [ "$TF_BUILD" = "True" ]
29 }
30
31 function isOSX {
32   [ "$TRAVIS_OS_NAME" = "osx" ] || [ "$AGENT_OS" = "Darwin" ]
33 }
34
35 function getCIBranch {
36   if [ "$TRAVIS" = "true" ]; then
37     echo "$TRAVIS_BRANCH"
38   else
39     echo "$BUILD_SOURCEBRANCHNAME"
40   fi;
41 }
42
43 if ! declare -F travis_fold; then
44   if [ "${TRAVIS-false}" = 'true' ]; then
45     # This is a trimmed down copy of
46     # https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh
47     travis_fold() {
48       echo -en "travis_fold:$1:$2\r\033[0K"
49     }
50     travis_time_start() {
51       travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
52       travis_start_time=$(travis_nanoseconds)
53       echo -en "travis_time:start:$travis_timer_id\r\033[0K"
54     }
55     travis_time_finish() {
56       travis_end_time=$(travis_nanoseconds)
57       local duration=$(($travis_end_time-$travis_start_time))
58       local msg="travis_time:end:$travis_timer_id"
59       echo -en "\n$msg:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r\033[0K"
60     }
61     if [ $(uname) = 'Darwin' ]; then
62       travis_nanoseconds() {
63         date -u '+%s000000000'
64       }
65     else
66       travis_nanoseconds() {
67         date -u '+%s%N'
68       }
69     fi
70   else
71     travis_fold() { return 0; }
72     travis_time_start() { return 0; }
73     travis_time_finish() { return 0; }
74   fi
75 fi