• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
33env
34
35mkdir src && cd src
36
37if [[ $PERFETTO_TEST_GIT_REF == "file://"* ]]; then
38# This is used only by tools/run_test_like_ci.
39git clone -q --no-tags --single-branch --depth=1 "$PERFETTO_TEST_GIT_REF" .
40else
41git clone -q --no-tags --single-branch \
42  https://android.googlesource.com/platform/external/perfetto.git .
43git config user.email "ci-bot@perfetto.dev"
44git config user.name "Perfetto CI"
45git fetch -q origin "$PERFETTO_TEST_GIT_REF"
46
47# We really want to test the result of the merge of the CL in ToT master. Don't
48# really care about whether the CL passes the test at the time it was written.
49git merge -q FETCH_HEAD -m merge
50fi
51
52# The android buildtools are huge due to the emulator, keep that as a separate
53# cache and pack/unpack separately. It's worth  ~30s on each non-android test.
54if [[ "$PERFETTO_TEST_GN_ARGS" =~ "android" ]]; then
55PREBUILTS_ARCHIVE=/ci/cache/buildtools-$(date +%Y-%m-%d)-android.tar.lz4
56else
57PREBUILTS_ARCHIVE=/ci/cache/buildtools-$(date +%Y-%m-%d).tar.lz4
58fi
59
60# Clear stale buildtools caches after 24h.
61(echo /ci/cache/buildtools-* | grep -v $PREBUILTS_ARCHIVE | xargs rm -f) || true
62
63if [ -f $PREBUILTS_ARCHIVE ]; then
64  lz4 -d $PREBUILTS_ARCHIVE | tar xf - || rm -f $PREBUILTS_ARCHIVE
65  git reset --hard  # Just in case some versioned file gets overwritten.
66fi
67
68
69# By default ccache uses the mtime of the compiler. This doesn't work because
70# our compilers are hermetic and their mtime is the time when we run
71# install-build-deps. Given that the toolchain is rolled via install-build-deps
72# we use that file as an identity function for the compiler check.
73export CCACHE_COMPILERCHECK=string:$(shasum tools/install-build-deps)
74export CCACHE_UMASK=000
75export CCACHE_DEPEND=1
76export CCACHE_MAXSIZE=8G
77export CCACHE_DIR=/ci/cache/ccache
78export CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime
79export CCACHE_COMPRESS=1
80export CCACHE_COMPRESSLEVEL=4
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="-l 100"
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=$(mktemp -p /ci/cache).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