1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # Setup for build cache
7 # Thunderbird builds will set prior to including this file
8 aws_prefix=${aws_prefix:-taskcluster}
9 gcp_prefix=${gcp_prefix:-sccache}
11 # builds where buildprops didn't have the data (eg: taskcluster) and without sccache disabled:
12 if test -z "$bucket" -a -z "$SCCACHE_DISABLE"; then
14 # prevent rerun if az is set, or wget is not available
15 if test -z "$availability_zone" -a -x "$(command -v wget)"; then
16 if test -n "$TASKCLUSTER_WORKER_LOCATION" -a -x "$(command -v jq)"; then
17 cloud=$(echo $TASKCLUSTER_WORKER_LOCATION | jq .cloud | tr -d \")
20 availability_zone=$(echo $TASKCLUSTER_WORKER_LOCATION | jq .availabilityZone | tr -d \")
21 region=$(echo $TASKCLUSTER_WORKER_LOCATION | jq .region | tr -d \")
25 if test -z "$availability_zone" -o -z "$region"; then
26 if test -n "${TASKCLUSTER_WORKER_GROUP}"; then
27 # TASKCLUSTER_WORKER_GROUP is just the region now, so
28 # stick an extra character on to make the already-convoluted logic
30 availability_zone="${TASKCLUSTER_WORKER_GROUP}x"
31 elif [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
32 # gcp availability_zone is of the form <region>-<letter> where region is e.g. us-west2, and az is us-west2-a
33 gcp_zone=$(wget -T 1 -t 1 -q -O - http://169.254.169.254/computeMetadata/v1beta1/instance/zone || true)
34 availability_zone=${gcp_zone##*/}
36 # timeout after 1 second, and don't retry (failure indicates instance is not in ec2 or network issue)
37 # ec2 availability_zone is of the form <region><letter> where region is e.g. us-west-2, and az is us-west-2a
38 availability_zone=$(wget -T 1 -t 1 -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone || true)
41 if test -z "$availability_zone" -o "$availability_zone" = "not-ec2"; then
42 availability_zone=not-ec2
43 elif test -n "$cloud"; then
46 bucket=${gcp_prefix}-l${MOZ_SCM_LEVEL}-${region}
49 bucket=${aws_prefix}-level-${MOZ_SCM_LEVEL}-sccache-${region}
52 elif [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
53 # gcp region is az with last two letters trimmed
54 if test -z "$region"; then
55 region=${availability_zone::${#availability_zone}-2}
57 bucket=${aws_prefix}-level-${MOZ_SCM_LEVEL}-sccache-${region}
59 # ec2 region is az with last letter trimmed
60 if test -z "$region"; then
61 region=${availability_zone%?}
63 bucket=${aws_prefix}-level-${MOZ_SCM_LEVEL}-sccache-${region}
68 if test -n "$bucket"; then
69 if test "$cloud" = "google"; then
70 mk_add_options "export SCCACHE_GCS_BUCKET=$bucket"
71 mk_add_options "export SCCACHE_GCS_RW_MODE=READ_WRITE"
72 mk_add_options "export SCCACHE_GCS_CREDENTIALS_URL=http://taskcluster/auth/v1/gcp/credentials/$SCCACHE_GCS_PROJECT/${bucket}@$SCCACHE_GCS_PROJECT.iam.gserviceaccount.com"
73 elif [ -n "${SCCACHE_GCS_KEY_PATH}" ]; then
74 mk_add_options "export SCCACHE_GCS_BUCKET=$bucket"
76 mk_add_options "export SCCACHE_BUCKET=$bucket"
77 # instruct sccache to fetch the credentials from the Auth service's awsS3Credentials endpoint, via the Taskcluster proxy.
78 mk_add_options "export AWS_IAM_CREDENTIALS_URL=http://taskcluster/auth/v1/aws/s3/read-write/${bucket}/?format=iam-role-compat"
80 export CCACHE="sccache"
81 export SCCACHE_VERBOSE_STATS=1
82 # Workaround for https://github.com/mozilla/sccache/issues/459#issuecomment-618756635
83 mk_add_options "export SCCACHE_MAX_FRAME_LENGTH=50000000"
84 mk_add_options MOZBUILD_MANAGE_SCCACHE_DAEMON=${MOZ_FETCHES_DIR}/sccache/sccache