]> git.lizzy.rs Git - rust.git/blob - src/ci/scripts/setup-environment.sh
Merge commit '35d9c6bf256968e1b40e0d554607928bdf9cebea' into sync_cg_clif-2022-02-23
[rust.git] / src / ci / scripts / setup-environment.sh
1 #!/bin/bash
2 # This script guesses some environment variables based on the builder name and
3 # the current platform, to reduce the amount of variables defined in the CI
4 # configuration.
5
6 set -euo pipefail
7 IFS=$'\n\t'
8
9 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10
11 # Since matrix variables are readonly in Azure Pipelines, we take
12 # INITIAL_RUST_CONFIGURE_ARGS and establish RUST_CONFIGURE_ARGS
13 # which downstream steps can alter
14 if isAzurePipelines; then
15     # macOS ships with Bash 3.16, so we cannot use [[ -v FOO ]],
16     # which was introduced in Bash 4.2
17     if [[ -z "${INITIAL_RUST_CONFIGURE_ARGS+x}" ]]; then
18         INITIAL_RUST_CONFIG=""
19         echo "No initial Rust configure args set"
20     else
21         INITIAL_RUST_CONFIG="${INITIAL_RUST_CONFIGURE_ARGS}"
22         ciCommandSetEnv RUST_CONFIGURE_ARGS "${INITIAL_RUST_CONFIG}"
23     fi
24 fi
25
26 # Load extra environment variables
27 vars="${EXTRA_VARIABLES-}"
28 echo "${vars}" | jq '' >/dev/null  # Validate JSON and exit on errors
29 for key in $(echo "${vars}" | jq "keys[]" -r); do
30     # On Windows, for whatever reason, $key contains the BOM character in it,
31     # and that messes up `jq ".${key}"`. This line strips the BOM from the key.
32     #
33     # https://unix.stackexchange.com/a/381263
34     key="$(echo "${key}" | sed '1s/^\xEF\xBB\xBF//')"
35
36     echo "adding extra environment variable ${key}"
37     value="$(echo "${vars}" | jq ".${key}" -r)"
38     export "${key}"="${value}"
39     ciCommandSetEnv "${key}" "${value}"
40 done
41
42 # Builders starting with `dist-` are dist builders, but if they also end with
43 # `-alt` they are alternate dist builders.
44 if [[ "${CI_JOB_NAME}" = dist-* ]]; then
45     if [[ "${CI_JOB_NAME}" = *-alt ]]; then
46         echo "alternate dist builder detected, setting DEPLOY_ALT=1"
47         ciCommandSetEnv DEPLOY_ALT 1
48     else
49         echo "normal dist builder detected, setting DEPLOY=1"
50         ciCommandSetEnv DEPLOY 1
51     fi
52 fi
53
54 # All the Linux builds happen inside Docker.
55 if isLinux; then
56     if [[ -z "${IMAGE+x}" ]]; then
57         echo "linux builder detected, using docker to run the build"
58         ciCommandSetEnv IMAGE "${CI_JOB_NAME}"
59     else
60         echo "a custom docker image is already set"
61     fi
62 fi