From 43a739b4a8133dec8d1b453bff9ae953352e1af1 Mon Sep 17 00:00:00 2001
From: Tilmann Zaschke <tilmannzaschke@improbable.io>
Date: Wed, 19 Jan 2022 14:47:44 +0000
Subject: [PATCH] TODO: CHANGELOG baselisk cmake (test)

---
 .bazelrc                                      |  6 +--
 .bazelversion                                 |  2 +-
 CHANGELOG.md                                  |  3 +-
 WORKSPACE                                     | 10 ++---
 ci/includes/bazel.sh                          |  2 +-
 ci/linting/clang-format.sh                    |  2 +-
 tools/bazel                                   | 42 ++-----------------
 .../valgrind-memcheck/valgrind-memcheck.sh    |  2 +-
 .../valgrind-suppressions.txt                 | 35 ++++++++++++++++
 9 files changed, 50 insertions(+), 54 deletions(-)

diff --git a/.bazelrc b/.bazelrc
index 4c2542e5..adcf592b 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -59,12 +59,9 @@ build:windows --action_env TMP=C:/Windows/Temp
 build:windows --action_env TEMP=C:/Windows/Temp
 build:windows --cxxopt="/DWIN32_LEAN_AND_MEAN"
 
-# Config for when tests are running in a "slow" environment such as Valgrind or TSan
-build:slow-tests --copt="-DIMPROBABLE_SLOW_TEST"
-
 # Valgrind config.
 build:valgrind-memcheck --config=linux
-build:valgrind-memcheck --config=slow-tests
+build:valgrind-memcheck --define valgrind-memcheck=true
 test:valgrind-memcheck --run_under=//tools/runners/sanitizers/valgrind-memcheck
 run:valgrind-memcheck --run_under=//tools/runners/sanitizers/valgrind-memcheck
 
@@ -85,7 +82,6 @@ test:asan --test_env="ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-9/bin/llvm-symbolizer"
 test:asan --run_under=//tools/runners/sanitizers/asan
 
 build:tsan --config=base-sanitizer
-build:tsan --config=slow-tests
 build:tsan --copt="-O1"
 build:tsan --copt="-fno-optimize-sibling-calls"
 build:tsan --copt="-fsanitize=thread"
diff --git a/.bazelversion b/.bazelversion
index 359a5b95..078bf8b7 100644
--- a/.bazelversion
+++ b/.bazelversion
@@ -1 +1 @@
-2.0.0
\ No newline at end of file
+4.2.2
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d850eac8..ad30c874 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 - FilterSphere for filtering by sphere constraint (by ctbur)
 ### Changed
 - Fixed imports  `<climits>` -> `<limits>` (by ctbur)
+- Cleaned up build scripts
 - Fixed warnings:
-  - "unused" function argument warnings
+  - "unused function argument" warnings
   - gcc/clang warnings
   - MSVC warnings
   - reserved identifier warnings (identifiers starting with `_`)
diff --git a/WORKSPACE b/WORKSPACE
index 707bc800..0bd3d32b 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -11,8 +11,8 @@ http_archive(
 load("@bazel_skylib//lib:versions.bzl", "versions")
 
 versions.check(
-    minimum_bazel_version = "3.4.1",
-    maximum_bazel_version = "3.4.1",
+    minimum_bazel_version = "4.2.2",
+    maximum_bazel_version = "4.2.2",
 )
 
 # NOTE: We make third_party/ its own bazel workspace because it allows to run `bazel build ...` without
@@ -34,9 +34,9 @@ http_archive(
 
 http_archive(
     name = "gbenchmark",
-    sha256 = "3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a",
-    strip_prefix = "benchmark-1.5.0",
-    url = "https://github.com/google/benchmark/archive/v1.5.0.tar.gz",
+    sha256 = "dccbdab796baa1043f04982147e67bb6e118fe610da2c65f88912d73987e700c",
+    strip_prefix = "benchmark-1.5.2",
+    url = "https://github.com/google/benchmark/archive/v1.5.2.tar.gz",
 )
 
 http_archive(
diff --git a/ci/includes/bazel.sh b/ci/includes/bazel.sh
index 8d1c7ee8..79a70e5d 100755
--- a/ci/includes/bazel.sh
+++ b/ci/includes/bazel.sh
@@ -10,5 +10,5 @@ function runBazel() {
 }
 
 function getBazelVersion() {
-  echo "3.4.1"
+  echo "4.2.2"
 }
diff --git a/ci/linting/clang-format.sh b/ci/linting/clang-format.sh
index 3ef66c29..cebf4a22 100755
--- a/ci/linting/clang-format.sh
+++ b/ci/linting/clang-format.sh
@@ -18,7 +18,7 @@ export MSYS2_ARG_CONV_EXCL="//..."
 function joinBy { perl -e '$s = shift @ARGV; print join($s, @ARGV);' "$@"; }
 
 function clangFormatLocation() {
-  local CLANG_FORMAT_VERSION=9.0.0
+  local CLANG_FORMAT_VERSION=10.0.0
   # Use find to get the path for either clang-format (macOS / Linux) or clang-format.exe (Windows)
   local CLANG_FORMAT_EXE=clang-format
   local CLANG_FORMAT_SHIM=clang-format
diff --git a/tools/bazel b/tools/bazel
index bda59d1e..03324532 100755
--- a/tools/bazel
+++ b/tools/bazel
@@ -12,29 +12,19 @@ source "${TOOLS_DIR}"/../ci/includes/bazel.sh
 REQUIRED_BAZEL_VERSION="$(getBazelVersion)"
 BAZEL_INSTALLATION_DIR="${HOME}/.bazel_installations/${REQUIRED_BAZEL_VERSION}"
 if isLinux; then
-  REQUIRED_BAZEL_SHA256="1a64c807716e10c872f1618852d95f4893d81667fe6e691ef696489103c9b460"
-  REQUIRED_BAZEL_SHA256CMD="sha256sum"
   DOWNLOAD_CMD="wget -q --no-clobber -O bazel"
   BAZEL_EXE="bazel-${REQUIRED_BAZEL_VERSION}-linux-x86_64"
 
-  if [[ !("$(lsb_release -cs)" =~ ^(bionic|focal)$) ]]; then
-    echo -e "\033[0;33mWarning: You don't seem to be running Ubuntu 18.04 or 20.04, which is the supported Linux distribution. Continuing anyway, but your mileage might vary.\033[0m"
-  fi
-
-  if which clang-9 1>/dev/null; then
-    # We follow the symlink of clang-9 here to avoid a bug with the LLVM package when combined with -no-canonical-prefixes.
-    export CC="$(readlink -f "$(which clang-9)")"
+  if which clang-10 1>/dev/null; then
+    # We follow the symlink of clang-10 here to avoid a bug with the LLVM package when combined with -no-canonical-prefixes.
+    export CC="$(readlink -f "$(which clang-10)")"
   else
     echo -e "\033[0;33mWarning: You don't seem to have clang-9 correctly installed. Please check README.md to ensure your compiler is set up correctly. Continuing with whatever compiler bazel detects, your mileage might vary.\033[0m"
   fi
 elif isMacOS; then
-  REQUIRED_BAZEL_SHA256="23ea93e5ef9f381babd7f658bbbf12d366510f0a719e816fea90bcbe9737aef2"
-  REQUIRED_BAZEL_SHA256CMD="shasum -a 256"
   DOWNLOAD_CMD="wget -q --no-clobber -O bazel"
   BAZEL_EXE="bazel-${REQUIRED_BAZEL_VERSION}-darwin-x86_64"
 else
-  REQUIRED_BAZEL_SHA256="d526f04197a1362d95f1d214d2aa51cde527fae01c5752ccea1167475c6f1c60"
-  REQUIRED_BAZEL_SHA256CMD="sha256sum"
   DOWNLOAD_CMD="curl -L -s -o bazel.exe"
   # Windows does not have an installer but retrieves the executable directly.
   BAZEL_EXE="bazel-${REQUIRED_BAZEL_VERSION}-windows-x86_64.exe"
@@ -77,22 +67,6 @@ if [[ ! -d "${BAZEL_INSTALLATION_DIR}" ]]; then
   mkdir -p "${BAZEL_INSTALLATION_DIR}"
 fi
 
-function _are_checksums_equal() {
-  CHECKSUM_A=$1
-  CHECKSUM_B=$2
-  # Split apart the checksum from the file name by splitting the returned string by the contained
-  # space; the checksum has the format:
-  # xxxxxx...xxxxx <filename>
-  CHECKSUM_A_PARTS=(${CHECKSUM_A})
-  CHECKSUM_B_PARTS=(${CHECKSUM_B})
-
-  if [[ "${CHECKSUM_A_PARTS[0]}" == "${CHECKSUM_B_PARTS[0]}" ]]; then
-    return 0 # True
-  else
-    return 1 # False
-  fi
-}
-
 # Install correct bazel version.
 # If we don't have a local Bazel install at this point we need to retrieve the right version from GitHub.
 mkdir -p "${BAZEL_INSTALLATION_DIR}/bin/tmp"
@@ -101,16 +75,6 @@ rm bazel 2>/dev/null || true # Remove bazel binary if already present in tmp dir
 echo "Starting download of bazel ${REQUIRED_BAZEL_VERSION}..."
 ${DOWNLOAD_CMD} "https://github.com/bazelbuild/bazel/releases/download/${REQUIRED_BAZEL_VERSION}/${BAZEL_EXE}"
 echo "Download finished."
-echo "Testing download file integrity..."
-CALCULATED_CHECKSUM="$(${REQUIRED_BAZEL_SHA256CMD} bazel)"
-if ! _are_checksums_equal "${CALCULATED_CHECKSUM}" "${REQUIRED_BAZEL_SHA256}"; then
-  cat <<EOM
-  ABORT - Downloaded Bazel failed the SHA-256 hash check.
-  ABORT - Expected: ${REQUIRED_BAZEL_SHA256}  bazel
-  ABORT - Found:    ${CALCULATED_CHECKSUM}
-EOM
-  exit 1
-fi
 # Mark downloaded file executable and move out of tmp directory.
 chmod a+x "bazel"
 mv bazel ..
diff --git a/tools/runners/sanitizers/valgrind-memcheck/valgrind-memcheck.sh b/tools/runners/sanitizers/valgrind-memcheck/valgrind-memcheck.sh
index c76b1662..6b17bc8c 100755
--- a/tools/runners/sanitizers/valgrind-memcheck/valgrind-memcheck.sh
+++ b/tools/runners/sanitizers/valgrind-memcheck/valgrind-memcheck.sh
@@ -1 +1 @@
-valgrind --leak-check=full --error-exitcode=1 --suppressions=tools/runners/sanitizers/valgrind-memcheck/valgrind-suppressions.txt "${@}"
+valgrind --leak-check=full --error-exitcode=1 --num-callers=30 --suppressions=tools/runners/sanitizers/valgrind-memcheck/valgrind-suppressions.txt "${@}"
diff --git a/tools/runners/sanitizers/valgrind-memcheck/valgrind-suppressions.txt b/tools/runners/sanitizers/valgrind-memcheck/valgrind-suppressions.txt
index 59fbc13c..cd25f914 100644
--- a/tools/runners/sanitizers/valgrind-memcheck/valgrind-suppressions.txt
+++ b/tools/runners/sanitizers/valgrind-memcheck/valgrind-suppressions.txt
@@ -15,3 +15,38 @@
    fun:CRYPTO_THREAD_run_once
    fun:OPENSSL_init_crypto
 }
+{
+   pthread_stack_allocation
+   Memcheck:Leak
+   match-leak-kinds: possible
+   ...
+   fun:allocate_stack
+   fun:pthread_create*
+}
+{
+   gtest_use_of_uninitialised_value
+   Memcheck:Value8
+   fun:_itoa_word
+   fun:vfprintf
+   fun:vsnprintf
+   fun:snprintf
+   fun:_ZN7testing*
+}
+{
+   gtest_conditional_jump_or_move
+   Memcheck:Cond
+   fun:_itoa_word
+   fun:vfprintf
+   fun:vsnprintf
+   fun:snprintf
+   fun:_ZN7testing*
+}
+{
+   gtest_conditional_jump_or_move_2
+   Memcheck:Cond
+   fun:vfprintf
+   fun:vsnprintf
+   fun:snprintf
+   fun:_ZN7testing*
+}
+
