|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2023 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +source "$(dirname "$0")/../../lib/init.sh" |
| 20 | +source module ci/cloudbuild/builds/lib/cmake.sh |
| 21 | +source module ci/cloudbuild/builds/lib/features.sh |
| 22 | +source module ci/cloudbuild/builds/lib/integration.sh |
| 23 | +source module ci/lib/io.sh |
| 24 | + |
| 25 | +export CC=clang |
| 26 | +export CXX=clang++ |
| 27 | +export CTCACHE_DIR=~/.cache/ctcache |
| 28 | + |
| 29 | +# Load the build configuration. Start with the default, then any settings for |
| 30 | +# all workspaces, then the settings for the current workspace. |
| 31 | +# |
| 32 | +# Developers only need to override what changes, keep a configuration file that |
| 33 | +# applies to all their builds, and have some workspaces with custom settings. |
| 34 | +source module ci/etc/cloudcxxrc |
| 35 | +if [[ -r "${HOME}/.cloudcxxrc" ]]; then |
| 36 | + source "${HOME}/.cloudcxxrc" |
| 37 | +fi |
| 38 | +if [[ -r "${PROJECT_ROOT}/.cloudcxxrc" ]]; then |
| 39 | + source "${PROJECT_ROOT}/.cloudcxxrc" |
| 40 | +fi |
| 41 | + |
| 42 | +# Always remove the CMakeCache because it may be invalidated by `cloudcxxrc` |
| 43 | +# changes. |
| 44 | +if [[ "${ALWAYS_RESET_CMAKE_CACHE}" = "YES" ]]; then |
| 45 | + io::run rm -f cmake-out/CMakeCache.txt |
| 46 | +fi |
| 47 | + |
| 48 | +# Note: we use C++14 for this build because we don't want tidy suggestions that |
| 49 | +# require a newer C++ standard. |
| 50 | +mapfile -t cmake_args < <(cmake::common_args) |
| 51 | +io::run cmake "${cmake_args[@]}" \ |
| 52 | + -DCMAKE_CXX_CLANG_TIDY=/usr/local/bin/clang-tidy-wrapper \ |
| 53 | + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ |
| 54 | + -DCMAKE_CXX_STANDARD=14 \ |
| 55 | + -DGOOGLE_CLOUD_CPP_ENABLE="${ENABLED_FEATURES}" |
| 56 | +io::run cmake --build cmake-out |
| 57 | + |
| 58 | +if [[ "${RUN_CLANG_TIDY_FIX}" = "YES" ]]; then |
| 59 | + io::bold clang-tidy -p cmake-out -fix |
| 60 | + git_files -z -- '*.h' '*.cc' | |
| 61 | + xargs -r -P "$(nproc)" -n 1 -0 clang-tidy -p cmake-out -fix |
| 62 | + io::run cmake --build cmake-out |
| 63 | +fi |
| 64 | + |
| 65 | +if [[ "${RUN_UNIT_TESTS}" = "YES" ]]; then |
| 66 | + mapfile -t ctest_args < <(ctest::common_args) |
| 67 | + io::run ctest --test-dir cmake-out "${ctest_args[@]}" -LE integration-test |
| 68 | +fi |
| 69 | + |
| 70 | +if [[ "${RUN_INTEGRATION_TESTS}" = "YES" ]]; then |
| 71 | + integration::ctest_with_emulators "cmake-out" |
| 72 | +fi |
| 73 | + |
| 74 | +# This build should fail if any of the above work generated code differences. |
| 75 | +# This may be updated `.bzl` files, or files updated by clang-tidy. |
| 76 | +io::log_h2 "Highlight generated code differences" |
| 77 | +git diff --exit-code |
0 commit comments