xref: /aosp_15_r20/external/abseil-cpp/CMake/install_test_project/test.sh (revision 9356374a3709195abf420251b3e825997ff56c0f)
1*9356374aSAndroid Build Coastguard Worker#!/bin/bash
2*9356374aSAndroid Build Coastguard Worker#
3*9356374aSAndroid Build Coastguard Worker# Copyright 2019 The Abseil Authors.
4*9356374aSAndroid Build Coastguard Worker#
5*9356374aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*9356374aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*9356374aSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*9356374aSAndroid Build Coastguard Worker#
9*9356374aSAndroid Build Coastguard Worker#    https://www.apache.org/licenses/LICENSE-2.0
10*9356374aSAndroid Build Coastguard Worker#
11*9356374aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*9356374aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*9356374aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*9356374aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*9356374aSAndroid Build Coastguard Worker# limitations under the License.
16*9356374aSAndroid Build Coastguard Worker#
17*9356374aSAndroid Build Coastguard Worker# Unit and integration tests for Abseil LTS CMake installation
18*9356374aSAndroid Build Coastguard Worker
19*9356374aSAndroid Build Coastguard Worker# Fail on any error. Treat unset variables an error. Print commands as executed.
20*9356374aSAndroid Build Coastguard Workerset -euox pipefail
21*9356374aSAndroid Build Coastguard Worker
22*9356374aSAndroid Build Coastguard Workerabsl_dir=/abseil-cpp
23*9356374aSAndroid Build Coastguard Workerabsl_build_dir=/buildfs
24*9356374aSAndroid Build Coastguard Workergoogletest_builddir=/googletest_builddir
25*9356374aSAndroid Build Coastguard Workergoogletest_archive="googletest-${ABSL_GOOGLETEST_VERSION}.tar.gz"
26*9356374aSAndroid Build Coastguard Workerproject_dir="${absl_dir}/CMake/install_test_project"
27*9356374aSAndroid Build Coastguard Workerproject_build_dir=/buildfs/project-build
28*9356374aSAndroid Build Coastguard Worker
29*9356374aSAndroid Build Coastguard Workerbuild_shared_libs="OFF"
30*9356374aSAndroid Build Coastguard Workerif [ "${LINK_TYPE:-}" = "DYNAMIC" ]; then
31*9356374aSAndroid Build Coastguard Worker  build_shared_libs="ON"
32*9356374aSAndroid Build Coastguard Workerfi
33*9356374aSAndroid Build Coastguard Worker
34*9356374aSAndroid Build Coastguard Worker# Build and install GoogleTest
35*9356374aSAndroid Build Coastguard Workermkdir "${googletest_builddir}"
36*9356374aSAndroid Build Coastguard Workerpushd "${googletest_builddir}"
37*9356374aSAndroid Build Coastguard Workercurl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${googletest_archive}"
38*9356374aSAndroid Build Coastguard Workertar -xz -f "${googletest_archive}"
39*9356374aSAndroid Build Coastguard Workerpushd "googletest-${ABSL_GOOGLETEST_VERSION}"
40*9356374aSAndroid Build Coastguard Workermkdir build
41*9356374aSAndroid Build Coastguard Workerpushd build
42*9356374aSAndroid Build Coastguard Workercmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" ..
43*9356374aSAndroid Build Coastguard Workermake -j $(nproc)
44*9356374aSAndroid Build Coastguard Workermake install
45*9356374aSAndroid Build Coastguard Workerldconfig
46*9356374aSAndroid Build Coastguard Workerpopd
47*9356374aSAndroid Build Coastguard Workerpopd
48*9356374aSAndroid Build Coastguard Workerpopd
49*9356374aSAndroid Build Coastguard Worker
50*9356374aSAndroid Build Coastguard Worker# Run the LTS transformations
51*9356374aSAndroid Build Coastguard Worker./create_lts.py 99998877
52*9356374aSAndroid Build Coastguard Worker
53*9356374aSAndroid Build Coastguard Worker# Build and install Abseil
54*9356374aSAndroid Build Coastguard Workerpushd "${absl_build_dir}"
55*9356374aSAndroid Build Coastguard Workercmake "${absl_dir}" \
56*9356374aSAndroid Build Coastguard Worker  -DABSL_USE_EXTERNAL_GOOGLETEST=ON \
57*9356374aSAndroid Build Coastguard Worker  -DABSL_FIND_GOOGLETEST=ON  \
58*9356374aSAndroid Build Coastguard Worker  -DCMAKE_BUILD_TYPE=Release \
59*9356374aSAndroid Build Coastguard Worker  -DABSL_BUILD_TESTING=ON \
60*9356374aSAndroid Build Coastguard Worker  -DBUILD_SHARED_LIBS="${build_shared_libs}"
61*9356374aSAndroid Build Coastguard Workermake -j $(nproc)
62*9356374aSAndroid Build Coastguard Workerctest -j $(nproc) --output-on-failure
63*9356374aSAndroid Build Coastguard Workermake install
64*9356374aSAndroid Build Coastguard Workerldconfig
65*9356374aSAndroid Build Coastguard Workerpopd
66*9356374aSAndroid Build Coastguard Worker
67*9356374aSAndroid Build Coastguard Worker# Test the project against the installed Abseil
68*9356374aSAndroid Build Coastguard Workermkdir -p "${project_build_dir}"
69*9356374aSAndroid Build Coastguard Workerpushd "${project_build_dir}"
70*9356374aSAndroid Build Coastguard Workercmake "${project_dir}"
71*9356374aSAndroid Build Coastguard Workercmake --build . --target simple
72*9356374aSAndroid Build Coastguard Worker
73*9356374aSAndroid Build Coastguard Workeroutput="$(${project_build_dir}/simple "printme" 2>&1)"
74*9356374aSAndroid Build Coastguard Workerif [[ "${output}" != *"Arg 1: printme"* ]]; then
75*9356374aSAndroid Build Coastguard Worker  echo "Faulty output on simple project:"
76*9356374aSAndroid Build Coastguard Worker  echo "${output}"
77*9356374aSAndroid Build Coastguard Worker  exit 1
78*9356374aSAndroid Build Coastguard Workerfi
79*9356374aSAndroid Build Coastguard Worker
80*9356374aSAndroid Build Coastguard Workerpopd
81*9356374aSAndroid Build Coastguard Worker
82*9356374aSAndroid Build Coastguard Workerif ! grep absl::strings "/usr/local/lib/cmake/absl/abslTargets.cmake"; then
83*9356374aSAndroid Build Coastguard Worker  cat "/usr/local/lib/cmake/absl/abslTargets.cmake"
84*9356374aSAndroid Build Coastguard Worker  echo "CMake targets named incorrectly"
85*9356374aSAndroid Build Coastguard Worker  exit 1
86*9356374aSAndroid Build Coastguard Workerfi
87*9356374aSAndroid Build Coastguard Worker
88*9356374aSAndroid Build Coastguard Workerpushd "${HOME}"
89*9356374aSAndroid Build Coastguard Workercat > hello-abseil.cc << EOF
90*9356374aSAndroid Build Coastguard Worker#include <cstdlib>
91*9356374aSAndroid Build Coastguard Worker
92*9356374aSAndroid Build Coastguard Worker#include "absl/strings/str_format.h"
93*9356374aSAndroid Build Coastguard Worker
94*9356374aSAndroid Build Coastguard Workerint main(int argc, char **argv) {
95*9356374aSAndroid Build Coastguard Worker  absl::PrintF("Hello Abseil!\n");
96*9356374aSAndroid Build Coastguard Worker  return EXIT_SUCCESS;
97*9356374aSAndroid Build Coastguard Worker}
98*9356374aSAndroid Build Coastguard WorkerEOF
99*9356374aSAndroid Build Coastguard Worker
100*9356374aSAndroid Build Coastguard Workerif [ "${LINK_TYPE:-}" != "DYNAMIC" ]; then
101*9356374aSAndroid Build Coastguard Worker  pc_args=($(pkg-config --cflags --libs --static absl_str_format))
102*9356374aSAndroid Build Coastguard Worker  g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}"
103*9356374aSAndroid Build Coastguard Workerelse
104*9356374aSAndroid Build Coastguard Worker  pc_args=($(pkg-config --cflags --libs absl_str_format))
105*9356374aSAndroid Build Coastguard Worker  g++ -o hello-abseil hello-abseil.cc "${pc_args[@]}"
106*9356374aSAndroid Build Coastguard Workerfi
107*9356374aSAndroid Build Coastguard Workerhello="$(./hello-abseil)"
108*9356374aSAndroid Build Coastguard Worker[[ "${hello}" == "Hello Abseil!" ]]
109*9356374aSAndroid Build Coastguard Worker
110*9356374aSAndroid Build Coastguard Workerpopd
111*9356374aSAndroid Build Coastguard Worker
112*9356374aSAndroid Build Coastguard Workerecho "Install test complete!"
113*9356374aSAndroid Build Coastguard Workerexit 0
114