1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15# This script must be tested on fish 3.6.0 16 17# Get the absolute path of the bootstrap script. 18set _PW_BOOTSTRAP_PATH (path resolve (status current-filename)) 19 20# Check if this file is being executed or sourced. 21set _pw_sourced 0 22if string match --quiet '*from sourcing file*' (status) 23 set _pw_sourced 1 24end 25 26# Downstream projects need to set something other than PW_ROOT here, like 27# YOUR_PROJECT_ROOT. Please also set PW_PROJECT_ROOT and PW_ROOT before 28# invoking pw_bootstrap or pw_activate. 29######### BEGIN PROJECT-SPECIFIC CODE ######### 30set --export PW_ROOT (path resolve (dirname $_PW_BOOTSTRAP_PATH)) 31 32# Please also set PW_PROJECT_ROOT to YOUR_PROJECT_ROOT. 33set --export PW_PROJECT_ROOT $PW_ROOT 34 35# Downstream projects may wish to set PW_BANNER_FUNC to a function that prints 36# an ASCII art banner here. For example: 37# 38# set --export PW_BANNER_FUNC banner_function_name 39# 40########## END PROJECT-SPECIFIC CODE ########## 41 42source $PW_ROOT/pw_env_setup/util.fish 43 44# Check environment properties 45pw_deactivate 46pw_eval_sourced $_pw_sourced $_PW_BOOTSTRAP_PATH 47if not pw_check_root $PW_ROOT 48 return 49end 50 51set --export _PW_ACTUAL_ENVIRONMENT_ROOT (pw_get_env_root) 52 53set SETUP_SH "$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.fish" 54 55# Run full bootstrap when invoked as bootstrap, or env file is missing/empty. 56if test (status basename) = "bootstrap.fish" 57 or not test -e $SETUP_SH 58 or not test -s $SETUP_SH 59 ######### BEGIN PROJECT-SPECIFIC CODE ######### 60 pw_bootstrap --shell-file "$SETUP_SH" --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" 61 ########## END PROJECT-SPECIFIC CODE ########## 62 set finalize_mode bootstrap 63else 64 pw_activate_message 65 set finalize_mode activate 66end 67# NOTE: Sourced scripts in fish cannot be sourced within a fuction if 68# variables should be exported to the calling shell. So activate.fish 69# must be sourced here instead of within pw_finalize or another 70# function. 71pw_finalize_pre_check $finalize_mode "$SETUP_SH" 72source $SETUP_SH 73pw_finalize_post_check $finalize_mode "$SETUP_SH" 74 75if set --query _PW_ENV_SETUP_STATUS; and test "$_PW_ENV_SETUP_STATUS" -eq 0 76 # This is where any additional checks about the environment should go. 77 ######### BEGIN PROJECT-SPECIFIC CODE ######### 78 echo -n 79 ########## END PROJECT-SPECIFIC CODE ########## 80end 81 82set -e _pw_sourced 83set -e _PW_BOOTSTRAP_PATH 84set -e SETUP_SH 85 86source $PW_ROOT/pw_cli/py/pw_cli/shell_completion/pw.fish 87 88pw_cleanup 89 90git -C "$PW_ROOT" config blame.ignoreRevsFile .git-blame-ignore-revs 91