blob: ea8e67b985c21fe1780b54c33c957272a9af0c0a [file] [log] [blame]
Robert Szewczyk38cf7312020-06-29 09:07:49 -07001#
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
Michael Spangc7ed2602020-10-20 18:21:14 -040017_bootstrap_or_activate() {
18 if [ -n "$BASH" ]; then
19 local _BOOTSTRAP_PATH="${BASH_SOURCE[0]}"
20 else
21 local _BOOTSTRAP_PATH="$1"
22 fi
Michael Spang871ce0b2020-06-26 11:47:03 -040023
Michael Spangc7ed2602020-10-20 18:21:14 -040024 local _BOOTSTRAP_NAME="${_BOOTSTRAP_PATH##*/}"
25 local _CHIP_ROOT="$(cd "${_BOOTSTRAP_PATH%/*}/.." && pwd)"
Michael Spang871ce0b2020-06-26 11:47:03 -040026
Rob Mohr5cda0bd2021-04-10 01:23:15 -070027 local _CONFIG_FILE="scripts/environment.json"
28
29 if [ "$_BOOTSTRAP_NAME" = "no_cipd_bootstrap.sh" ]; then
30 _CONFIG_FILE="scripts/environment_no_cipd.json"
31 _BOOTSTRAP_NAME="bootstrap.sh"
32 fi
33
Michael Spangc7ed2602020-10-20 18:21:14 -040034 if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
35 [ ! -f "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh" ]; then
36 git submodule update --init
37 fi
Michael Spangabccd702020-07-03 09:48:41 -040038
Michael Spangc7ed2602020-10-20 18:21:14 -040039 local _CHIP_BANNER="$(
40 cat <<EOF
Martin Turonfc07dcf2021-12-03 09:54:30 -080041 ░▓░
42 ▓█▓
43 ▓█▓ ▒█ ▒█
44 ▒██▒▒▓██▒███▒ ░▒▓▒░ ░▒▓▒░ ░░▓█▒░ ░█ █████████████░ ░▒█▒░ ░░▒░
45 ░▓█████▓██░ ▒█▒░░▒▓██▓▒░░▒█▒ ░█▓▒░░▒████ █▓░ █▓░ ▒█▒░░░▒█▓░ ██▒░░
46 ▒█▒░ ░██▒ ░█░ █▓ ░█░ ░▓▒ ░▓█ █▓ █▓ ▒█░░ ░██ ▒▓
47 ░▓██▓░ ░██▓█░ ░█ ▓█ █░ ░█░ ██ █▓ █▓ ▓██████████ ▒█
48 ░▓███▒ ▒███▒░ ░█ ▓█ █░ ██░ ░███ █▓ █▓ ░█▒░ ▒█
49 ░▒████████░ ░███▓▓█▓▓▒ ░█ ▒▒ █░ ░█▓██▓█░▒█ ░▓▓█░ ░▓▓█░ ▒▓▓██▓█░ ▒▓
50 ░██▒░ ▒██▒ ▒██░ ░▒█▓
51 ░▓░ ░▓░
Michael Spangc7ed2602020-10-20 18:21:14 -040052EOF
53 )"
Michael Spang871ce0b2020-06-26 11:47:03 -040054
szatmz2244db62020-12-04 14:42:01 -050055 PW_PROJECT_ROOT="$_CHIP_ROOT"
56 export PW_PROJECT_ROOT
57
Michael Spangc7ed2602020-10-20 18:21:14 -040058 PW_ROOT="$_CHIP_ROOT/third_party/pigweed/repo"
59 export PW_ROOT
szatmz4b82c2b2020-10-16 12:32:43 -040060
Andrei Litvina4201ea2022-04-11 06:37:33 -100061 # Do not force use Rosetta in Pigweed because Matter is using host toolchain
62 if [ -z "$PW_BOOTSTRAP_USE_ROSETTA" ]; then
63 export PW_BOOTSTRAP_USE_ROSETTA=false
64 fi
65
Michael Spangc7ed2602020-10-20 18:21:14 -040066 . "$_CHIP_ROOT/third_party/pigweed/repo/pw_env_setup/util.sh"
szatmz4b82c2b2020-10-16 12:32:43 -040067
Michael Spangc7ed2602020-10-20 18:21:14 -040068 _chip_bootstrap_banner() {
69 if [ -z "$PW_ENVSETUP_QUIET" ] && [ -z "$PW_ENVSETUP_NO_BANNER" ]; then
70 pw_bold_white "$_CHIP_BANNER\n"
71 fi
72 }
73
74 local _PW_BANNER_FUNC="_chip_bootstrap_banner"
75
76 export _PW_ACTUAL_ENVIRONMENT_ROOT="$(pw_get_env_root)"
77 local _SETUP_SH="$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.sh"
78
79 export PW_DOCTOR_SKIP_CIPD_CHECKS=1
Rob Walker5c21f072020-10-20 16:20:09 -070080 export PATH # https://bugs.chromium.org/p/pigweed/issues/detail?id=281
Michael Spangc7ed2602020-10-20 18:21:14 -040081
82 if [ "$_BOOTSTRAP_NAME" = "bootstrap.sh" ] ||
83 [ ! -f "$_SETUP_SH" ] ||
84 [ ! -s "$_SETUP_SH" ]; then
85 pw_bootstrap --shell-file "$_SETUP_SH" \
86 --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" \
Michael Spang2c81a992021-05-31 12:04:46 -040087 --config-file "$_CHIP_ROOT/$_CONFIG_FILE" \
88 --virtualenv-gn-out-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT/gn_out"
Michael Spangc7ed2602020-10-20 18:21:14 -040089 pw_finalize bootstrap "$_SETUP_SH"
90 else
91 pw_activate
92 pw_finalize activate "$_SETUP_SH"
93 fi
94}
95
96_bootstrap_or_activate "$0"
97unset -f _bootstrap_or_activate
98
99pw_cleanup
100
101unset PW_CIPD_INSTALL_DIR
102unset CIPD_CACHE_DIR
103unset _PW_BANNER_FUNC
104unset _PW_TEXT
105unset PW_DOCTOR_SKIP_CIPD_CHECKS
106
Michael Spangc7ed2602020-10-20 18:21:14 -0400107unset -f _chip_bootstrap_banner