]> git.lizzy.rs Git - rust.git/blob - src/ci/shared.sh
Do not complain about missing `fn main()` in some cases
[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 export MIRRORS_BASE="https://rust-lang-ci-mirrors.s3-us-west-1.amazonaws.com/rustc"
8
9 # See http://unix.stackexchange.com/questions/82598
10 # Duplicated in docker/dist-various-2/shared.sh
11 function retry {
12   echo "Attempting with retry:" "$@"
13   local n=1
14   local max=5
15   while true; do
16     "$@" && break || {
17       if [[ $n -lt $max ]]; then
18         sleep $n  # don't retry immediately
19         ((n++))
20         echo "Command failed. Attempt $n/$max:"
21       else
22         echo "The command has failed after $n attempts."
23         return 1
24       fi
25     }
26   done
27 }
28
29 function isCI {
30   [ "$CI" = "true" ] || [ "$TF_BUILD" = "True" ]
31 }
32
33 function isMacOS {
34   [ "$AGENT_OS" = "Darwin" ]
35 }
36
37 function isWindows {
38   [ "$AGENT_OS" = "Windows_NT" ]
39 }
40
41 function isLinux {
42   [ "$AGENT_OS" = "Linux" ]
43 }
44
45 function getCIBranch {
46   echo "$BUILD_SOURCEBRANCHNAME"
47 }
48
49 function ciCommandAddPath {
50     if [[ $# -ne 1 ]]; then
51         echo "usage: $0 <path>"
52         exit 1
53     fi
54     path="$1"
55
56     echo "##vso[task.prependpath]${path}"
57 }
58
59 function ciCommandSetEnv {
60     if [[ $# -ne 2 ]]; then
61         echo "usage: $0 <name> <value>"
62         exit 1
63     fi
64     name="$1"
65     value="$2"
66
67     echo "##vso[task.setvariable variable=${name}]${value}"
68 }