verify-codecgen.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. kube::golang::setup_env
  21. generated_files=($(
  22. find . -not \( \
  23. \( \
  24. -wholename './output' \
  25. -o -wholename './_output' \
  26. -o -wholename './release' \
  27. -o -wholename './target' \
  28. -o -wholename '*/third_party/*' \
  29. -o -wholename '*/vendor/*' \
  30. \) -prune \
  31. \) -name '*.generated.go'))
  32. function cleanup {
  33. for generated_file in ${generated_files[@]}; do
  34. rm -f "${generated_file}.original"
  35. done
  36. }
  37. trap cleanup EXIT SIGINT
  38. for generated_file in ${generated_files[@]}; do
  39. cat "${generated_file}" > "${generated_file}.original"
  40. done
  41. ${KUBE_ROOT}/hack/update-codecgen.sh
  42. ret=0
  43. # Generate files in the dependency order.
  44. for generated_file in ${generated_files[@]}; do
  45. cur=0
  46. diff -Naupr -I 'Auto generated by' "${generated_file}" "${generated_file}.original" || cur=$?
  47. if [[ $cur -eq 0 ]]; then
  48. echo "${generated_file} up to date."
  49. else
  50. echo "${generated_file} was out of date. Please run hack/update-codecgen.sh. (If you're running locally, this was run for you already.)"
  51. ret=1
  52. fi
  53. done
  54. exit $ret