1#!/bin/bash 2# Copyright (C) 2019 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# Should code live in this script or in the PERFETTO_TEST_SCRIPT script? 17# You might argue: after all they are both part of the same repo? The difference 18# is in temporal pinning. 19# Code in this script is part of the Docker image that is manually pushed 20# on the VMs. Everything in here is orthogonal to the evolution of the repo. 21# Everything from /ramdisk instead will reflect the state of the repo at the 22# point in time of the checkout. 23# Things like script that upload performance data to dashboarads should probably 24# be in the docker image. Things that depend on build artifacts should probably 25# come from the repo. 26 27set -eux 28 29# CWD is /ci/ramdisk. In the CI this is based on a tmpfs ramdisk. 30 31# Print env vars for debugging. They contain GN args and entrypoint. 32date 33hostname 34env 35 36mkdir src && cd src 37 38if [[ -f "$PERFETTO_TEST_GIT_REF" ]]; then 39# This is used only by tools/run_test_like_ci. 40git clone -q --no-tags --single-branch --depth=1 "$PERFETTO_TEST_GIT_REF" . 41else 42git clone -q --no-tags --single-branch \ 43 https://android.googlesource.com/platform/external/perfetto.git . 44git config user.email "ci-bot@perfetto.dev" 45git config user.name "Perfetto CI" 46git fetch -q origin "$PERFETTO_TEST_GIT_REF" 47 48# We really want to test the result of the merge of the CL in ToT master. Don't 49# really care about whether the CL passes the test at the time it was written. 50git merge -q FETCH_HEAD -m merge 51fi 52 53# The android buildtools are huge due to the emulator, keep that as a separate 54# cache and pack/unpack separately. It's worth ~30s on each non-android test. 55if [[ "$PERFETTO_TEST_GN_ARGS" =~ "android" ]]; then 56PREBUILTS_ARCHIVE=/ci/cache/buildtools-$(date +%Y-%m-%d)-android.tar.lz4 57else 58PREBUILTS_ARCHIVE=/ci/cache/buildtools-$(date +%Y-%m-%d).tar.lz4 59fi 60 61# Clear stale buildtools caches after 24h. 62(echo /ci/cache/buildtools-* | grep -v $PREBUILTS_ARCHIVE | xargs rm -f) || true 63 64if [ -f $PREBUILTS_ARCHIVE ]; then 65 lz4 -d $PREBUILTS_ARCHIVE | tar xf - || rm -f $PREBUILTS_ARCHIVE 66 git reset --hard # Just in case some versioned file gets overwritten. 67fi 68 69 70# By default ccache uses the mtime of the compiler. This doesn't work because 71# our compilers are hermetic and their mtime is the time when we run 72# install-build-deps. Given that the toolchain is rolled via install-build-deps 73# we use that file as an identity function for the compiler check. 74export CCACHE_COMPILERCHECK=string:$(shasum tools/install-build-deps) 75export CCACHE_UMASK=000 76export CCACHE_DEPEND=1 77export CCACHE_MAXSIZE=32G 78export CCACHE_DIR=/ci/cache/ccache 79export CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime 80export CCACHE_NOCOMPRESS=1 81mkdir -m 777 -p $CCACHE_DIR 82 83export PERFETTO_TEST_GN_ARGS="${PERFETTO_TEST_GN_ARGS} cc_wrapper=\"ccache\"" 84 85export PERFETTO_TEST_NINJA_ARGS="" 86$PERFETTO_TEST_SCRIPT 87 88# The code after this point will NOT run if the test fails (because of set -e). 89 90ccache --show-stats 91 92# Populate the cache on the first run. Do that atomically so in case of races 93# one random worker wins. 94if [ ! -f $PREBUILTS_ARCHIVE ]; then 95 TMPFILE=/ci/cache/buildtools-$(hostname -s).tar.lz4 96 # Add only git-ignored dirs to the cache. 97 git check-ignore buildtools/* | xargs tar c | lz4 -z - "$TMPFILE" 98 mv -f "$TMPFILE" $PREBUILTS_ARCHIVE 99fi 100