blob: 99989b031d36ddccecf0f1d22871750a88cd19e4 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001#!/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 Absl CMake installation
18
19# TODO(absl-team): This script isn't fully hermetic because
20# -DABSL_USE_GOOGLETEST_HEAD=ON means that this script isn't pinned to a fixed
21# version of GoogleTest. This means that an upstream change to GoogleTest could
22# break this test. Fix this by allowing this script to pin to a known-good
23# version of GoogleTest.
24
25# Fail on any error. Treat unset variables an error. Print commands as executed.
26set -euox pipefail
27
28install_absl() {
29 pushd "${absl_build_dir}"
30 if [[ "${#}" -eq 1 ]]; then
31 cmake -DCMAKE_INSTALL_PREFIX="${1}" "${absl_dir}"
32 else
33 cmake "${absl_dir}"
34 fi
35 cmake --build . --target install -- -j
36 popd
37}
38
39uninstall_absl() {
40 xargs rm < "${absl_build_dir}"/install_manifest.txt
41 rm -rf "${absl_build_dir}"
42 mkdir -p "${absl_build_dir}"
43}
44
45lts_install=""
46
47while getopts ":l" lts; do
48 case "${lts}" in
49 l )
50 lts_install="true"
51 ;;
52 esac
53done
54
55absl_dir=/abseil-cpp
56absl_build_dir=/buildfs/absl-build
57project_dir="${absl_dir}"/CMake/install_test_project
58project_build_dir=/buildfs/project-build
59
60mkdir -p "${absl_build_dir}"
61mkdir -p "${project_build_dir}"
62
63if [[ "${lts_install}" ]]; then
64 install_dir="/usr/local"
65else
66 install_dir="${project_build_dir}"/install
67fi
68mkdir -p "${install_dir}"
69
70# Test build, install, and link against installed abseil
71pushd "${project_build_dir}"
72if [[ "${lts_install}" ]]; then
73 install_absl
74 cmake "${project_dir}"
75else
76 install_absl "${install_dir}"
77 cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}"
78fi
79
80cmake --build . --target simple
81
82output="$(${project_build_dir}/simple "printme" 2>&1)"
83if [[ "${output}" != *"Arg 1: printme"* ]]; then
84 echo "Faulty output on simple project:"
85 echo "${output}"
86 exit 1
87fi
88
89popd
90
91# Test that we haven't accidentally made absl::abslblah
92pushd "${install_dir}"
93
94# Starting in CMake 3.12 the default install dir is lib$bit_width
95if [[ -d lib64 ]]; then
96 libdir="lib64"
97elif [[ -d lib ]]; then
98 libdir="lib"
99else
100 echo "ls *, */*, */*/*:"
101 ls *
102 ls */*
103 ls */*/*
104 echo "unknown lib dir"
105fi
106
107if [[ "${lts_install}" ]]; then
108 # LTS versions append the date of the release to the subdir.
109 # 9999/99/99 is the dummy date used in the local_lts workflow.
110 absl_subdir="absl_99999999"
111else
112 absl_subdir="absl"
113fi
114
115if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then
116 cat "${libdir}"/cmake/absl/abslTargets.cmake
117 echo "CMake targets named incorrectly"
118 exit 1
119fi
120
121uninstall_absl
122popd
123
124if [[ ! "${lts_install}" ]]; then
125 # Test that we warn if installed without a prefix or a system prefix
126 output="$(install_absl 2>&1)"
127 if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
128 echo "Install without prefix didn't warn as expected. Output:"
129 echo "${output}"
130 exit 1
131 fi
132 uninstall_absl
133
134 output="$(install_absl /usr 2>&1)"
135 if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
136 echo "Install with /usr didn't warn as expected. Output:"
137 echo "${output}"
138 exit 1
139 fi
140 uninstall_absl
141fi
142
143echo "Install test complete!"
144exit 0