|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2021 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 | +# http://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 | +# This build script serves two main purposes: |
| 18 | +# |
| 19 | +# 1. It demonstrates to users how to install `google-cloud-cpp`. We will |
| 20 | +# extract part of this script into user-facing markdown documentation. |
| 21 | +# 2. It verifies that the installed artifacts work by compiling and running the |
| 22 | +# quickstart programs against the installed artifacts. |
| 23 | + |
| 24 | +# Make our include guard clean against set -o nounset. |
| 25 | +test -n "${CI_CLOUDBUILD_BUILDS_LIB_QUICKSTART_SH__:-}" || declare -i CI_CLOUDBUILD_BUILDS_LIB_QUICKSTART_SH__=0 |
| 26 | +if ((CI_CLOUDBUILD_BUILDS_LIB_QUICKSTART_SH__++ != 0)); then |
| 27 | + return 0 |
| 28 | +fi # include guard |
| 29 | + |
| 30 | +source module ci/cloudbuild/builds/lib/cmake.sh |
| 31 | +source module ci/etc/quickstart-config.sh |
| 32 | +source module ci/lib/io.sh |
| 33 | + |
| 34 | +# Builds and runs the CMake and Makefile quickstart programs. This is a useful |
| 35 | +# way to test that the artifacts installed by `google-cloud-cpp` work. This |
| 36 | +# function requires a single argument specifying the directory where the |
| 37 | +# `google-cloud-cpp` library was installed. |
| 38 | +# |
| 39 | +# Example: |
| 40 | +# |
| 41 | +# quickstart::run_cmake_and_make "/usr/local" |
| 42 | +function quickstart::run_cmake_and_make() { |
| 43 | + local prefix="$1" |
| 44 | + for lib in $(quickstart::libraries); do |
| 45 | + mapfile -t run_args < <(quickstart::arguments "${lib}") |
| 46 | + io::log_h2 "Building quickstart: ${lib}" |
| 47 | + if [[ "${PROJECT_ID:-}" != "cloud-cpp-testing-resources" ]]; then |
| 48 | + run_args=() # Empties these args so we don't execute quickstarts below |
| 49 | + io::log_yellow "Not executing quickstarts," \ |
| 50 | + "which can only run in GCB project 'cloud-cpp-testing-resources'" |
| 51 | + fi |
| 52 | + |
| 53 | + io::log "[ CMake ]" |
| 54 | + src_dir="${PROJECT_ROOT}/google/cloud/${lib}/quickstart" |
| 55 | + bin_dir="${PROJECT_ROOT}/cmake-out/quickstart-${lib}" |
| 56 | + cmake -H"${src_dir}" -B"${bin_dir}" "-DCMAKE_PREFIX_PATH=${prefix}" |
| 57 | + cmake --build "${bin_dir}" |
| 58 | + test "${#run_args[@]}" -eq 0 || "${bin_dir}/quickstart" "${run_args[@]}" |
| 59 | + |
| 60 | + echo |
| 61 | + io::log "[ Make ]" |
| 62 | + PKG_CONFIG_PATH="${prefix}/lib64/pkgconfig:${prefix}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" \ |
| 63 | + make -C "${src_dir}" |
| 64 | + test "${#run_args[@]}" -eq 0 || "${src_dir}/quickstart" "${run_args[@]}" |
| 65 | + done |
| 66 | +} |
0 commit comments