xref: /aosp_15_r20/external/pigweed/bootstrap.fish (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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# Get the absolute path of the bootstrap script.
18*61c4878aSAndroid Build Coastguard Workerset _PW_BOOTSTRAP_PATH (path resolve (status current-filename))
19*61c4878aSAndroid Build Coastguard Worker
20*61c4878aSAndroid Build Coastguard Worker# Check if this file is being executed or sourced.
21*61c4878aSAndroid Build Coastguard Workerset _pw_sourced 0
22*61c4878aSAndroid Build Coastguard Workerif string match --quiet '*from sourcing file*' (status)
23*61c4878aSAndroid Build Coastguard Worker    set _pw_sourced 1
24*61c4878aSAndroid Build Coastguard Workerend
25*61c4878aSAndroid Build Coastguard Worker
26*61c4878aSAndroid Build Coastguard Worker# Downstream projects need to set something other than PW_ROOT here, like
27*61c4878aSAndroid Build Coastguard Worker# YOUR_PROJECT_ROOT. Please also set PW_PROJECT_ROOT and PW_ROOT before
28*61c4878aSAndroid Build Coastguard Worker# invoking pw_bootstrap or pw_activate.
29*61c4878aSAndroid Build Coastguard Worker######### BEGIN PROJECT-SPECIFIC CODE #########
30*61c4878aSAndroid Build Coastguard Workerset --export PW_ROOT (path resolve (dirname $_PW_BOOTSTRAP_PATH))
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Worker# Please also set PW_PROJECT_ROOT to YOUR_PROJECT_ROOT.
33*61c4878aSAndroid Build Coastguard Workerset --export PW_PROJECT_ROOT $PW_ROOT
34*61c4878aSAndroid Build Coastguard Worker
35*61c4878aSAndroid Build Coastguard Worker# Downstream projects may wish to set PW_BANNER_FUNC to a function that prints
36*61c4878aSAndroid Build Coastguard Worker# an ASCII art banner here. For example:
37*61c4878aSAndroid Build Coastguard Worker#
38*61c4878aSAndroid Build Coastguard Worker#   set --export PW_BANNER_FUNC banner_function_name
39*61c4878aSAndroid Build Coastguard Worker#
40*61c4878aSAndroid Build Coastguard Worker########## END PROJECT-SPECIFIC CODE ##########
41*61c4878aSAndroid Build Coastguard Worker
42*61c4878aSAndroid Build Coastguard Workersource $PW_ROOT/pw_env_setup/util.fish
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard Worker# Check environment properties
45*61c4878aSAndroid Build Coastguard Workerpw_deactivate
46*61c4878aSAndroid Build Coastguard Workerpw_eval_sourced $_pw_sourced $_PW_BOOTSTRAP_PATH
47*61c4878aSAndroid Build Coastguard Workerif not pw_check_root $PW_ROOT
48*61c4878aSAndroid Build Coastguard Worker    return
49*61c4878aSAndroid Build Coastguard Workerend
50*61c4878aSAndroid Build Coastguard Worker
51*61c4878aSAndroid Build Coastguard Workerset --export _PW_ACTUAL_ENVIRONMENT_ROOT (pw_get_env_root)
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Workerset SETUP_SH "$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.fish"
54*61c4878aSAndroid Build Coastguard Worker
55*61c4878aSAndroid Build Coastguard Worker# Run full bootstrap when invoked as bootstrap, or env file is missing/empty.
56*61c4878aSAndroid Build Coastguard Workerif test (status basename) = "bootstrap.fish"
57*61c4878aSAndroid Build Coastguard Worker    or not test -e $SETUP_SH
58*61c4878aSAndroid Build Coastguard Worker    or not test -s $SETUP_SH
59*61c4878aSAndroid Build Coastguard Worker    ######### BEGIN PROJECT-SPECIFIC CODE #########
60*61c4878aSAndroid Build Coastguard Worker    pw_bootstrap --shell-file "$SETUP_SH" --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT"
61*61c4878aSAndroid Build Coastguard Worker    ########## END PROJECT-SPECIFIC CODE ##########
62*61c4878aSAndroid Build Coastguard Worker    set finalize_mode bootstrap
63*61c4878aSAndroid Build Coastguard Workerelse
64*61c4878aSAndroid Build Coastguard Worker    pw_activate_message
65*61c4878aSAndroid Build Coastguard Worker    set finalize_mode activate
66*61c4878aSAndroid Build Coastguard Workerend
67*61c4878aSAndroid Build Coastguard Worker# NOTE: Sourced scripts in fish cannot be sourced within a fuction if
68*61c4878aSAndroid Build Coastguard Worker# variables should be exported to the calling shell. So activate.fish
69*61c4878aSAndroid Build Coastguard Worker# must be sourced here instead of within pw_finalize or another
70*61c4878aSAndroid Build Coastguard Worker# function.
71*61c4878aSAndroid Build Coastguard Workerpw_finalize_pre_check $finalize_mode "$SETUP_SH"
72*61c4878aSAndroid Build Coastguard Workersource $SETUP_SH
73*61c4878aSAndroid Build Coastguard Workerpw_finalize_post_check $finalize_mode "$SETUP_SH"
74*61c4878aSAndroid Build Coastguard Worker
75*61c4878aSAndroid Build Coastguard Workerif set --query _PW_ENV_SETUP_STATUS; and test "$_PW_ENV_SETUP_STATUS" -eq 0
76*61c4878aSAndroid Build Coastguard Worker    # This is where any additional checks about the environment should go.
77*61c4878aSAndroid Build Coastguard Worker    ######### BEGIN PROJECT-SPECIFIC CODE #########
78*61c4878aSAndroid Build Coastguard Worker    echo -n
79*61c4878aSAndroid Build Coastguard Worker    ########## END PROJECT-SPECIFIC CODE ##########
80*61c4878aSAndroid Build Coastguard Workerend
81*61c4878aSAndroid Build Coastguard Worker
82*61c4878aSAndroid Build Coastguard Workerset -e _pw_sourced
83*61c4878aSAndroid Build Coastguard Workerset -e _PW_BOOTSTRAP_PATH
84*61c4878aSAndroid Build Coastguard Workerset -e SETUP_SH
85*61c4878aSAndroid Build Coastguard Worker
86*61c4878aSAndroid Build Coastguard Workersource $PW_ROOT/pw_cli/py/pw_cli/shell_completion/pw.fish
87*61c4878aSAndroid Build Coastguard Worker
88*61c4878aSAndroid Build Coastguard Workerpw_cleanup
89*61c4878aSAndroid Build Coastguard Worker
90*61c4878aSAndroid Build Coastguard Workergit -C "$PW_ROOT" config blame.ignoreRevsFile .git-blame-ignore-revs
91