Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame^] | 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 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. |
| 26 | set -euox pipefail |
| 27 | |
| 28 | install_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 | |
| 39 | uninstall_absl() { |
| 40 | xargs rm < "${absl_build_dir}"/install_manifest.txt |
| 41 | rm -rf "${absl_build_dir}" |
| 42 | mkdir -p "${absl_build_dir}" |
| 43 | } |
| 44 | |
| 45 | lts_install="" |
| 46 | |
| 47 | while getopts ":l" lts; do |
| 48 | case "${lts}" in |
| 49 | l ) |
| 50 | lts_install="true" |
| 51 | ;; |
| 52 | esac |
| 53 | done |
| 54 | |
| 55 | absl_dir=/abseil-cpp |
| 56 | absl_build_dir=/buildfs/absl-build |
| 57 | project_dir="${absl_dir}"/CMake/install_test_project |
| 58 | project_build_dir=/buildfs/project-build |
| 59 | |
| 60 | mkdir -p "${absl_build_dir}" |
| 61 | mkdir -p "${project_build_dir}" |
| 62 | |
| 63 | if [[ "${lts_install}" ]]; then |
| 64 | install_dir="/usr/local" |
| 65 | else |
| 66 | install_dir="${project_build_dir}"/install |
| 67 | fi |
| 68 | mkdir -p "${install_dir}" |
| 69 | |
| 70 | # Test build, install, and link against installed abseil |
| 71 | pushd "${project_build_dir}" |
| 72 | if [[ "${lts_install}" ]]; then |
| 73 | install_absl |
| 74 | cmake "${project_dir}" |
| 75 | else |
| 76 | install_absl "${install_dir}" |
| 77 | cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}" |
| 78 | fi |
| 79 | |
| 80 | cmake --build . --target simple |
| 81 | |
| 82 | output="$(${project_build_dir}/simple "printme" 2>&1)" |
| 83 | if [[ "${output}" != *"Arg 1: printme"* ]]; then |
| 84 | echo "Faulty output on simple project:" |
| 85 | echo "${output}" |
| 86 | exit 1 |
| 87 | fi |
| 88 | |
| 89 | popd |
| 90 | |
| 91 | # Test that we haven't accidentally made absl::abslblah |
| 92 | pushd "${install_dir}" |
| 93 | |
| 94 | # Starting in CMake 3.12 the default install dir is lib$bit_width |
| 95 | if [[ -d lib64 ]]; then |
| 96 | libdir="lib64" |
| 97 | elif [[ -d lib ]]; then |
| 98 | libdir="lib" |
| 99 | else |
| 100 | echo "ls *, */*, */*/*:" |
| 101 | ls * |
| 102 | ls */* |
| 103 | ls */*/* |
| 104 | echo "unknown lib dir" |
| 105 | fi |
| 106 | |
| 107 | if [[ "${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" |
| 111 | else |
| 112 | absl_subdir="absl" |
| 113 | fi |
| 114 | |
| 115 | if ! 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 |
| 119 | fi |
| 120 | |
| 121 | uninstall_absl |
| 122 | popd |
| 123 | |
| 124 | if [[ ! "${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 |
| 141 | fi |
| 142 | |
| 143 | echo "Install test complete!" |
| 144 | exit 0 |