#!/usr/bin/env bash

################################################################################
# Runs misc custom checks on repistory.
#
# Usage:
#     check/misc
################################################################################

# Get the working directory to the repo root.
thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
cd "${topdir}" || exit $?

# Check for non-contrib references to contrib.
results=$(grep -Rl "\bcirq\.contrib\b" cirq-core | grep -v "cirq/contrib" | grep -v "__")
RESULT=$?
if [ $RESULT -eq 0 ]; then
  echo -e "\033[31m'cirq.contrib' mentioned in non-contrib files:\033[0m"
  echo "${results}"
  echo
  echo -e "\033[31mSource files outside cirq.contrib must not reference cirq.contrib, as this can cause errors for users who 'pip install cirq' instead of 'pip install cirq-core[contrib]'.\033[0m"
  exit 1
fi

echo -e "\033[32mNo issues\033[0m."
