Anthony DiGirolamo | b302d74 | 2023-09-12 16:48:53 +0000 | [diff] [blame] | 1 | # Copyright 2023 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 sourced, not executed. |
| 16 | # |
| 17 | # Create a new environment: |
| 18 | # |
| 19 | # source bootstrap.sh |
| 20 | # |
| 21 | # Activate an existing environment: |
| 22 | # |
| 23 | # source activate.sh |
| 24 | |
| 25 | _bootstrap_abspath () { |
| 26 | $(command -v python3 || command -v python2 || command -v python) -c "import os.path; print(os.path.abspath('$@'))" |
| 27 | } |
| 28 | |
| 29 | # Shell: bash. |
| 30 | if test -n "$BASH"; then |
| 31 | _BOOTSTRAP_PATH="$(_bootstrap_abspath "$BASH_SOURCE")" |
| 32 | # Shell: zsh. |
| 33 | elif test -n "$ZSH_NAME"; then |
| 34 | _BOOTSTRAP_PATH="$(_bootstrap_abspath "${(%):-%N}")" |
| 35 | # Shell: dash. |
| 36 | elif test ${0##*/} = dash; then |
| 37 | _BOOTSTRAP_PATH="$(_bootstrap_abspath \ |
| 38 | "$(lsof -p $$ -Fn0 | tail -1 | sed 's#^[^/]*##;')")" |
| 39 | # If everything else fails, try $0. It could work. |
| 40 | else |
| 41 | _BOOTSTRAP_PATH="$(_bootstrap_abspath "$0")" |
| 42 | fi |
| 43 | |
| 44 | # Check if this file is being executed or sourced. |
| 45 | _pw_sourced=0 |
| 46 | if [ -n "$SWARMING_BOT_ID" ]; then |
| 47 | # If set we're running on swarming and don't need this check. |
| 48 | _pw_sourced=1 |
| 49 | elif [ -n "$ZSH_EVAL_CONTEXT" ]; then |
| 50 | case $ZSH_EVAL_CONTEXT in *:file) _pw_sourced=1;; esac |
| 51 | elif [ -n "$KSH_VERSION" ]; then |
| 52 | [ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != \ |
| 53 | "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] \ |
| 54 | && _pw_sourced=1 |
| 55 | elif [ -n "$BASH_VERSION" ]; then |
| 56 | (return 0 2>/dev/null) && _pw_sourced=1 |
| 57 | else # All other shells: examine $0 for known shell binary filenames |
| 58 | # Detects `sh` and `dash`; add additional shell filenames as needed. |
| 59 | case ${0##*/} in sh|dash) _pw_sourced=1;; esac |
| 60 | fi |
| 61 | |
| 62 | # Downstream projects need to set something other than PW_ROOT here, like |
| 63 | # YOUR_PROJECT_ROOT. Please also set PW_PROJECT_ROOT and PW_ROOT before |
| 64 | # invoking pw_bootstrap or pw_activate. |
| 65 | ######### BEGIN PROJECT-SPECIFIC CODE ######### |
| 66 | export KUDZU_ROOT="$(_bootstrap_abspath "$(dirname "$_BOOTSTRAP_PATH")")" |
| 67 | # Make pw experimental presubmit happy |
| 68 | export PIGWEED_EXPERIMENTAL_ROOT="$KUDZU_ROOT" |
Anthony DiGirolamo | 41de34b | 2024-06-06 20:08:19 +0000 | [diff] [blame] | 69 | export PW_PROJECT_ROOT="$KUDZU_ROOT" |
| 70 | export PW_ROOT="$KUDZU_ROOT/third_party/pigweed" |
Anthony DiGirolamo | b302d74 | 2023-09-12 16:48:53 +0000 | [diff] [blame] | 71 | |
| 72 | # Set your project's banner and color. |
| 73 | export PW_BRANDING_BANNER="$KUDZU_ROOT/banner.txt" |
| 74 | export PW_BRANDING_BANNER_COLOR=magenta |
| 75 | |
| 76 | KUDZU_banner() { |
| 77 | cat "$PW_BRANDING_BANNER" |
| 78 | echo |
| 79 | } |
| 80 | |
Anthony DiGirolamo | 41de34b | 2024-06-06 20:08:19 +0000 | [diff] [blame] | 81 | export PW_BANNER_FUNC="KUDZU_banner" |
Anthony DiGirolamo | b302d74 | 2023-09-12 16:48:53 +0000 | [diff] [blame] | 82 | ########## END PROJECT-SPECIFIC CODE ########## |
Anthony DiGirolamo | b302d74 | 2023-09-12 16:48:53 +0000 | [diff] [blame] | 83 | |
| 84 | _util_sh="$PW_ROOT/pw_env_setup/util.sh" |
| 85 | |
| 86 | # Double-check that the Pigweed submodule has been checked out. |
| 87 | if [ ! -e "$_util_sh" ]; then |
Armando Montanez | 76d7b19 | 2023-10-06 16:35:47 +0000 | [diff] [blame] | 88 | echo "Updating git submodules ..." |
| 89 | # Init without recursion. |
| 90 | git submodule update --init |
| 91 | fi |
Armando Montanez | 52ad5a7 | 2023-10-06 16:48:42 +0000 | [diff] [blame] | 92 | if [ ! -f "$PW_PROJECT_ROOT/third_party/pico-sdk/lib/tinyusb/LICENSE" ]; then |
Armando Montanez | 76d7b19 | 2023-10-06 16:35:47 +0000 | [diff] [blame] | 93 | echo "Updating git submodules for 'third_party/pico-sdk' ..." |
| 94 | # Init tinyusb only with no recursion. |
Armando Montanez | 52ad5a7 | 2023-10-06 16:48:42 +0000 | [diff] [blame] | 95 | pushd third_party/pico-sdk/ |
Armando Montanez | 76d7b19 | 2023-10-06 16:35:47 +0000 | [diff] [blame] | 96 | git submodule update --init lib/tinyusb |
| 97 | popd |
Anthony DiGirolamo | b302d74 | 2023-09-12 16:48:53 +0000 | [diff] [blame] | 98 | fi |
| 99 | |
| 100 | . "$_util_sh" |
| 101 | |
| 102 | pw_deactivate |
| 103 | pw_eval_sourced "$_pw_sourced" |
| 104 | pw_check_root "$PW_ROOT" |
| 105 | _PW_ACTUAL_ENVIRONMENT_ROOT="$(pw_get_env_root)" |
| 106 | export _PW_ACTUAL_ENVIRONMENT_ROOT |
| 107 | SETUP_SH="$_PW_ACTUAL_ENVIRONMENT_ROOT/activate.sh" |
| 108 | |
| 109 | # Run full bootstrap when invoked as bootstrap, or env file is missing/empty. |
| 110 | if [ "$(basename "$_BOOTSTRAP_PATH")" = "bootstrap.sh" ] || \ |
| 111 | [ ! -f "$SETUP_SH" ] || \ |
| 112 | [ ! -s "$SETUP_SH" ]; then |
| 113 | # This is where pw_bootstrap is called. Most small projects will include |
| 114 | # --use-pigweed-defaults. |
| 115 | ######### BEGIN PROJECT-SPECIFIC CODE ######### |
| 116 | pw_bootstrap --shell-file "$SETUP_SH" --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" --config-file "$PW_PROJECT_ROOT/pigweed.json" |
| 117 | ########## END PROJECT-SPECIFIC CODE ########## |
| 118 | pw_finalize bootstrap "$SETUP_SH" |
| 119 | else |
| 120 | pw_activate |
| 121 | pw_finalize activate "$SETUP_SH" |
| 122 | fi |
| 123 | |
| 124 | # This is where any additional checks about the environment should go. |
| 125 | ######### BEGIN PROJECT-SPECIFIC CODE ######### |
| 126 | ########## END PROJECT-SPECIFIC CODE ########## |
| 127 | |
| 128 | unset _pw_sourced |
| 129 | unset _BOOTSTRAP_PATH |
| 130 | unset SETUP_SH |
| 131 | unset _bootstrap_abspath |
| 132 | unset _util_sh |
| 133 | |
| 134 | pw_install_post_checkout_hook |
| 135 | |
Anthony DiGirolamo | 41de34b | 2024-06-06 20:08:19 +0000 | [diff] [blame] | 136 | if [[ "$TERM" != dumb ]]; then |
| 137 | # Shell completion: bash. |
| 138 | if test -n "$BASH"; then |
| 139 | . "$PW_ROOT/pw_cli/py/pw_cli/shell_completion/pw.bash" |
| 140 | . "$PW_ROOT/pw_cli/py/pw_cli/shell_completion/pw_build.bash" |
| 141 | # Shell completion: zsh. |
| 142 | elif test -n "$ZSH_NAME"; then |
| 143 | . "$PW_ROOT/pw_cli/py/pw_cli/shell_completion/pw.zsh" |
| 144 | . "$PW_ROOT/pw_cli/py/pw_cli/shell_completion/pw_build.zsh" |
| 145 | fi |
| 146 | fi |
| 147 | |
Anthony DiGirolamo | b302d74 | 2023-09-12 16:48:53 +0000 | [diff] [blame] | 148 | pw_cleanup |