1#!/bin/bash 2# 3# Copyright 2019 The Abseil Authors. 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# Unit and integration tests for Abseil LTS CMake installation 18 19# Fail on any error. Treat unset variables an error. Print commands as executed. 20set -euox pipefail 21 22absl_dir=/abseil-cpp 23absl_build_dir=/buildfs 24googletest_builddir=/googletest_builddir 25googletest_archive="googletest-${ABSL_GOOGLETEST_VERSION}.tar.gz" 26project_dir="${absl_dir}/CMake/install_test_project" 27project_build_dir=/buildfs/project-build 28 29build_shared_libs="OFF" 30if [ "${LINK_TYPE:-}" = "DYNAMIC" ]; then 31 build_shared_libs="ON" 32fi 33 34# Build and install GoogleTest 35mkdir "${googletest_builddir}" 36pushd "${googletest_builddir}" 37curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${googletest_archive}" 38tar -xz -f "${googletest_archive}" 39pushd "googletest-${ABSL_GOOGLETEST_VERSION}" 40mkdir build 41pushd build 42cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" .. 43make -j $(nproc) 44make install 45ldconfig 46popd 47popd 48popd 49 50# Run the LTS transformations 51./create_lts.py 99998877 52 53# Build and install Abseil 54pushd "${absl_build_dir}" 55cmake "${absl_dir}" \ 56 -DABSL_USE_EXTERNAL_GOOGLETEST=ON \ 57 -DABSL_FIND_GOOGLETEST=ON \ 58 -DCMAKE_BUILD_TYPE=Release \ 59 -DABSL_BUILD_TESTING=ON \ 60 -DBUILD_SHARED_LIBS="${build_shared_libs}" 61make -j $(nproc) 62ctest -j $(nproc) --output-on-failure 63make install 64ldconfig 65popd 66 67# Test the project against the installed Abseil 68mkdir -p "${project_build_dir}" 69pushd "${project_build_dir}" 70cmake "${project_dir}" 71cmake --build . --target simple 72 73output="$(${project_build_dir}/simple "printme" 2>&1)" 74if [[ "${output}" != *"Arg 1: printme"* ]]; then 75 echo "Faulty output on simple project:" 76 echo "${output}" 77 exit 1 78fi 79 80popd 81 82if ! grep absl::strings "/usr/local/lib/cmake/absl/abslTargets.cmake"; then 83 cat "/usr/local/lib/cmake/absl/abslTargets.cmake" 84 echo "CMake targets named incorrectly" 85 exit 1 86fi 87 88pushd "${HOME}" 89cat > hello-abseil.cc << EOF 90#include <cstdlib> 91 92#include "absl/strings/str_format.h" 93 94int main(int argc, char **argv) { 95 absl::PrintF("Hello Abseil!\n"); 96 return EXIT_SUCCESS; 97} 98EOF 99 100if [ "${LINK_TYPE:-}" != "DYNAMIC" ]; then 101 pc_args=($(pkg-config --cflags --libs --static absl_str_format)) 102 g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}" 103else 104 pc_args=($(pkg-config --cflags --libs absl_str_format)) 105 g++ -o hello-abseil hello-abseil.cc "${pc_args[@]}" 106fi 107hello="$(./hello-abseil)" 108[[ "${hello}" == "Hello Abseil!" ]] 109 110popd 111 112echo "Install test complete!" 113exit 0 114