Rob Mohr | 709472a | 2020-04-17 11:50:47 -0700 | [diff] [blame] | 1 | :<<"::WINDOWS_ONLY" |
Alexei Frolov | d0e6954 | 2020-01-21 14:22:24 -0800 | [diff] [blame] | 2 | @echo off |
| 3 | :: Copyright 2020 The Pigweed Authors |
| 4 | :: |
| 5 | :: Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | :: use this file except in compliance with the License. You may obtain a copy of |
| 7 | :: the License at |
| 8 | :: |
| 9 | :: https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | :: |
| 11 | :: Unless required by applicable law or agreed to in writing, software |
| 12 | :: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | :: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | :: License for the specific language governing permissions and limitations under |
| 15 | :: the License. |
Rob Mohr | 709472a | 2020-04-17 11:50:47 -0700 | [diff] [blame] | 16 | ::WINDOWS_ONLY |
| 17 | :; echo "ERROR: Attempting to run Windows .bat from a Unix/POSIX shell!" |
| 18 | :; echo "Instead, run the following command." |
| 19 | :; echo "" |
| 20 | :; echo " source ./bootstrap.sh" |
| 21 | :; echo "" |
| 22 | :<<"::WINDOWS_ONLY" |
Alexei Frolov | d0e6954 | 2020-01-21 14:22:24 -0800 | [diff] [blame] | 23 | |
| 24 | :: Pigweed Windows environment setup. |
| 25 | |
Rob Mohr | 3700b7a | 2020-02-21 14:26:18 -0800 | [diff] [blame] | 26 | :: If PW_CHECKOUT_ROOT is set, use it. Users should not set this variable. |
| 27 | :: It's used because when one batch script invokes another the Powershell magic |
| 28 | :: below doesn't work. To reinforce that users should not be using |
| 29 | :: PW_CHECKOUT_ROOT, it is cleared here after it is used, and other pw tools |
| 30 | :: will complain if they see that variable set. |
| 31 | :: TODO(mohrr) find out a way to do this without PW_CHECKOUT_ROOT. |
| 32 | if "%PW_CHECKOUT_ROOT%"=="" ( |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 33 | :: ~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] | 34 | set "PW_ROOT=%~dp0" |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 35 | ) else ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 36 | set "PW_ROOT=%PW_CHECKOUT_ROOT%" |
Rob Mohr | 3700b7a | 2020-02-21 14:26:18 -0800 | [diff] [blame] | 37 | set PW_CHECKOUT_ROOT= |
| 38 | ) |
Alexei Frolov | d0e6954 | 2020-01-21 14:22:24 -0800 | [diff] [blame] | 39 | |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 40 | :: Allow forcing a specific Python version through the environment variable |
Alexei Frolov | ba4de1c | 2020-03-09 16:43:40 -0700 | [diff] [blame] | 41 | :: PW_BOOTSTRAP_PYTHON. Otherwise, use the system Python if one exists. |
| 42 | if not "%PW_BOOTSTRAP_PYTHON%" == "" ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 43 | set "python=%PW_BOOTSTRAP_PYTHON%" |
Alexei Frolov | ba4de1c | 2020-03-09 16:43:40 -0700 | [diff] [blame] | 44 | ) else ( |
| 45 | where python >NUL 2>&1 |
| 46 | if %ERRORLEVEL% EQU 0 ( |
| 47 | set python=python |
| 48 | ) else ( |
| 49 | echo. |
| 50 | echo Error: no system Python present |
| 51 | echo. |
| 52 | echo Pigweed's bootstrap process requires a local system Python. |
| 53 | echo Please install Python on your system, add it to your PATH |
| 54 | echo and re-try running bootstrap. |
| 55 | goto finish |
| 56 | ) |
| 57 | ) |
| 58 | |
Rob Mohr | ce87bc0 | 2020-07-15 11:16:17 -0700 | [diff] [blame] | 59 | :: Not prefixing environment with "." since that doesn't hide it anyway. |
| 60 | if "%PW_ENVIRONMENT_ROOT%"=="" ( |
| 61 | set "PW_ENVIRONMENT_ROOT=%PW_ROOT%\environment" |
| 62 | ) |
| 63 | set "shell_file=%PW_ENVIRONMENT_ROOT%\activate.bat" |
| 64 | |
Rob Mohr | d596a53 | 2020-04-03 08:59:12 -0700 | [diff] [blame] | 65 | set _PW_OLD_CIPD_PACKAGE_FILES=%PW_CIPD_PACKAGE_FILES% |
| 66 | set _PW_OLD_VIRTUALENV_REQUIREMENTS=%PW_VIRTUALENV_REQUIREMENTS% |
| 67 | set _PW_OLD_VIRTUALENV_SETUP_PY_ROOTS=%PW_VIRTUALENV_SETUP_PY_ROOTS% |
| 68 | set _PW_OLD_CARGO_PACKAGE_FILES=%PW_CARGO_PACKAGE_FILES% |
| 69 | |
Rob Mohr | f7d9657 | 2020-07-24 06:29:54 -0700 | [diff] [blame^] | 70 | set PW_CIPD_PACKAGE_FILES=%PW_ROOT%\pw_env_setup\py\pw_env_setup\cipd_setup\pigweed.json;%PW_ROOT%\pw_env_setup\py\pw_env_setup\cipd_setup\luci.json;%PW_CIPD_PACKAGE_FILES% |
Rob Mohr | d596a53 | 2020-04-03 08:59:12 -0700 | [diff] [blame] | 71 | set PW_VIRTUALENV_REQUIREMENTS=%PW_ROOT%\pw_env_setup\py\pw_env_setup\virtualenv_setup\requirements.txt;%PW_VIRTUALENV_REQUIREMENTS% |
| 72 | set PW_VIRTUALENV_SETUP_PY_ROOTS=%PW_ROOT%;%PW_VIRTUALENV_SETUP_PY_ROOTS% |
| 73 | set PW_CARGO_PACKAGE_FILES=%PW_ROOT%\pw_env_setup\py\pw_env_setup\cargo_setup\packages.txt;%PW_CARGO_PACKAGE_FILES% |
| 74 | |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 75 | set "_pw_start_script=%PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py" |
Alexei Frolov | b8aadc3 | 2020-01-23 10:46:14 -0800 | [diff] [blame] | 76 | |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 77 | :: If PW_SKIP_BOOTSTRAP is set, only run the activation stage instead of the |
| 78 | :: complete env_setup. |
| 79 | if "%PW_SKIP_BOOTSTRAP%" == "" ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 80 | :: Without the trailing slash in %PW_ROOT%/, batch combines that token with |
| 81 | :: the --shell-file argument. |
| 82 | call "%python%" "%PW_ROOT%\pw_env_setup\py\pw_env_setup\env_setup.py" ^ |
| 83 | --pw-root "%PW_ROOT%/" ^ |
Rob Mohr | ce87bc0 | 2020-07-15 11:16:17 -0700 | [diff] [blame] | 84 | --shell-file "%shell_file%" ^ |
| 85 | --install-dir "%PW_ENVIRONMENT_ROOT%" |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 86 | ) else ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 87 | if exist "%shell_file%" ( |
| 88 | call "%python%" "%_pw_start_script%" |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 89 | ) else ( |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 90 | call "%python%" "%_pw_start_script%" --no-shell-file |
Alexei Frolov | 4dcf99d | 2020-03-10 16:48:26 -0700 | [diff] [blame] | 91 | goto finish |
| 92 | ) |
Alexei Frolov | b8aadc3 | 2020-01-23 10:46:14 -0800 | [diff] [blame] | 93 | ) |
| 94 | |
Rob Mohr | d596a53 | 2020-04-03 08:59:12 -0700 | [diff] [blame] | 95 | set PW_CIPD_PACKAGE_FILES=%_PW_OLD_CIPD_PACKAGE_FILES% |
| 96 | set PW_VIRTUALENV_REQUIREMENTS=%_PW_OLD_VIRTUALENV_REQUIREMENTS% |
| 97 | set PW_VIRTUALENV_SETUP_PY_ROOTS=%_PW_OLD_VIRTUALENV_SETUP_PY_ROOTS% |
| 98 | set PW_CARGO_PACKAGE_FILES=%_PW_OLD_CARGO_PACKAGE_FILES% |
| 99 | |
Wyatt Hepler | 61682e8 | 2020-03-19 11:36:48 -0700 | [diff] [blame] | 100 | call "%shell_file%" |
Alexei Frolov | ba4de1c | 2020-03-09 16:43:40 -0700 | [diff] [blame] | 101 | |
| 102 | :finish |
Rob Mohr | 709472a | 2020-04-17 11:50:47 -0700 | [diff] [blame] | 103 | ::WINDOWS_ONLY |