linux-presubmit.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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:20210525"
  33. readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20201015"
  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="-Wno-error=pragmas" \
  74. --keep_going \
  75. --show_timestamps \
  76. --test_output=errors
  77. # Test GCC
  78. for std in ${STD}; do
  79. for absl in 0 1; do
  80. time docker run \
  81. --volume="${GTEST_ROOT}:/src:ro" \
  82. --workdir="/src" \
  83. --rm \
  84. --env="CC=/usr/local/bin/gcc" \
  85. --env="BAZEL_CXXOPTS=-std=${std}" \
  86. ${LINUX_LATEST_CONTAINER} \
  87. /usr/local/bin/bazel test ... \
  88. --copt="-Wall" \
  89. --copt="-Werror" \
  90. --define="absl=${absl}" \
  91. --distdir="/bazel-distdir" \
  92. --keep_going \
  93. --show_timestamps \
  94. --test_output=errors
  95. done
  96. done
  97. # Test Clang
  98. for std in ${STD}; do
  99. for absl in 0 1; do
  100. time docker run \
  101. --volume="${GTEST_ROOT}:/src:ro" \
  102. --workdir="/src" \
  103. --rm \
  104. --env="CC=/opt/llvm/clang/bin/clang" \
  105. --env="BAZEL_CXXOPTS=-std=${std}" \
  106. ${LINUX_LATEST_CONTAINER} \
  107. /usr/local/bin/bazel test ... \
  108. --copt="--gcc-toolchain=/usr/local" \
  109. --copt="-Wall" \
  110. --copt="-Werror" \
  111. --define="absl=${absl}" \
  112. --distdir="/bazel-distdir" \
  113. --keep_going \
  114. --linkopt="--gcc-toolchain=/usr/local" \
  115. --show_timestamps \
  116. --test_output=errors
  117. done
  118. done