bazel 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # Copyright 2019 The gRPC 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. # Keeping up with Bazel's breaking changes is currently difficult.
  16. # This script wraps calling bazel by downloading the currently
  17. # supported version, and then calling it. This way, we can make sure
  18. # that running bazel will always get meaningful results, at least
  19. # until Bazel 1.0 is released.
  20. # NOTE: This script relies on bazel's feature where //tools/bazel
  21. # script can be used to hijack "bazel" invocations in given workspace.
  22. set -e
  23. # DISABLE_BAZEL_WRAPPER can be set to eliminate the wrapper logic
  24. if [ "${DISABLE_BAZEL_WRAPPER}" != "" ] && [ "${OVERRIDE_BAZEL_VERSION}" == "" ]
  25. then
  26. if [ "${BAZEL_REAL}" != "" ]
  27. then
  28. # use BAZEL_REAL as set by
  29. # https://github.com/bazelbuild/bazel/blob/master/scripts/packages/bazel.sh
  30. # that originally invoked this script (this is what happens when you
  31. # run "bazel" in our workspace)
  32. exec -a "$0" "${BAZEL_REAL}" "$@"
  33. else
  34. # if BAZEL_REAL is not set, just invoke the default system bazel
  35. exec bazel "$@"
  36. fi
  37. fi
  38. # IMPORTANT: if you update the version here, other parts of infrastructure might needs updating as well
  39. # (e.g. sanity checks, bazel toolchains etc.)
  40. VERSION=${OVERRIDE_BAZEL_VERSION:-4.2.1}
  41. echo "INFO: Running bazel wrapper (see //tools/bazel for details), bazel version $VERSION will be used instead of system-wide bazel installation." >&2
  42. # update tools/update_mirror.sh to populate the mirror with new bazel archives
  43. BASEURL_MIRROR="https://storage.googleapis.com/grpc-bazel-mirror/github.com/bazelbuild/bazel/releases/download"
  44. BASEURL="https://github.com/bazelbuild/bazel/releases/download"
  45. pushd "$(dirname "$0")" >/dev/null
  46. # bazel binary will be downloaded to GRPC_REPO_ROOT/tools directory by default
  47. DOWNLOAD_DIR=${OVERRIDE_BAZEL_WRAPPER_DOWNLOAD_DIR:-$(pwd)}
  48. case $(uname -sm) in
  49. "Linux x86_64")
  50. suffix=linux-x86_64
  51. ;;
  52. "Linux aarch64")
  53. suffix=linux-arm64
  54. ;;
  55. "Darwin x86_64")
  56. suffix=darwin-x86_64
  57. ;;
  58. "MINGW"* | "MSYS_NT"*)
  59. suffix=windows-x86_64.exe
  60. ;;
  61. *)
  62. echo "Unsupported architecture: $(uname -sm)" >&2
  63. exit 1
  64. ;;
  65. esac
  66. filename="bazel-$VERSION-$suffix"
  67. filename_abs="${DOWNLOAD_DIR}/${filename}"
  68. if [ ! -x "${filename_abs}" ] ; then
  69. # first try to download using mirror, fallback to download from github
  70. echo "Downloading bazel, will try URLs: ${BASEURL_MIRROR}/${VERSION}/${filename} ${BASEURL}/${VERSION}/${filename}" >&2
  71. curl --fail -L --output "${filename_abs}" "${BASEURL_MIRROR}/${VERSION}/${filename}" || curl --fail -L --output "${filename_abs}" "${BASEURL}/${VERSION}/${filename}"
  72. chmod a+x "${filename_abs}"
  73. fi
  74. popd >/dev/null
  75. exec "${filename_abs}" "$@"