verify-bazel.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # This script checks whether updating of the bazel compilation files is needed
  16. # or not. We should run `hack/update-bazel.sh` if actually updates them.
  17. # Usage: `hack/verify-bazel.sh`.
  18. set -o errexit
  19. set -o nounset
  20. set -o pipefail
  21. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  22. export KUBE_ROOT
  23. source "${KUBE_ROOT}/hack/lib/init.sh"
  24. if [[ ! -f "${KUBE_ROOT}/vendor/BUILD" ]]; then
  25. echo "${KUBE_ROOT}/vendor/BUILD does not exist." >&2
  26. echo >&2
  27. echo "Run ./hack/update-bazel.sh" >&2
  28. exit 1
  29. fi
  30. # Remove generated files prior to running kazel.
  31. # TODO(spxtr): Remove this line once Bazel is the only way to build.
  32. rm -f "${KUBE_ROOT}/{pkg/generated,staging/src/k8s.io/apiextensions-apiserver/pkg/client,staging/src/k8s.io/kube-aggregator/pkg/client}/openapi/zz_generated.openapi.go"
  33. _tmpdir="$(kube::realpath "$(mktemp -d -t verify-bazel.XXXXXX)")"
  34. kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
  35. _tmp_gopath="${_tmpdir}/go"
  36. _tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
  37. mkdir -p "${_tmp_kuberoot}/.."
  38. cp -a "${KUBE_ROOT}" "${_tmp_kuberoot}/.."
  39. cd "${_tmp_kuberoot}"
  40. GOPATH="${_tmp_gopath}" PATH="${_tmp_gopath}/bin:${PATH}" ./hack/update-bazel.sh
  41. diff=$(diff -Naupr -x '_output' "${KUBE_ROOT}" "${_tmp_kuberoot}" || true)
  42. if [[ -n "${diff}" ]]; then
  43. echo "${diff}" >&2
  44. echo >&2
  45. echo "Run ./hack/update-bazel.sh" >&2
  46. exit 1
  47. fi