linux-presubmit.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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++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=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. time docker run \
  65. --volume="${GTEST_ROOT}:/src:ro" \
  66. --workdir="/src" \
  67. --rm \
  68. --env="CC=/usr/local/bin/gcc" \
  69. --env="BAZEL_CXXOPTS=-std=c++14" \
  70. ${LINUX_GCC_FLOOR_CONTAINER} \
  71. /usr/local/bin/bazel test ... \
  72. --copt="-Wall" \
  73. --copt="-Werror" \
  74. --copt="-Wuninitialized" \
  75. --copt="-Wno-error=pragmas" \
  76. --distdir="/bazel-distdir" \
  77. --features=external_include_paths \
  78. --keep_going \
  79. --show_timestamps \
  80. --test_output=errors
  81. # Test GCC
  82. for std in ${STD}; do
  83. for absl in 0 1; do
  84. time docker run \
  85. --volume="${GTEST_ROOT}:/src:ro" \
  86. --workdir="/src" \
  87. --rm \
  88. --env="CC=/usr/local/bin/gcc" \
  89. --env="BAZEL_CXXOPTS=-std=${std}" \
  90. ${LINUX_LATEST_CONTAINER} \
  91. /usr/local/bin/bazel test ... \
  92. --copt="-Wall" \
  93. --copt="-Werror" \
  94. --copt="-Wuninitialized" \
  95. --define="absl=${absl}" \
  96. --distdir="/bazel-distdir" \
  97. --features=external_include_paths \
  98. --keep_going \
  99. --show_timestamps \
  100. --test_output=errors
  101. done
  102. done
  103. # Test Clang
  104. for std in ${STD}; do
  105. for absl in 0 1; do
  106. time docker run \
  107. --volume="${GTEST_ROOT}:/src:ro" \
  108. --workdir="/src" \
  109. --rm \
  110. --env="CC=/opt/llvm/clang/bin/clang" \
  111. --env="BAZEL_CXXOPTS=-std=${std}" \
  112. ${LINUX_LATEST_CONTAINER} \
  113. /usr/local/bin/bazel test ... \
  114. --copt="--gcc-toolchain=/usr/local" \
  115. --copt="-Wall" \
  116. --copt="-Werror" \
  117. --copt="-Wuninitialized" \
  118. --define="absl=${absl}" \
  119. --distdir="/bazel-distdir" \
  120. --features=external_include_paths \
  121. --keep_going \
  122. --linkopt="--gcc-toolchain=/usr/local" \
  123. --show_timestamps \
  124. --test_output=errors
  125. done
  126. done