linux-presubmit.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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:20220217"
  33. readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20220621"
  34. if [[ -z ${GTEST_ROOT:-} ]]; then
  35. GTEST_ROOT="$(realpath $(dirname ${0})/..)"
  36. fi
  37. if [[ -z ${STD:-} ]]; then
  38. STD="c++11 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="CXX_FLAGS=\"-Werror -Wdeprecated\"" \
  50. ${LINUX_LATEST_CONTAINER} \
  51. /bin/bash -c "
  52. cmake /src \
  53. -DCMAKE_CXX_STANDARD=11 \
  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. time docker run \
  65. --volume="${GTEST_ROOT}:/src:ro" \
  66. --workdir="/src" \
  67. --rm \
  68. --env="CC=/usr/local/bin/gcc" \
  69. ${LINUX_GCC_FLOOR_CONTAINER} \
  70. /usr/local/bin/bazel test ... \
  71. --copt="-Wall" \
  72. --copt="-Werror" \
  73. --copt="-Wuninitialized" \
  74. --copt="-Wno-error=pragmas" \
  75. --distdir="/bazel-distdir" \
  76. --keep_going \
  77. --show_timestamps \
  78. --test_output=errors
  79. # Test GCC
  80. for std in ${STD}; do
  81. for absl in 0 1; do
  82. time docker run \
  83. --volume="${GTEST_ROOT}:/src:ro" \
  84. --workdir="/src" \
  85. --rm \
  86. --env="CC=/usr/local/bin/gcc" \
  87. --env="BAZEL_CXXOPTS=-std=${std}" \
  88. ${LINUX_LATEST_CONTAINER} \
  89. /usr/local/bin/bazel test ... \
  90. --copt="-Wall" \
  91. --copt="-Werror" \
  92. --copt="-Wuninitialized" \
  93. --define="absl=${absl}" \
  94. --distdir="/bazel-distdir" \
  95. --keep_going \
  96. --show_timestamps \
  97. --test_output=errors
  98. done
  99. done
  100. # Test Clang
  101. for std in ${STD}; do
  102. for absl in 0 1; do
  103. time docker run \
  104. --volume="${GTEST_ROOT}:/src:ro" \
  105. --workdir="/src" \
  106. --rm \
  107. --env="CC=/opt/llvm/clang/bin/clang" \
  108. --env="BAZEL_CXXOPTS=-std=${std}" \
  109. ${LINUX_LATEST_CONTAINER} \
  110. /usr/local/bin/bazel test ... \
  111. --copt="--gcc-toolchain=/usr/local" \
  112. --copt="-Wall" \
  113. --copt="-Werror" \
  114. --copt="-Wuninitialized" \
  115. --define="absl=${absl}" \
  116. --distdir="/bazel-distdir" \
  117. --keep_going \
  118. --linkopt="--gcc-toolchain=/usr/local" \
  119. --show_timestamps \
  120. --test_output=errors
  121. done
  122. done