generate-bindata.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 pipefail
  17. set -o nounset
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  19. export KUBE_ROOT
  20. source "${KUBE_ROOT}/hack/lib/init.sh"
  21. source "${KUBE_ROOT}/hack/lib/logging.sh"
  22. if [[ ! -d "${KUBE_ROOT}/pkg" ]]; then
  23. echo "${KUBE_ROOT}/pkg not detected. This script should be run from a location where the source dirs are available."
  24. exit 1
  25. fi
  26. # kube::golang::build_kube_toolchain installs the vendored go-bindata in
  27. # $GOPATH/bin, so make sure that's explicitly part of our $PATH.
  28. export PATH="${KUBE_OUTPUT_BINPATH}:${PATH}"
  29. if ! which go-bindata &>/dev/null ; then
  30. echo "Cannot find go-bindata."
  31. exit 5
  32. fi
  33. # run the generation from the root directory for stable output
  34. pushd "${KUBE_ROOT}" >/dev/null
  35. # These are files for e2e tests.
  36. BINDATA_OUTPUT="test/e2e/generated/bindata.go"
  37. # IMPORTANT: if you make any changes to these arguments, you must also update
  38. # test/e2e/generated/BUILD and/or build/bindata.bzl.
  39. go-bindata -nometadata -o "${BINDATA_OUTPUT}.tmp" -pkg generated \
  40. -ignore .jpg -ignore .png -ignore .md -ignore 'BUILD(\.bazel)?' \
  41. "test/e2e/testing-manifests/..." \
  42. "test/images/..." \
  43. "test/fixtures/..."
  44. gofmt -s -w "${BINDATA_OUTPUT}.tmp"
  45. # Here we compare and overwrite only if different to avoid updating the
  46. # timestamp and triggering a rebuild. The 'cat' redirect trick to preserve file
  47. # permissions of the target file.
  48. if ! cmp -s "${BINDATA_OUTPUT}.tmp" "${BINDATA_OUTPUT}" ; then
  49. cat "${BINDATA_OUTPUT}.tmp" > "${BINDATA_OUTPUT}"
  50. V=2 kube::log::info "Generated bindata file : ${BINDATA_OUTPUT} has $(wc -l ${BINDATA_OUTPUT}) lines of lovely automated artifacts"
  51. else
  52. V=2 kube::log::info "No changes in generated bindata file: ${BINDATA_OUTPUT}"
  53. fi
  54. rm -f "${BINDATA_OUTPUT}.tmp"
  55. # These are files for runtime code
  56. BINDATA_OUTPUT="pkg/kubectl/generated/bindata.go"
  57. # IMPORTANT: if you make any changes to these arguments, you must also update
  58. # pkg/generated/BUILD and/or build/bindata.bzl.
  59. go-bindata -nometadata -nocompress -o "${BINDATA_OUTPUT}.tmp" -pkg generated \
  60. -ignore .jpg -ignore .png -ignore .md -ignore 'BUILD(\.bazel)?' \
  61. "translations/..."
  62. gofmt -s -w "${BINDATA_OUTPUT}.tmp"
  63. # Here we compare and overwrite only if different to avoid updating the
  64. # timestamp and triggering a rebuild. The 'cat' redirect trick to preserve file
  65. # permissions of the target file.
  66. if ! cmp -s "${BINDATA_OUTPUT}.tmp" "${BINDATA_OUTPUT}" ; then
  67. cat "${BINDATA_OUTPUT}.tmp" > "${BINDATA_OUTPUT}"
  68. V=2 kube::log::info "Generated bindata file : ${BINDATA_OUTPUT} has $(wc -l ${BINDATA_OUTPUT}) lines of lovely automated artifacts"
  69. else
  70. V=2 kube::log::info "No changes in generated bindata file: ${BINDATA_OUTPUT}"
  71. fi
  72. rm -f "${BINDATA_OUTPUT}.tmp"
  73. popd >/dev/null