Alexei Frolov | d0e6954 | 2020-01-21 14:22:24 -0800 | [diff] [blame] | 1 | @echo off |
| 2 | :: Copyright 2020 The Pigweed Authors |
| 3 | :: |
| 4 | :: Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | :: use this file except in compliance with the License. You may obtain a copy of |
| 6 | :: the License at |
| 7 | :: |
| 8 | :: https://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, WITHOUT |
| 12 | :: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | :: License for the specific language governing permissions and limitations under |
| 14 | :: the License. |
| 15 | |
| 16 | :: Pigweed Windows environment setup. |
| 17 | |
Rob Mohr | 3700b7a | 2020-02-21 14:26:18 -0800 | [diff] [blame] | 18 | :: If PW_CHECKOUT_ROOT is set, use it. Users should not set this variable. |
| 19 | :: It's used because when one batch script invokes another the Powershell magic |
| 20 | :: below doesn't work. To reinforce that users should not be using |
| 21 | :: PW_CHECKOUT_ROOT, it is cleared here after it is used, and other pw tools |
| 22 | :: will complain if they see that variable set. |
| 23 | :: TODO(mohrr) find out a way to do this without PW_CHECKOUT_ROOT. |
| 24 | if "%PW_CHECKOUT_ROOT%"=="" ( |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 25 | :: ~dp0 is the batchism for the directory in which a .bat file resides. |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 26 | set "PW_ROOT=%~dp0" |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 27 | ) else ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 28 | set "PW_ROOT=%PW_CHECKOUT_ROOT%" |
Rob Mohr | 3700b7a | 2020-02-21 14:26:18 -0800 | [diff] [blame] | 29 | set PW_CHECKOUT_ROOT= |
| 30 | ) |
Alexei Frolov | d0e6954 | 2020-01-21 14:22:24 -0800 | [diff] [blame] | 31 | |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 32 | :: Allow forcing a specific Python version through the environment variable |
Alexei Frolov | ba4de1c | 2020-03-09 16:43:40 -0700 | [diff] [blame] | 33 | :: PW_BOOTSTRAP_PYTHON. Otherwise, use the system Python if one exists. |
| 34 | if not "%PW_BOOTSTRAP_PYTHON%" == "" ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 35 | set "python=%PW_BOOTSTRAP_PYTHON%" |
Alexei Frolov | ba4de1c | 2020-03-09 16:43:40 -0700 | [diff] [blame] | 36 | ) else ( |
| 37 | where python >NUL 2>&1 |
| 38 | if %ERRORLEVEL% EQU 0 ( |
| 39 | set python=python |
| 40 | ) else ( |
| 41 | echo. |
| 42 | echo Error: no system Python present |
| 43 | echo. |
| 44 | echo Pigweed's bootstrap process requires a local system Python. |
| 45 | echo Please install Python on your system, add it to your PATH |
| 46 | echo and re-try running bootstrap. |
| 47 | goto finish |
| 48 | ) |
| 49 | ) |
| 50 | |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 51 | set "_pw_start_script=%PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py" |
| 52 | set "shell_file=%PW_ROOT%\pw_env_setup\.env_setup.bat" |
Alexei Frolov | b8aadc3 | 2020-01-23 10:46:14 -0800 | [diff] [blame] | 53 | |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 54 | :: If PW_SKIP_BOOTSTRAP is set, only run the activation stage instead of the |
| 55 | :: complete env_setup. |
| 56 | if "%PW_SKIP_BOOTSTRAP%" == "" ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 57 | :: Without the trailing slash in %PW_ROOT%/, batch combines that token with |
| 58 | :: the --shell-file argument. |
| 59 | call "%python%" "%PW_ROOT%\pw_env_setup\py\pw_env_setup\env_setup.py" ^ |
| 60 | --pw-root "%PW_ROOT%/" ^ |
| 61 | --shell-file "%shell_file%" |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 62 | ) else ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 63 | if exist "%shell_file%" ( |
| 64 | call "%python%" "%_pw_start_script%" |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 65 | ) else ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 66 | call "%python%" "%_pw_start_script%" --no-shell-file |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 67 | goto finish |
| 68 | ) |
Alexei Frolov | b8aadc3 | 2020-01-23 10:46:14 -0800 | [diff] [blame] | 69 | ) |
| 70 | |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame^] | 71 | call "%shell_file%" |
Alexei Frolov | ba4de1c | 2020-03-09 16:43:40 -0700 | [diff] [blame] | 72 | |
| 73 | :finish |