#! /bin/bash

set -euo pipefail

CLANG_TIDY="${1}"
CMAKE_BINARY_DIR="${2}"
CMAKE_SOURCE_DIR="${3}"
FILE="${4}"

if [[ ! -e "${CMAKE_BINARY_DIR}/compile_commands.json" ]]; then
  echo "compile_commands.json not found!"
  exit 1
fi

# Filter out anything that we aren't trying to compile. Older clang-tidy
# versions (<=6) skipped them automatically.
if grep "${FILE}" "${CMAKE_BINARY_DIR}/compile_commands.json"; then
  ${CLANG_TIDY} -quiet -header-filter="\(${CMAKE_SOURCE_DIR}|\\.\\.\)/src/.*" --extra-arg-before=-Wno-unknown-warning-option -format-style=file -p "${CMAKE_BINARY_DIR}" "${FILE}"
else
  echo "Skipping ${FILE}"
fi

#! /bin/bash

set -euo pipefail

CLANG_TIDY="${1}"
CMAKE_BINARY_DIR="${2}"
CMAKE_SOURCE_DIR="${3}"
FILE="${4}"

if [[ ! -e "${CMAKE_BINARY_DIR}/compile_commands.json" ]]; then
  echo "compile_commands.json not found!"
  exit 1
fi

# Filter out anything that we aren't trying to compile. Older clang-tidy
# versions (<=6) skipped them automatically.
if grep -q "${FILE}" "${CMAKE_BINARY_DIR}/compile_commands.json"; then
  ${CLANG_TIDY} -quiet -header-filter="\(${CMAKE_SOURCE_DIR}|\\.\\.\)/src/.*" --extra-arg-before=-Wno-unknown-warning-option -format-style=file -p "${CMAKE_BINARY_DIR}" "${FILE}"
else
  echo "Skipping ${FILE}"
fi

Remove extra grep logs when running clang-tidy
Remove extra grep logs when running clang-tidy

Signed-off-by: Laurent Bonnans <0909bc0a3d1b0c91d8e00372b9633e8e9ea958de@here.com>
