blob: 2cf0cdf34005e143b16dcc636c2d6695d4e3b913 [file] [log] [blame]
Alexei Frolovd0e69542020-01-21 14:22:24 -08001@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 Mohr3700b7a2020-02-21 14:26:18 -080018:: 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.
24if "%PW_CHECKOUT_ROOT%"=="" (
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070025 :: ~dp0 is the batchism for the directory in which a .bat file resides.
Wyatt Hepler61682e82020-03-19 11:36:48 -070026 set "PW_ROOT=%~dp0"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070027) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070028 set "PW_ROOT=%PW_CHECKOUT_ROOT%"
Rob Mohr3700b7a2020-02-21 14:26:18 -080029 set PW_CHECKOUT_ROOT=
30)
Alexei Frolovd0e69542020-01-21 14:22:24 -080031
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070032:: Allow forcing a specific Python version through the environment variable
Alexei Frolovba4de1c2020-03-09 16:43:40 -070033:: PW_BOOTSTRAP_PYTHON. Otherwise, use the system Python if one exists.
34if not "%PW_BOOTSTRAP_PYTHON%" == "" (
Wyatt Hepler61682e82020-03-19 11:36:48 -070035 set "python=%PW_BOOTSTRAP_PYTHON%"
Alexei Frolovba4de1c2020-03-09 16:43:40 -070036) 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 Hepler61682e82020-03-19 11:36:48 -070051set "_pw_start_script=%PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py"
52set "shell_file=%PW_ROOT%\pw_env_setup\.env_setup.bat"
Alexei Frolovb8aadc32020-01-23 10:46:14 -080053
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070054:: If PW_SKIP_BOOTSTRAP is set, only run the activation stage instead of the
55:: complete env_setup.
56if "%PW_SKIP_BOOTSTRAP%" == "" (
Wyatt Hepler61682e82020-03-19 11:36:48 -070057 :: 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 Frolov4dcf99d2020-03-10 16:48:26 -070062) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070063 if exist "%shell_file%" (
64 call "%python%" "%_pw_start_script%"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070065 ) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070066 call "%python%" "%_pw_start_script%" --no-shell-file
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070067 goto finish
68 )
Alexei Frolovb8aadc32020-01-23 10:46:14 -080069)
70
Wyatt Hepler61682e82020-03-19 11:36:48 -070071call "%shell_file%"
Alexei Frolovba4de1c2020-03-09 16:43:40 -070072
73:finish