verify-bazel.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. # Copyright 2016 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[0]}")/..
  19. export KUBE_ROOT
  20. source "${KUBE_ROOT}/hack/lib/init.sh"
  21. if [[ ! -f "${KUBE_ROOT}/vendor/BUILD" ]]; then
  22. echo "${KUBE_ROOT}/vendor/BUILD does not exist." >&2
  23. echo >&2
  24. echo "Run ./hack/update-bazel.sh" >&2
  25. exit 1
  26. fi
  27. # Remove generated files prior to running kazel.
  28. # TODO(spxtr): Remove this line once Bazel is the only way to build.
  29. rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
  30. _tmpdir="$(kube::realpath "$(mktemp -d -t verify-bazel.XXXXXX)")"
  31. kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
  32. _tmp_gopath="${_tmpdir}/go"
  33. _tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
  34. mkdir -p "${_tmp_kuberoot}/.."
  35. cp -a "${KUBE_ROOT}" "${_tmp_kuberoot}/.."
  36. cd "${_tmp_kuberoot}"
  37. GOPATH="${_tmp_gopath}" PATH="${_tmp_gopath}/bin:${PATH}" ./hack/update-bazel.sh
  38. diff=$(diff -Naupr -x '_output' "${KUBE_ROOT}" "${_tmp_kuberoot}" || true)
  39. if [[ -n "${diff}" ]]; then
  40. echo "${diff}" >&2
  41. echo >&2
  42. echo "Run ./hack/update-bazel.sh" >&2
  43. exit 1
  44. fi