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 16source $(dirname ${BASH_SOURCE[0]})/common.sh 17 18# Save CI time by skipping runs on {UI,docs,infra}-only changes 19if [[ $UI_DOCS_INFRA_ONLY_CHANGE == 1 ]]; then 20echo "Detected non-code change, probably a UI-only change." 21echo "skipping build + test runs" 22exit 0 23fi 24 25BAZEL_DISK_CACHE_FOLDER="/ci/cache/bazel-disk-cache-$(hostname)" 26readonly BAZEL_DISK_CACHE_FOLDER 27# Cleanup the cache if any of the two conditions are true. 28BAZEL_DISK_CACHE_GC_OPTIONS="--experimental_disk_cache_gc_max_age=7d --experimental_disk_cache_gc_max_size=10G" 29# We don't run a bazel daemon in background, so we do a GC during the build, 30# that's why we specify _idle_delay=0. 31BAZEL_DISK_CACHE_GC_OPTIONS+=" --experimental_disk_cache_gc_idle_delay=0" 32readonly BAZEL_DISK_CACHE_GC_OPTIONS 33 34BAZEL_DISK_CACHE_FLAGS="--disk_cache=${BAZEL_DISK_CACHE_FOLDER} ${BAZEL_DISK_CACHE_GC_OPTIONS}" 35readonly BAZEL_DISK_CACHE_FLAGS 36 37# shellcheck disable=SC2086 38tools/bazel build //:all ${BAZEL_DISK_CACHE_FLAGS} --verbose_failures 39# shellcheck disable=SC2086 40tools/bazel build //python:all ${BAZEL_DISK_CACHE_FLAGS} --verbose_failures 41 42# Smoke test that processes run without crashing. 43./bazel-bin/traced & 44./bazel-bin/traced_probes & 45sleep 5 46TRACE=/ci/artifacts/bazel.trace 47./bazel-bin/perfetto -c :test -o $TRACE 48kill $(jobs -p) 49./bazel-bin/trace_processor_shell -q <(echo 'select count(1) from sched') $TRACE 50 51# Check the amalgamated build here to avoid slowing down all the Linux bots. 52echo -e "\n\n***** Testing amalgamated build *****\n" 53tools/test_gen_amalgamated.py 54 55# Print the size of the bazel cache to make sure it won't grow infinitely. 56du -sh "${BAZEL_DISK_CACHE_FOLDER}" 57