linux-presubmit.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/bash
  2. #
  3. # Copyright 2020, Google Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following disclaimer
  14. # in the documentation and/or other materials provided with the
  15. # distribution.
  16. # * Neither the name of Google Inc. nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. set -euox pipefail
  32. readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20240523"
  33. readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120"
  34. if [[ -z ${GTEST_ROOT:-} ]]; then
  35. GTEST_ROOT="$(realpath $(dirname ${0})/..)"
  36. fi
  37. if [[ -z ${STD:-} ]]; then
  38. STD="c++14 c++17 c++20"
  39. fi
  40. # Test the CMake build
  41. for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do
  42. for cmake_off_on in OFF ON; do
  43. time docker run \
  44. --volume="${GTEST_ROOT}:/src:ro" \
  45. --tmpfs="/build:exec" \
  46. --workdir="/build" \
  47. --rm \
  48. --env="CC=${cc}" \
  49. --env=CXXFLAGS="-Werror -Wdeprecated" \
  50. ${LINUX_LATEST_CONTAINER} \
  51. /bin/bash -c "
  52. cmake /src \
  53. -DCMAKE_CXX_STANDARD=14 \
  54. -Dgtest_build_samples=ON \
  55. -Dgtest_build_tests=ON \
  56. -Dgmock_build_tests=ON \
  57. -Dcxx_no_exception=${cmake_off_on} \
  58. -Dcxx_no_rtti=${cmake_off_on} && \
  59. make -j$(nproc) && \
  60. ctest -j$(nproc) --output-on-failure"
  61. done
  62. done
  63. # Do one test with an older version of GCC
  64. # TODO(googletest-team): This currently uses Bazel 5. When upgrading to a
  65. # version of Bazel that supports Bzlmod, add --enable_bzlmod=false to keep test
  66. # coverage for the old WORKSPACE dependency management.
  67. time docker run \
  68. --volume="${GTEST_ROOT}:/src:ro" \
  69. --workdir="/src" \
  70. --rm \
  71. --env="CC=/usr/local/bin/gcc" \
  72. --env="BAZEL_CXXOPTS=-std=c++14" \
  73. ${LINUX_GCC_FLOOR_CONTAINER} \
  74. /usr/local/bin/bazel test ... \
  75. --copt="-Wall" \
  76. --copt="-Werror" \
  77. --copt="-Wuninitialized" \
  78. --copt="-Wundef" \
  79. --copt="-Wno-error=pragmas" \
  80. --features=external_include_paths \
  81. --keep_going \
  82. --show_timestamps \
  83. --test_output=errors
  84. # Test GCC
  85. for std in ${STD}; do
  86. for absl in 0 1; do
  87. time docker run \
  88. --volume="${GTEST_ROOT}:/src:ro" \
  89. --workdir="/src" \
  90. --rm \
  91. --env="CC=/usr/local/bin/gcc" \
  92. --env="BAZEL_CXXOPTS=-std=${std}" \
  93. ${LINUX_LATEST_CONTAINER} \
  94. /usr/local/bin/bazel test ... \
  95. --copt="-Wall" \
  96. --copt="-Werror" \
  97. --copt="-Wuninitialized" \
  98. --copt="-Wundef" \
  99. --define="absl=${absl}" \
  100. --enable_bzlmod=true \
  101. --features=external_include_paths \
  102. --keep_going \
  103. --show_timestamps \
  104. --test_output=errors
  105. done
  106. done
  107. # Test Clang
  108. for std in ${STD}; do
  109. for absl in 0 1; do
  110. time docker run \
  111. --volume="${GTEST_ROOT}:/src:ro" \
  112. --workdir="/src" \
  113. --rm \
  114. --env="CC=/opt/llvm/clang/bin/clang" \
  115. --env="BAZEL_CXXOPTS=-std=${std}" \
  116. ${LINUX_LATEST_CONTAINER} \
  117. /usr/local/bin/bazel test ... \
  118. --copt="--gcc-toolchain=/usr/local" \
  119. --copt="-Wall" \
  120. --copt="-Werror" \
  121. --copt="-Wuninitialized" \
  122. --copt="-Wundef" \
  123. --define="absl=${absl}" \
  124. --enable_bzlmod=true \
  125. --features=external_include_paths \
  126. --keep_going \
  127. --linkopt="--gcc-toolchain=/usr/local" \
  128. --show_timestamps \
  129. --test_output=errors
  130. done
  131. done