bootstrap.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #
  2. # Copyright (c) 2020 Project CHIP 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. #
  16. _bootstrap_or_activate() {
  17. if [ -n "$BASH" ]; then
  18. local _BOOTSTRAP_PATH="${BASH_SOURCE[0]}"
  19. else
  20. local _BOOTSTRAP_PATH="$1"
  21. fi
  22. local _BOOTSTRAP_NAME="${_BOOTSTRAP_PATH##*/}"
  23. local _CHIP_ROOT="$(cd "${_BOOTSTRAP_PATH%/*}/.." && pwd)"
  24. local _CONFIG_FILE="scripts/environment.json"
  25. if [ "$_BOOTSTRAP_NAME" = "no_cipd_bootstrap.sh" ]; then
  26. _CONFIG_FILE="scripts/environment_no_cipd.json"
  27. _BOOTSTRAP_NAME="bootstrap.sh"
  28. fi
  29. if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
  30. [ ! -f "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh" ]; then
  31. git submodule update --init
  32. fi
  33. local _CHIP_BANNER="$(
  34. cat <<EOF
  35. ▄███▒ ░▓█ ░▓█ ░▓█▓ ▒█████▄
  36. ██▒ ▀█▒ ▒█ ▒█ ░█▒ ▒█░ █░
  37. █▓░ ▒██████ ░█▒ ▒█▄▄▄█░
  38. ▓█ █▒ ▒█ ▒█ ░█░ ▒█▀
  39. ░▓███▀ ░▓███░▓█▒ ░█░ ▒█
  40. EOF
  41. )"
  42. PW_PROJECT_ROOT="$_CHIP_ROOT"
  43. export PW_PROJECT_ROOT
  44. PW_ROOT="$_CHIP_ROOT/third_party/pigweed/repo"
  45. export PW_ROOT
  46. . "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh"
  47. _chip_bootstrap_banner() {
  48. if [ -z "$PW_ENVSETUP_QUIET" ] && [ -z "$PW_ENVSETUP_NO_BANNER" ]; then
  49. pw_bold_white "$_CHIP_BANNER\n"
  50. fi
  51. }
  52. local _PW_BANNER_FUNC="_chip_bootstrap_banner"
  53. export _PW_ACTUAL_ENVIRONMENT_ROOT="$(pw_get_env_root)"
  54. local _SETUP_SH="$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.sh"
  55. export PW_DOCTOR_SKIP_CIPD_CHECKS=1
  56. export PATH # https://bugs.chromium.org/p/pigweed/issues/detail?id=281
  57. if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
  58. [ ! -f "$_SETUP_SH" ] ||
  59. [ ! -s "$_SETUP_SH" ]; then
  60. pw_bootstrap --shell-file "$_SETUP_SH" \
  61. --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" \
  62. --config-file "$_CHIP_ROOT/$_CONFIG_FILE"
  63. pw_finalize bootstrap "$_SETUP_SH"
  64. else
  65. pw_activate
  66. pw_finalize activate "$_SETUP_SH"
  67. fi
  68. }
  69. _bootstrap_or_activate "$0"
  70. unset -f _bootstrap_or_activate
  71. pw_cleanup
  72. unset PW_CIPD_INSTALL_DIR
  73. unset CIPD_CACHE_DIR
  74. unset _PW_BANNER_FUNC
  75. unset _PW_TEXT
  76. unset PW_DOCTOR_SKIP_CIPD_CHECKS
  77. unset -f pw_cleanup
  78. unset -f _pw_hello
  79. unset -f _chip_bootstrap_banner