aboutsummaryrefslogtreecommitdiff
path: root/third_party/abseil-cpp/CMake/install_test_project/test.sh
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-15 21:47:18 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-15 21:47:18 +0000
commita32061b365b2d32963d08e27396cbf32e08c31cb (patch)
treecb306ffb64819f95c080c3cb6bfcdfb45a7b3a76 /third_party/abseil-cpp/CMake/install_test_project/test.sh
parent93534cddabc1dc3b7dfa5387784c6c7394f729c4 (diff)
parentb7c9dafe99969a4e9d5ffa101bb9a8d6e1df69df (diff)
downloadwebrtc-a32061b365b2d32963d08e27396cbf32e08c31cb.tar.gz
Change-Id: Iab4fa0d9b620eddf41ca88e1eb5547f79c316203
Diffstat (limited to 'third_party/abseil-cpp/CMake/install_test_project/test.sh')
-rw-r--r--[-rwxr-xr-x]third_party/abseil-cpp/CMake/install_test_project/test.sh164
1 files changed, 98 insertions, 66 deletions
diff --git a/third_party/abseil-cpp/CMake/install_test_project/test.sh b/third_party/abseil-cpp/CMake/install_test_project/test.sh
index 5a78c92cd1..99989b031d 100755..100644
--- a/third_party/abseil-cpp/CMake/install_test_project/test.sh
+++ b/third_party/abseil-cpp/CMake/install_test_project/test.sh
@@ -13,60 +13,70 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#
-# Unit and integration tests for Abseil LTS CMake installation
+
+# "Unit" and integration tests for Absl CMake installation
+
+# TODO(absl-team): This script isn't fully hermetic because
+# -DABSL_USE_GOOGLETEST_HEAD=ON means that this script isn't pinned to a fixed
+# version of GoogleTest. This means that an upstream change to GoogleTest could
+# break this test. Fix this by allowing this script to pin to a known-good
+# version of GoogleTest.
# Fail on any error. Treat unset variables an error. Print commands as executed.
set -euox pipefail
+install_absl() {
+ pushd "${absl_build_dir}"
+ if [[ "${#}" -eq 1 ]]; then
+ cmake -DCMAKE_INSTALL_PREFIX="${1}" "${absl_dir}"
+ else
+ cmake "${absl_dir}"
+ fi
+ cmake --build . --target install -- -j
+ popd
+}
+
+uninstall_absl() {
+ xargs rm < "${absl_build_dir}"/install_manifest.txt
+ rm -rf "${absl_build_dir}"
+ mkdir -p "${absl_build_dir}"
+}
+
+lts_install=""
+
+while getopts ":l" lts; do
+ case "${lts}" in
+ l )
+ lts_install="true"
+ ;;
+ esac
+done
+
absl_dir=/abseil-cpp
-absl_build_dir=/buildfs
-googletest_builddir=/googletest_builddir
+absl_build_dir=/buildfs/absl-build
project_dir="${absl_dir}"/CMake/install_test_project
project_build_dir=/buildfs/project-build
-build_shared_libs="OFF"
-if [ "${LINK_TYPE:-}" = "DYNAMIC" ]; then
- build_shared_libs="ON"
-fi
-
-# Build and install GoogleTest
-mkdir "${googletest_builddir}"
-pushd "${googletest_builddir}"
-curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${ABSL_GOOGLETEST_COMMIT}".zip
-unzip "${ABSL_GOOGLETEST_COMMIT}".zip
-pushd "googletest-${ABSL_GOOGLETEST_COMMIT}"
-mkdir build
-pushd build
-cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" ..
-make -j $(nproc)
-make install
-ldconfig
-popd
-popd
-popd
+mkdir -p "${absl_build_dir}"
+mkdir -p "${project_build_dir}"
-# Run the LTS transformations
-./create_lts.py 99998877
-
-# Build and install Abseil
-pushd "${absl_build_dir}"
-cmake "${absl_dir}" \
- -DABSL_USE_EXTERNAL_GOOGLETEST=ON \
- -DABSL_FIND_GOOGLETEST=ON \
- -DCMAKE_BUILD_TYPE=Release \
- -DBUILD_TESTING=ON \
- -DBUILD_SHARED_LIBS="${build_shared_libs}"
-make -j $(nproc)
-ctest -j $(nproc)
-make install
-ldconfig
-popd
+if [[ "${lts_install}" ]]; then
+ install_dir="/usr/local"
+else
+ install_dir="${project_build_dir}"/install
+fi
+mkdir -p "${install_dir}"
-# Test the project against the installed Abseil
-mkdir -p "${project_build_dir}"
+# Test build, install, and link against installed abseil
pushd "${project_build_dir}"
-cmake "${project_dir}"
+if [[ "${lts_install}" ]]; then
+ install_absl
+ cmake "${project_dir}"
+else
+ install_absl "${install_dir}"
+ cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}"
+fi
+
cmake --build . --target simple
output="$(${project_build_dir}/simple "printme" 2>&1)"
@@ -78,35 +88,57 @@ fi
popd
-if ! grep absl::strings "/usr/local/lib/cmake/absl/abslTargets.cmake"; then
- cat "/usr/local/lib/cmake/absl/abslTargets.cmake"
- echo "CMake targets named incorrectly"
- exit 1
-fi
-
-pushd "${HOME}"
-cat > hello-abseil.cc << EOF
-#include <cstdlib>
-
-#include "absl/strings/str_format.h"
+# Test that we haven't accidentally made absl::abslblah
+pushd "${install_dir}"
-int main(int argc, char **argv) {
- absl::PrintF("Hello Abseil!\n");
- return EXIT_SUCCESS;
-}
-EOF
+# Starting in CMake 3.12 the default install dir is lib$bit_width
+if [[ -d lib64 ]]; then
+ libdir="lib64"
+elif [[ -d lib ]]; then
+ libdir="lib"
+else
+ echo "ls *, */*, */*/*:"
+ ls *
+ ls */*
+ ls */*/*
+ echo "unknown lib dir"
+fi
-if [ "${LINK_TYPE:-}" != "DYNAMIC" ]; then
- pc_args=($(pkg-config --cflags --libs --static absl_str_format))
- g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}"
+if [[ "${lts_install}" ]]; then
+ # LTS versions append the date of the release to the subdir.
+ # 9999/99/99 is the dummy date used in the local_lts workflow.
+ absl_subdir="absl_99999999"
else
- pc_args=($(pkg-config --cflags --libs absl_str_format))
- g++ -o hello-abseil hello-abseil.cc "${pc_args[@]}"
+ absl_subdir="absl"
fi
-hello="$(./hello-abseil)"
-[[ "${hello}" == "Hello Abseil!" ]]
+if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then
+ cat "${libdir}"/cmake/absl/abslTargets.cmake
+ echo "CMake targets named incorrectly"
+ exit 1
+fi
+
+uninstall_absl
popd
+if [[ ! "${lts_install}" ]]; then
+ # Test that we warn if installed without a prefix or a system prefix
+ output="$(install_absl 2>&1)"
+ if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
+ echo "Install without prefix didn't warn as expected. Output:"
+ echo "${output}"
+ exit 1
+ fi
+ uninstall_absl
+
+ output="$(install_absl /usr 2>&1)"
+ if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
+ echo "Install with /usr didn't warn as expected. Output:"
+ echo "${output}"
+ exit 1
+ fi
+ uninstall_absl
+fi
+
echo "Install test complete!"
exit 0