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