clean-check 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. set -eu -o pipefail
  3. top_dir="$(readlink -m "${BASH_SOURCE[0]}/../..")"
  4. # Also allow operation on a copy named ${orig_top_dir}.clean-check.${something}
  5. # I.e., .../graphene.clean-check.test/Scripts/clean-check will check:
  6. # .../graphene.clean-check.test against .../graphene.clean-check.clean
  7. clean_dir="${top_dir%.clean-check.*}.clean-check.clean"
  8. if [ -n "${JENKINS_HOME:-}" ]; then
  9. clean_dir="/tmp/$(basename "$clean_dir")"
  10. fi
  11. show_diff=false
  12. if [ "${1:-}" == "--show-diff" ]; then
  13. show_diff=true
  14. fi
  15. if ! [ -d "$clean_dir" ]; then
  16. echo "ERROR: Copy of clean source directory not found!"
  17. echo
  18. echo "You need to call clean-check-prepare on the clean source directory before using"
  19. echo "clean-check."
  20. exit 1
  21. fi
  22. trap 'rm -rf "$diff"' EXIT
  23. diff="$(mktemp)"
  24. if [ "$show_diff" == true ]; then
  25. diff_opts="-u"
  26. else
  27. diff_opts="-q"
  28. fi
  29. ok=true
  30. diff "$diff_opts" -x .git -r "$clean_dir" "$top_dir" > "$diff" || ok=false
  31. if [ "$ok" == true ]; then
  32. echo "Source tree is unchanged. :]"
  33. exit 0
  34. fi
  35. echo "================================================================================"
  36. echo " ERROR: Source tree is not unchanged after clean:"
  37. echo "--------------------------------------------------------------------------------"
  38. cat "$diff"
  39. echo "================================================================================"
  40. exit 1