bootstrap.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 _BOOTSTRAP_DIR="${_BOOTSTRAP_PATH%/*}"
  24. # Strip off the 'scripts[/setup]' directory, leaving the root of the repo.
  25. local _CHIP_ROOT="$(cd "${_BOOTSTRAP_DIR%/setup}/.." && pwd)"
  26. local _CONFIG_FILE="scripts/setup/environment.json"
  27. if [ -n "$PW_CONFIG_FILE" ]; then
  28. _CONFIG_FILE="$PW_CONFIG_FILE"
  29. unset PW_CONFIG_FILE
  30. fi
  31. if [ ! -f "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh" ]; then
  32. # Make sure our submodule remotes are correct for this revision.
  33. git submodule sync --recursive
  34. git submodule update --init
  35. elif [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ]; then
  36. # In this case, only update already checked out submodules.
  37. git submodule sync --recursive
  38. git submodule update
  39. fi
  40. PW_BRANDING_BANNER="$_CHIP_ROOT/scripts/setup/banner.txt"
  41. export PW_BRANDING_BANNER
  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. cat "$PW_BRANDING_BANNER"
  50. echo
  51. fi
  52. }
  53. local _PW_BANNER_FUNC="_chip_bootstrap_banner"
  54. # Force the Pigweed environment directory to be '.environment'
  55. if [ -z "$PW_ENVIRONMENT_ROOT" ]; then
  56. export PW_ENVIRONMENT_ROOT="$PW_PROJECT_ROOT/.environment"
  57. fi
  58. export _PW_ACTUAL_ENVIRONMENT_ROOT="$(pw_get_env_root)"
  59. local _SETUP_SH="$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.sh"
  60. export PW_DOCTOR_SKIP_CIPD_CHECKS=1
  61. export PATH # https://bugs.chromium.org/p/pigweed/issues/detail?id=281
  62. if test -n "$GITHUB_ACTION"; then
  63. mkdir -p "$_PW_ACTUAL_ENVIRONMENT_ROOT"
  64. tee <<EOF >"${_PW_ACTUAL_ENVIRONMENT_ROOT}/pip.conf"
  65. [global]
  66. cache-dir = ${_PW_ACTUAL_ENVIRONMENT_ROOT}/pip-cache
  67. EOF
  68. export PIP_CONFIG_FILE="$_PW_ACTUAL_ENVIRONMENT_ROOT/pip.conf"
  69. fi
  70. if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
  71. [ ! -f "$_SETUP_SH" ] ||
  72. [ ! -s "$_SETUP_SH" ]; then
  73. pw_bootstrap --shell-file "$_SETUP_SH" \
  74. --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" \
  75. --config-file "$_CHIP_ROOT/$_CONFIG_FILE" \
  76. --virtualenv-gn-out-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT/gn_out"
  77. pw_finalize bootstrap "$_SETUP_SH"
  78. else
  79. pw_activate
  80. pw_finalize activate "$_SETUP_SH"
  81. fi
  82. }
  83. _bootstrap_or_activate "$0"
  84. unset -f _bootstrap_or_activate
  85. pw_cleanup
  86. unset PW_CIPD_INSTALL_DIR
  87. unset CIPD_CACHE_DIR
  88. unset _PW_BANNER_FUNC
  89. unset _PW_TEXT
  90. unset PW_DOCTOR_SKIP_CIPD_CHECKS
  91. unset -f _chip_bootstrap_banner