1*61c4878aSAndroid Build Coastguard Worker# Copyright 2024 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Worker# This script must be tested on fish 3.6.0 16*61c4878aSAndroid Build Coastguard Worker 17*61c4878aSAndroid Build Coastguard Worker# Note: Colors are unfortunately duplicated in several places; and removing the 18*61c4878aSAndroid Build Coastguard Worker# duplication is not easy. Their locations are: 19*61c4878aSAndroid Build Coastguard Worker# 20*61c4878aSAndroid Build Coastguard Worker# - bootstrap.sh 21*61c4878aSAndroid Build Coastguard Worker# - pw_cli/color.py 22*61c4878aSAndroid Build Coastguard Worker# - pw_env_setup/py/pw_env_setup/colors.py 23*61c4878aSAndroid Build Coastguard Worker# - pw_env_setup/util.fish 24*61c4878aSAndroid Build Coastguard Worker# - pw_env_setup/util.sh 25*61c4878aSAndroid Build Coastguard Worker# 26*61c4878aSAndroid Build Coastguard Worker# So please keep them matching then modifying them. 27*61c4878aSAndroid Build Coastguard Workerfunction pw_none 28*61c4878aSAndroid Build Coastguard Worker set_color normal 29*61c4878aSAndroid Build Coastguard Worker echo -e $argv 30*61c4878aSAndroid Build Coastguard Workerend 31*61c4878aSAndroid Build Coastguard Worker 32*61c4878aSAndroid Build Coastguard Workerfunction pw_red 33*61c4878aSAndroid Build Coastguard Worker set_color red 34*61c4878aSAndroid Build Coastguard Worker echo -e $argv 35*61c4878aSAndroid Build Coastguard Worker set_color normal 36*61c4878aSAndroid Build Coastguard Workerend 37*61c4878aSAndroid Build Coastguard Worker 38*61c4878aSAndroid Build Coastguard Workerfunction pw_bold_red 39*61c4878aSAndroid Build Coastguard Worker set_color --bold red 40*61c4878aSAndroid Build Coastguard Worker echo -e $argv 41*61c4878aSAndroid Build Coastguard Worker set_color normal 42*61c4878aSAndroid Build Coastguard Workerend 43*61c4878aSAndroid Build Coastguard Worker 44*61c4878aSAndroid Build Coastguard Workerfunction pw_yellow 45*61c4878aSAndroid Build Coastguard Worker set_color yellow 46*61c4878aSAndroid Build Coastguard Worker echo -e $argv 47*61c4878aSAndroid Build Coastguard Worker set_color normal 48*61c4878aSAndroid Build Coastguard Workerend 49*61c4878aSAndroid Build Coastguard Worker 50*61c4878aSAndroid Build Coastguard Workerfunction pw_bold_yellow 51*61c4878aSAndroid Build Coastguard Worker set_color --bold yellow 52*61c4878aSAndroid Build Coastguard Worker echo -e $argv 53*61c4878aSAndroid Build Coastguard Worker set_color normal 54*61c4878aSAndroid Build Coastguard Workerend 55*61c4878aSAndroid Build Coastguard Worker 56*61c4878aSAndroid Build Coastguard Workerfunction pw_green 57*61c4878aSAndroid Build Coastguard Worker set_color green 58*61c4878aSAndroid Build Coastguard Worker echo -e $argv 59*61c4878aSAndroid Build Coastguard Worker set_color normal 60*61c4878aSAndroid Build Coastguard Workerend 61*61c4878aSAndroid Build Coastguard Worker 62*61c4878aSAndroid Build Coastguard Workerfunction pw_bold_green 63*61c4878aSAndroid Build Coastguard Worker set_color --bold green 64*61c4878aSAndroid Build Coastguard Worker echo -e $argv 65*61c4878aSAndroid Build Coastguard Worker set_color normal 66*61c4878aSAndroid Build Coastguard Workerend 67*61c4878aSAndroid Build Coastguard Worker 68*61c4878aSAndroid Build Coastguard Workerfunction pw_blue 69*61c4878aSAndroid Build Coastguard Worker set_color blue 70*61c4878aSAndroid Build Coastguard Worker echo -e $argv 71*61c4878aSAndroid Build Coastguard Worker set_color normal 72*61c4878aSAndroid Build Coastguard Workerend 73*61c4878aSAndroid Build Coastguard Worker 74*61c4878aSAndroid Build Coastguard Workerfunction pw_cyan 75*61c4878aSAndroid Build Coastguard Worker set_color cyan 76*61c4878aSAndroid Build Coastguard Worker echo -e $argv 77*61c4878aSAndroid Build Coastguard Worker set_color normal 78*61c4878aSAndroid Build Coastguard Workerend 79*61c4878aSAndroid Build Coastguard Worker 80*61c4878aSAndroid Build Coastguard Workerfunction pw_magenta 81*61c4878aSAndroid Build Coastguard Worker set_color magenta 82*61c4878aSAndroid Build Coastguard Worker echo -e $argv 83*61c4878aSAndroid Build Coastguard Worker set_color normal 84*61c4878aSAndroid Build Coastguard Workerend 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard Workerfunction pw_bold_white 87*61c4878aSAndroid Build Coastguard Worker set_color --bold white 88*61c4878aSAndroid Build Coastguard Worker echo -e $argv 89*61c4878aSAndroid Build Coastguard Worker set_color normal 90*61c4878aSAndroid Build Coastguard Workerend 91*61c4878aSAndroid Build Coastguard Worker 92*61c4878aSAndroid Build Coastguard Workerfunction pw_error 93*61c4878aSAndroid Build Coastguard Worker set_color --bold brred 94*61c4878aSAndroid Build Coastguard Worker echo -e $argv 1>&2 95*61c4878aSAndroid Build Coastguard Worker set_color normal 96*61c4878aSAndroid Build Coastguard Workerend 97*61c4878aSAndroid Build Coastguard Worker 98*61c4878aSAndroid Build Coastguard Workerfunction pw_error_info 99*61c4878aSAndroid Build Coastguard Worker set_color red 100*61c4878aSAndroid Build Coastguard Worker echo -e $argv 1>&2 101*61c4878aSAndroid Build Coastguard Worker set_color normal 102*61c4878aSAndroid Build Coastguard Workerend 103*61c4878aSAndroid Build Coastguard Worker 104*61c4878aSAndroid Build Coastguard Worker# Print an error and exit if $is_sourced == 0 (the first argument). 105*61c4878aSAndroid Build Coastguard Workerfunction pw_eval_sourced --argument-names is_sourced bootstrap_path 106*61c4878aSAndroid Build Coastguard Worker if test $is_sourced -eq 0 107*61c4878aSAndroid Build Coastguard Worker set _PW_NAME (basename $bootstrap_path) 108*61c4878aSAndroid Build Coastguard Worker pw_error "Error: Attempting to $_PW_NAME in a subshell" 109*61c4878aSAndroid Build Coastguard Worker pw_error_info " Since $_PW_NAME modifies your shell's environment" 110*61c4878aSAndroid Build Coastguard Worker pw_error_info " variables, it must be sourced rather than executed. In" 111*61c4878aSAndroid Build Coastguard Worker pw_error_info " particular, 'fish $_PW_NAME' will not work since the " 112*61c4878aSAndroid Build Coastguard Worker pw_error_info " modified environment will get destroyed at the end of the" 113*61c4878aSAndroid Build Coastguard Worker pw_error_info " script. Instead, source the script's contents in your" 114*61c4878aSAndroid Build Coastguard Worker pw_error_info " shell:" 115*61c4878aSAndroid Build Coastguard Worker pw_error_info "" 116*61c4878aSAndroid Build Coastguard Worker pw_error_info " \$ source $_PW_NAME" 117*61c4878aSAndroid Build Coastguard Worker exit 1 118*61c4878aSAndroid Build Coastguard Worker end 119*61c4878aSAndroid Build Coastguard Workerend 120*61c4878aSAndroid Build Coastguard Worker 121*61c4878aSAndroid Build Coastguard Worker# Check for spaces in $_PW_ROOT (the first argument). 122*61c4878aSAndroid Build Coastguard Workerfunction pw_check_root --argument-names _PW_ROOT 123*61c4878aSAndroid Build Coastguard Worker if string match --quiet '* *' $_PW_ROOT 124*61c4878aSAndroid Build Coastguard Worker pw_error "Error: The Pigweed path contains spaces" 125*61c4878aSAndroid Build Coastguard Worker pw_error_info " The path '$_PW_ROOT' contains spaces. " 126*61c4878aSAndroid Build Coastguard Worker pw_error_info " Pigweed's Python environment currently requires Pigweed to" 127*61c4878aSAndroid Build Coastguard Worker pw_error_info " be at a path without spaces. Please checkout Pigweed in a" 128*61c4878aSAndroid Build Coastguard Worker pw_error_info " directory without spaces and retry running bootstrap." 129*61c4878aSAndroid Build Coastguard Worker return -1 130*61c4878aSAndroid Build Coastguard Worker end 131*61c4878aSAndroid Build Coastguard Workerend 132*61c4878aSAndroid Build Coastguard Worker 133*61c4878aSAndroid Build Coastguard Worker# Check for and return the environment directory location. 134*61c4878aSAndroid Build Coastguard Workerfunction pw_get_env_root 135*61c4878aSAndroid Build Coastguard Worker # PW_ENVIRONMENT_ROOT allows callers to specify where the environment should 136*61c4878aSAndroid Build Coastguard Worker # be installed. bootstrap.sh scripts should not use that variable to store the 137*61c4878aSAndroid Build Coastguard Worker # result of this function. This separation allows scripts to assume 138*61c4878aSAndroid Build Coastguard Worker # PW_ENVIRONMENT_ROOT came from the caller and not from a previous bootstrap 139*61c4878aSAndroid Build Coastguard Worker # possibly from another workspace. PW_ENVIRONMENT_ROOT will be cleared after 140*61c4878aSAndroid Build Coastguard Worker # environment setup completes. 141*61c4878aSAndroid Build Coastguard Worker if set --query PW_ENVIRONMENT_ROOT 142*61c4878aSAndroid Build Coastguard Worker echo $PW_ENVIRONMENT_ROOT 143*61c4878aSAndroid Build Coastguard Worker return 144*61c4878aSAndroid Build Coastguard Worker end 145*61c4878aSAndroid Build Coastguard Worker 146*61c4878aSAndroid Build Coastguard Worker # Determine project-level root directory. 147*61c4878aSAndroid Build Coastguard Worker if set --query PW_PROJECT_ROOT 148*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_PREFIX $PW_PROJECT_ROOT 149*61c4878aSAndroid Build Coastguard Worker else 150*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_PREFIX $PW_ROOT 151*61c4878aSAndroid Build Coastguard Worker end 152*61c4878aSAndroid Build Coastguard Worker 153*61c4878aSAndroid Build Coastguard Worker # If <root>/environment exists, use it. Otherwise, if <root>/.environment 154*61c4878aSAndroid Build Coastguard Worker # exists, use it. Finally, use <root>/environment. 155*61c4878aSAndroid Build Coastguard Worker set _PW_DOTENV $_PW_ENV_PREFIX/.environment 156*61c4878aSAndroid Build Coastguard Worker set _PW_ENV $_PW_ENV_PREFIX/environment 157*61c4878aSAndroid Build Coastguard Worker 158*61c4878aSAndroid Build Coastguard Worker if test -d $_PW_DOTENV 159*61c4878aSAndroid Build Coastguard Worker if test -d $_PW_ENV 160*61c4878aSAndroid Build Coastguard Worker pw_error "Error: both possible environment directories exist." 161*61c4878aSAndroid Build Coastguard Worker pw_error_info " $_PW_DOTENV" 162*61c4878aSAndroid Build Coastguard Worker pw_error_info " $_PW_ENV" 163*61c4878aSAndroid Build Coastguard Worker pw_error_info " If only one of these folders exists it will be used for" 164*61c4878aSAndroid Build Coastguard Worker pw_error_info " the Pigweed environment. If neither exists" 165*61c4878aSAndroid Build Coastguard Worker pw_error_info " '<...>/environment' will be used. Since both exist," 166*61c4878aSAndroid Build Coastguard Worker pw_error_info " bootstrap doesn't know which to use. Please delete one" 167*61c4878aSAndroid Build Coastguard Worker pw_error_info " or both and rerun bootstrap." 168*61c4878aSAndroid Build Coastguard Worker exit 1 169*61c4878aSAndroid Build Coastguard Worker end 170*61c4878aSAndroid Build Coastguard Worker end 171*61c4878aSAndroid Build Coastguard Worker 172*61c4878aSAndroid Build Coastguard Worker if test -d $_PW_ENV 173*61c4878aSAndroid Build Coastguard Worker echo $_PW_ENV 174*61c4878aSAndroid Build Coastguard Worker else if test -d $_PW_DOTENV 175*61c4878aSAndroid Build Coastguard Worker echo $_PW_DOTENV 176*61c4878aSAndroid Build Coastguard Worker else 177*61c4878aSAndroid Build Coastguard Worker echo $_PW_ENV 178*61c4878aSAndroid Build Coastguard Worker end 179*61c4878aSAndroid Build Coastguard Workerend 180*61c4878aSAndroid Build Coastguard Worker 181*61c4878aSAndroid Build Coastguard Worker 182*61c4878aSAndroid Build Coastguard Workerset --export _PW_BANNER "\ 183*61c4878aSAndroid Build Coastguard Worker ▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄ 184*61c4878aSAndroid Build Coastguard Worker ▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌ 185*61c4878aSAndroid Build Coastguard Worker ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌ 186*61c4878aSAndroid Build Coastguard Worker ▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌ 187*61c4878aSAndroid Build Coastguard Worker ▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀ 188*61c4878aSAndroid Build Coastguard Worker" 189*61c4878aSAndroid Build Coastguard Worker 190*61c4878aSAndroid Build Coastguard Workerfunction _default_pw_banner_func 191*61c4878aSAndroid Build Coastguard Worker pw_magenta $_PW_BANNER 192*61c4878aSAndroid Build Coastguard Workerend 193*61c4878aSAndroid Build Coastguard Worker 194*61c4878aSAndroid Build Coastguard Workerset --export _PW_BANNER_FUNC _default_pw_banner_func 195*61c4878aSAndroid Build Coastguard Worker 196*61c4878aSAndroid Build Coastguard Workerfunction _pw_hello --argument-names _PW_TEXT 197*61c4878aSAndroid Build Coastguard Worker # If $PW_BANNER_FUNC is defined, use that as the banner function 198*61c4878aSAndroid Build Coastguard Worker # instead of the default. 199*61c4878aSAndroid Build Coastguard Worker if set --query PW_BANNER_FUNC 200*61c4878aSAndroid Build Coastguard Worker set _PW_BANNER_FUNC $PW_BANNER_FUNC 201*61c4878aSAndroid Build Coastguard Worker end 202*61c4878aSAndroid Build Coastguard Worker # Display the banner unless PW_ENVSETUP_QUIET or 203*61c4878aSAndroid Build Coastguard Worker # PW_ENVSETUP_NO_BANNER is set. 204*61c4878aSAndroid Build Coastguard Worker if test -z "$PW_ENVSETUP_QUIET" && test -z "$PW_ENVSETUP_NO_BANNER" 205*61c4878aSAndroid Build Coastguard Worker pw_green "\n WELCOME TO...\n" 206*61c4878aSAndroid Build Coastguard Worker set_color normal 207*61c4878aSAndroid Build Coastguard Worker $_PW_BANNER_FUNC 208*61c4878aSAndroid Build Coastguard Worker set_color normal 209*61c4878aSAndroid Build Coastguard Worker pw_green $_PW_TEXT 210*61c4878aSAndroid Build Coastguard Worker end 211*61c4878aSAndroid Build Coastguard Workerend 212*61c4878aSAndroid Build Coastguard Worker 213*61c4878aSAndroid Build Coastguard Workerfunction pw_deactivate 214*61c4878aSAndroid Build Coastguard Worker # Assume PW_ROOT and PW_PROJECT_ROOT have already been set and we need to 215*61c4878aSAndroid Build Coastguard Worker # preserve their values. 216*61c4878aSAndroid Build Coastguard Worker set _NEW_PW_ROOT $PW_ROOT 217*61c4878aSAndroid Build Coastguard Worker set _NEW_PW_PROJECT_ROOT $PW_PROJECT_ROOT 218*61c4878aSAndroid Build Coastguard Worker 219*61c4878aSAndroid Build Coastguard Worker # Find deactivate script, run it, and then delete it. This way if the 220*61c4878aSAndroid Build Coastguard Worker # deactivate script is doing something wrong subsequent bootstraps still 221*61c4878aSAndroid Build Coastguard Worker # have a chance to pass. 222*61c4878aSAndroid Build Coastguard Worker set _PW_DEACTIVATE_SH $_PW_ACTUAL_ENVIRONMENT_ROOT/deactivate.fish 223*61c4878aSAndroid Build Coastguard Worker if test -f $_PW_DEACTIVATE_SH 224*61c4878aSAndroid Build Coastguard Worker . $_PW_DEACTIVATE_SH 225*61c4878aSAndroid Build Coastguard Worker rm -f $_PW_DEACTIVATE_SH &>/dev/null 226*61c4878aSAndroid Build Coastguard Worker end 227*61c4878aSAndroid Build Coastguard Worker 228*61c4878aSAndroid Build Coastguard Worker # If there's a _pw_deactivate function run it. Redirect output to /dev/null 229*61c4878aSAndroid Build Coastguard Worker # in case _pw_deactivate doesn't exist. Remove _pw_deactivate when complete. 230*61c4878aSAndroid Build Coastguard Worker if functions --query _pw_deactivate 231*61c4878aSAndroid Build Coastguard Worker _pw_deactivate >/dev/null 2>/dev/null 232*61c4878aSAndroid Build Coastguard Worker functions -e _pw_deactivate 233*61c4878aSAndroid Build Coastguard Worker end 234*61c4878aSAndroid Build Coastguard Worker 235*61c4878aSAndroid Build Coastguard Worker # Restore. 236*61c4878aSAndroid Build Coastguard Worker set --export PW_ROOT $_NEW_PW_ROOT 237*61c4878aSAndroid Build Coastguard Worker set --export PW_PROJECT_ROOT $_NEW_PW_PROJECT_ROOT 238*61c4878aSAndroid Build Coastguard Workerend 239*61c4878aSAndroid Build Coastguard Worker 240*61c4878aSAndroid Build Coastguard Workerfunction deactivate 241*61c4878aSAndroid Build Coastguard Worker pw_deactivate 242*61c4878aSAndroid Build Coastguard Worker functions -e pw_deactivate 243*61c4878aSAndroid Build Coastguard Worker functions -e deactivate 244*61c4878aSAndroid Build Coastguard Worker set -e PW_ROOT 245*61c4878aSAndroid Build Coastguard Worker set -e PW_PROJECT_ROOT 246*61c4878aSAndroid Build Coastguard Worker set -e PW_BRANDING_BANNER 247*61c4878aSAndroid Build Coastguard Worker set -e PW_BRANDING_BANNER_COLOR 248*61c4878aSAndroid Build Coastguard Workerend 249*61c4878aSAndroid Build Coastguard Worker 250*61c4878aSAndroid Build Coastguard Worker# The next three functions use the following variables. 251*61c4878aSAndroid Build Coastguard Worker# * PW_BANNER_FUNC: function to print banner 252*61c4878aSAndroid Build Coastguard Worker# * PW_BOOTSTRAP_PYTHON: specific Python interpreter to use for bootstrap 253*61c4878aSAndroid Build Coastguard Worker# * PW_ROOT: path to Pigweed root 254*61c4878aSAndroid Build Coastguard Worker# * PW_ENVSETUP_QUIET: limit output if "true" 255*61c4878aSAndroid Build Coastguard Worker# 256*61c4878aSAndroid Build Coastguard Worker# All arguments passed in are passed on to env_setup.py in pw_bootstrap, 257*61c4878aSAndroid Build Coastguard Worker# pw_activate takes no arguments, and pw_finalize takes the name of the script 258*61c4878aSAndroid Build Coastguard Worker# "bootstrap" or "activate" and the path to the setup script written by 259*61c4878aSAndroid Build Coastguard Worker# bootstrap.fish. 260*61c4878aSAndroid Build Coastguard Workerfunction pw_bootstrap 261*61c4878aSAndroid Build Coastguard Worker _pw_hello " BOOTSTRAP! Bootstrap may take a few minutes; please be patient.\n" 262*61c4878aSAndroid Build Coastguard Worker 263*61c4878aSAndroid Build Coastguard Worker if functions --query python 264*61c4878aSAndroid Build Coastguard Worker pw_error "Error: 'python' is an alias" 265*61c4878aSAndroid Build Coastguard Worker pw_error_info "The shell has a 'python' alias set. This causes many obscure" 266*61c4878aSAndroid Build Coastguard Worker pw_error_info "Python-related issues both in and out of Pigweed. Please" 267*61c4878aSAndroid Build Coastguard Worker pw_error_info "remove the Python alias from your shell init file or at" 268*61c4878aSAndroid Build Coastguard Worker pw_error_info "least run the following command before bootstrapping" 269*61c4878aSAndroid Build Coastguard Worker pw_error_info "Pigweed." 270*61c4878aSAndroid Build Coastguard Worker pw_error_info 271*61c4878aSAndroid Build Coastguard Worker pw_error_info " functions --erase python" 272*61c4878aSAndroid Build Coastguard Worker pw_error_info 273*61c4878aSAndroid Build Coastguard Worker return 274*61c4878aSAndroid Build Coastguard Worker end 275*61c4878aSAndroid Build Coastguard Worker 276*61c4878aSAndroid Build Coastguard Worker # Allow forcing a specific version of Python for testing pursposes. 277*61c4878aSAndroid Build Coastguard Worker if test -n "$PW_BOOTSTRAP_PYTHON" 278*61c4878aSAndroid Build Coastguard Worker set _PW_PYTHON "$PW_BOOTSTRAP_PYTHON" 279*61c4878aSAndroid Build Coastguard Worker else if command -v python3 >/dev/null 2>/dev/null 280*61c4878aSAndroid Build Coastguard Worker set _PW_PYTHON python3 281*61c4878aSAndroid Build Coastguard Worker else if command -v python >/dev/null 2>/dev/null 282*61c4878aSAndroid Build Coastguard Worker set _PW_PYTHON python 283*61c4878aSAndroid Build Coastguard Worker else 284*61c4878aSAndroid Build Coastguard Worker pw_error "Error: No system Python present\n" 285*61c4878aSAndroid Build Coastguard Worker pw_error_info " Pigweed's bootstrap process requires a local system" 286*61c4878aSAndroid Build Coastguard Worker pw_error_info " Python. Please install Python on your system, add it to " 287*61c4878aSAndroid Build Coastguard Worker pw_error_info " your PATH and re-try running bootstrap." 288*61c4878aSAndroid Build Coastguard Worker return 289*61c4878aSAndroid Build Coastguard Worker end 290*61c4878aSAndroid Build Coastguard Worker 291*61c4878aSAndroid Build Coastguard Worker if test -n "$_PW_ENV_SETUP" 292*61c4878aSAndroid Build Coastguard Worker $_PW_ENV_SETUP $argv 293*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_SETUP_STATUS $status 294*61c4878aSAndroid Build Coastguard Worker else 295*61c4878aSAndroid Build Coastguard Worker $_PW_PYTHON $PW_ROOT/pw_env_setup/py/pw_env_setup/env_setup.py $argv 296*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_SETUP_STATUS $status 297*61c4878aSAndroid Build Coastguard Worker end 298*61c4878aSAndroid Build Coastguard Worker 299*61c4878aSAndroid Build Coastguard Worker # Write the directory path at bootstrap time into the directory. This helps 300*61c4878aSAndroid Build Coastguard Worker # us double-check things are still in the same space when calling activate. 301*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_ROOT_TXT $_PW_ACTUAL_ENVIRONMENT_ROOT/env_root.txt 302*61c4878aSAndroid Build Coastguard Worker echo $_PW_ACTUAL_ENVIRONMENT_ROOT >$_PW_ENV_ROOT_TXT 2>/dev/null 303*61c4878aSAndroid Build Coastguard Worker 304*61c4878aSAndroid Build Coastguard Worker # Create the environment README file. Use quotes to prevent alias expansion. 305*61c4878aSAndroid Build Coastguard Worker cp $PW_ROOT/pw_env_setup/destination.md $_PW_ACTUAL_ENVIRONMENT_ROOT/README.md &>/dev/null 306*61c4878aSAndroid Build Coastguard Workerend 307*61c4878aSAndroid Build Coastguard Worker 308*61c4878aSAndroid Build Coastguard Workerfunction pw_activate_message 309*61c4878aSAndroid Build Coastguard Worker _pw_hello " ACTIVATOR! This sets your shell environment variables.\n" 310*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_SETUP_STATUS 0 311*61c4878aSAndroid Build Coastguard Workerend 312*61c4878aSAndroid Build Coastguard Worker 313*61c4878aSAndroid Build Coastguard Workerfunction pw_finalize_pre_check --argument-names _PW_NAME _PW_SETUP_SH 314*61c4878aSAndroid Build Coastguard Worker # Check that the environment directory agrees that the path it's at matches 315*61c4878aSAndroid Build Coastguard Worker # where it thinks it should be. If not, bail. 316*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_ROOT_TXT "$_PW_ACTUAL_ENVIRONMENT_ROOT/env_root.txt" 317*61c4878aSAndroid Build Coastguard Worker if test -f $_PW_ENV_ROOT_TXT 318*61c4878aSAndroid Build Coastguard Worker set _PW_PREV_ENV_ROOT (cat $_PW_ENV_ROOT_TXT) 319*61c4878aSAndroid Build Coastguard Worker if test "$_PW_ACTUAL_ENVIRONMENT_ROOT" != "$_PW_PREV_ENV_ROOT" 320*61c4878aSAndroid Build Coastguard Worker pw_error "Error: Environment directory moved" 321*61c4878aSAndroid Build Coastguard Worker pw_error_info "This Pigweed environment was created at" 322*61c4878aSAndroid Build Coastguard Worker pw_error_info 323*61c4878aSAndroid Build Coastguard Worker pw_error_info " $_PW_PREV_ENV_ROOT" 324*61c4878aSAndroid Build Coastguard Worker pw_error_info 325*61c4878aSAndroid Build Coastguard Worker pw_error_info "But it is now being activated from" 326*61c4878aSAndroid Build Coastguard Worker pw_error_info 327*61c4878aSAndroid Build Coastguard Worker pw_error_info " $_PW_ACTUAL_ENVIRONMENT_ROOT" 328*61c4878aSAndroid Build Coastguard Worker pw_error_info 329*61c4878aSAndroid Build Coastguard Worker pw_error_info "This is likely because the checkout moved. After moving " 330*61c4878aSAndroid Build Coastguard Worker pw_error_info "the checkout a full '. ./bootstrap.fish' is required." 331*61c4878aSAndroid Build Coastguard Worker pw_error_info 332*61c4878aSAndroid Build Coastguard Worker set _PW_ENV_SETUP_STATUS 1 333*61c4878aSAndroid Build Coastguard Worker end 334*61c4878aSAndroid Build Coastguard Worker end 335*61c4878aSAndroid Build Coastguard Worker 336*61c4878aSAndroid Build Coastguard Worker if test -n "$_PW_ENV_SETUP_STATUS" && test "$_PW_ENV_SETUP_STATUS" -ne 0 337*61c4878aSAndroid Build Coastguard Worker return 338*61c4878aSAndroid Build Coastguard Worker end 339*61c4878aSAndroid Build Coastguard Worker 340*61c4878aSAndroid Build Coastguard Worker if not test -f "$_PW_SETUP_SH" 341*61c4878aSAndroid Build Coastguard Worker pw_error "Error during $_PW_NAME--see messages above." 342*61c4878aSAndroid Build Coastguard Worker end 343*61c4878aSAndroid Build Coastguard Workerend 344*61c4878aSAndroid Build Coastguard Worker 345*61c4878aSAndroid Build Coastguard Workerfunction pw_finalize_post_check --argument-names _PW_NAME _PW_SETUP_SH 346*61c4878aSAndroid Build Coastguard Worker if test "$status" -eq 0 347*61c4878aSAndroid Build Coastguard Worker if test "$_PW_NAME" = bootstrap && test -z "$PW_ENVSETUP_QUIET" 348*61c4878aSAndroid Build Coastguard Worker echo "To reactivate this environment in the future, run this in your " 349*61c4878aSAndroid Build Coastguard Worker echo "terminal:" 350*61c4878aSAndroid Build Coastguard Worker echo 351*61c4878aSAndroid Build Coastguard Worker pw_green " source ./activate.fish" 352*61c4878aSAndroid Build Coastguard Worker echo 353*61c4878aSAndroid Build Coastguard Worker echo "To deactivate this environment, run this:" 354*61c4878aSAndroid Build Coastguard Worker echo 355*61c4878aSAndroid Build Coastguard Worker pw_green " deactivate" 356*61c4878aSAndroid Build Coastguard Worker echo 357*61c4878aSAndroid Build Coastguard Worker end 358*61c4878aSAndroid Build Coastguard Worker else 359*61c4878aSAndroid Build Coastguard Worker pw_error "Error during $_PW_NAME--see messages above." 360*61c4878aSAndroid Build Coastguard Worker end 361*61c4878aSAndroid Build Coastguard Workerend 362*61c4878aSAndroid Build Coastguard Worker 363*61c4878aSAndroid Build Coastguard Workerfunction pw_install_post_checkout_hook 364*61c4878aSAndroid Build Coastguard Worker cp $PW_ROOT/pw_env_setup/post-checkout-hook.sh $PW_PROJECT_ROOT/.git/hooks/post-checkout 365*61c4878aSAndroid Build Coastguard Workerend 366*61c4878aSAndroid Build Coastguard Worker 367*61c4878aSAndroid Build Coastguard Workerfunction pw_cleanup 368*61c4878aSAndroid Build Coastguard Worker set -e _PW_BANNER 369*61c4878aSAndroid Build Coastguard Worker set -e _PW_BANNER_FUNC 370*61c4878aSAndroid Build Coastguard Worker set -e PW_BANNER_FUNC 371*61c4878aSAndroid Build Coastguard Worker set -e _PW_ENV_SETUP 372*61c4878aSAndroid Build Coastguard Worker set -e _PW_NAME 373*61c4878aSAndroid Build Coastguard Worker set -e PW_ENVIRONMENT_ROOT 374*61c4878aSAndroid Build Coastguard Worker set -e _PW_PYTHON 375*61c4878aSAndroid Build Coastguard Worker set -e _PW_ENV_ROOT_TXT 376*61c4878aSAndroid Build Coastguard Worker set -e _PW_PREV_ENV_ROOT 377*61c4878aSAndroid Build Coastguard Worker set -e _PW_SETUP_SH 378*61c4878aSAndroid Build Coastguard Worker set -e _PW_DEACTIVATE_SH 379*61c4878aSAndroid Build Coastguard Worker set -e _NEW_PW_ROOT 380*61c4878aSAndroid Build Coastguard Worker set -e _PW_ENV_SETUP_STATUS 381*61c4878aSAndroid Build Coastguard Worker set -e _PW_ENV_PREFIX 382*61c4878aSAndroid Build Coastguard Worker set -e _PW_ENV 383*61c4878aSAndroid Build Coastguard Worker set -e _PW_DOTENV 384*61c4878aSAndroid Build Coastguard Worker 385*61c4878aSAndroid Build Coastguard Worker functions -e pw_none 386*61c4878aSAndroid Build Coastguard Worker functions -e pw_red 387*61c4878aSAndroid Build Coastguard Worker functions -e pw_bold_red 388*61c4878aSAndroid Build Coastguard Worker functions -e pw_yellow 389*61c4878aSAndroid Build Coastguard Worker functions -e pw_bold_yellow 390*61c4878aSAndroid Build Coastguard Worker functions -e pw_green 391*61c4878aSAndroid Build Coastguard Worker functions -e pw_bold_green 392*61c4878aSAndroid Build Coastguard Worker functions -e pw_blue 393*61c4878aSAndroid Build Coastguard Worker functions -e pw_cyan 394*61c4878aSAndroid Build Coastguard Worker functions -e pw_magenta 395*61c4878aSAndroid Build Coastguard Worker functions -e pw_bold_white 396*61c4878aSAndroid Build Coastguard Worker functions -e pw_eval_sourced 397*61c4878aSAndroid Build Coastguard Worker functions -e pw_check_root 398*61c4878aSAndroid Build Coastguard Worker functions -e pw_get_env_root 399*61c4878aSAndroid Build Coastguard Worker functions -e _pw_banner 400*61c4878aSAndroid Build Coastguard Worker functions -e pw_bootstrap 401*61c4878aSAndroid Build Coastguard Worker functions -e pw_activate 402*61c4878aSAndroid Build Coastguard Worker functions -e pw_finalize 403*61c4878aSAndroid Build Coastguard Worker functions -e pw_install_post_checkout_hook 404*61c4878aSAndroid Build Coastguard Worker functions -e pw_cleanup 405*61c4878aSAndroid Build Coastguard Worker functions -e _pw_hello 406*61c4878aSAndroid Build Coastguard Worker functions -e pw_error 407*61c4878aSAndroid Build Coastguard Worker functions -e pw_error_info 408*61c4878aSAndroid Build Coastguard Workerend 409