bootstrap.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 [ ! -z "$PW_CONFIG_FILE" ]; then
  26. _CONFIG_FILE="$PW_CONFIG_FILE"
  27. fi
  28. if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
  29. [ ! -f "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh" ]; then
  30. git submodule update --init
  31. fi
  32. PW_BRANDING_BANNER="$_CHIP_ROOT/scripts/matter_banner.txt"
  33. export PW_BRANDING_BANNER
  34. PW_PROJECT_ROOT="$_CHIP_ROOT"
  35. export PW_PROJECT_ROOT
  36. PW_ROOT="$_CHIP_ROOT/third_party/pigweed/repo"
  37. export PW_ROOT
  38. . "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh"
  39. _chip_bootstrap_banner() {
  40. if [ -z "$PW_ENVSETUP_QUIET" ] && [ -z "$PW_ENVSETUP_NO_BANNER" ]; then
  41. cat "$PW_BRANDING_BANNER"
  42. echo
  43. fi
  44. }
  45. local _PW_BANNER_FUNC="_chip_bootstrap_banner"
  46. export _PW_ACTUAL_ENVIRONMENT_ROOT="$(pw_get_env_root)"
  47. local _SETUP_SH="$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.sh"
  48. export PW_DOCTOR_SKIP_CIPD_CHECKS=1
  49. export PATH # https://bugs.chromium.org/p/pigweed/issues/detail?id=281
  50. if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
  51. [ ! -f "$_SETUP_SH" ] ||
  52. [ ! -s "$_SETUP_SH" ]; then
  53. pw_bootstrap --shell-file "$_SETUP_SH" \
  54. --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" \
  55. --config-file "$_CHIP_ROOT/$_CONFIG_FILE" \
  56. --virtualenv-gn-out-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT/gn_out"
  57. pw_finalize bootstrap "$_SETUP_SH"
  58. else
  59. pw_activate
  60. pw_finalize activate "$_SETUP_SH"
  61. fi
  62. }
  63. _bootstrap_or_activate "$0"
  64. unset -f _bootstrap_or_activate
  65. pw_cleanup
  66. unset PW_CIPD_INSTALL_DIR
  67. unset CIPD_CACHE_DIR
  68. unset _PW_BANNER_FUNC
  69. unset _PW_TEXT
  70. unset PW_DOCTOR_SKIP_CIPD_CHECKS
  71. unset -f _chip_bootstrap_banner