#!/bin/sh -e

args=""
src=""

while [ -n "$1" ]; do
  arg="$1"
  args="${args} $1"
  shift

  if [ "${arg}" = "-c" ]; then
    src="$1"
    args="${args} $1"
    shift
  fi
done

# ignore third party code (which we don't control)
# generally it's found in `//third_party/` but is also found in
# `//src/gpu/vk/vulkanmemoryallocator` and in a generated folder when building
# dawn using CMake
if [ -n "${src}" ] && case "${src}" in
  *third_party* | *vulkanmemoryallocator* | *cmake_*) exit 1 ;;
  *) ;;
esac then
  clang-tidy -quiet -header-filter='.*' -warnings-as-errors='*' "${src}" -- "${args}"
fi
exec clang++ "${args}"
