blob: 7abe3a422528e66190bf415304c07ef8eff3d85a [file] [log] [blame]
Rob Mohr709472a2020-04-17 11:50:47 -07001:<<"::WINDOWS_ONLY"
Alexei Frolovd0e69542020-01-21 14:22:24 -08002@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 Mohr709472a2020-04-17 11:50:47 -070016::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 Frolovd0e69542020-01-21 14:22:24 -080023
24:: Pigweed Windows environment setup.
25
Rob Mohr3700b7a2020-02-21 14:26:18 -080026:: 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.
32if "%PW_CHECKOUT_ROOT%"=="" (
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070033 :: ~dp0 is the batchism for the directory in which a .bat file resides.
Wyatt Hepler61682e82020-03-19 11:36:48 -070034 set "PW_ROOT=%~dp0"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070035) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070036 set "PW_ROOT=%PW_CHECKOUT_ROOT%"
Rob Mohr3700b7a2020-02-21 14:26:18 -080037 set PW_CHECKOUT_ROOT=
38)
Alexei Frolovd0e69542020-01-21 14:22:24 -080039
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070040:: Allow forcing a specific Python version through the environment variable
Alexei Frolovba4de1c2020-03-09 16:43:40 -070041:: PW_BOOTSTRAP_PYTHON. Otherwise, use the system Python if one exists.
42if not "%PW_BOOTSTRAP_PYTHON%" == "" (
Wyatt Hepler61682e82020-03-19 11:36:48 -070043 set "python=%PW_BOOTSTRAP_PYTHON%"
Alexei Frolovba4de1c2020-03-09 16:43:40 -070044) 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 Mohrd596a532020-04-03 08:59:12 -070059set _PW_OLD_CIPD_PACKAGE_FILES=%PW_CIPD_PACKAGE_FILES%
60set _PW_OLD_VIRTUALENV_REQUIREMENTS=%PW_VIRTUALENV_REQUIREMENTS%
61set _PW_OLD_VIRTUALENV_SETUP_PY_ROOTS=%PW_VIRTUALENV_SETUP_PY_ROOTS%
62set _PW_OLD_CARGO_PACKAGE_FILES=%PW_CARGO_PACKAGE_FILES%
63
64set PW_CIPD_PACKAGE_FILES=%PW_ROOT%\pw_env_setup\py\pw_env_setup\cipd_setup\*.json;%PW_CIPD_PACKAGE_FILES%
65set PW_VIRTUALENV_REQUIREMENTS=%PW_ROOT%\pw_env_setup\py\pw_env_setup\virtualenv_setup\requirements.txt;%PW_VIRTUALENV_REQUIREMENTS%
66set PW_VIRTUALENV_SETUP_PY_ROOTS=%PW_ROOT%;%PW_VIRTUALENV_SETUP_PY_ROOTS%
67set PW_CARGO_PACKAGE_FILES=%PW_ROOT%\pw_env_setup\py\pw_env_setup\cargo_setup\packages.txt;%PW_CARGO_PACKAGE_FILES%
68
Wyatt Hepler61682e82020-03-19 11:36:48 -070069set "_pw_start_script=%PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py"
70set "shell_file=%PW_ROOT%\pw_env_setup\.env_setup.bat"
Alexei Frolovb8aadc32020-01-23 10:46:14 -080071
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070072:: If PW_SKIP_BOOTSTRAP is set, only run the activation stage instead of the
73:: complete env_setup.
74if "%PW_SKIP_BOOTSTRAP%" == "" (
Wyatt Hepler61682e82020-03-19 11:36:48 -070075 :: Without the trailing slash in %PW_ROOT%/, batch combines that token with
76 :: the --shell-file argument.
77 call "%python%" "%PW_ROOT%\pw_env_setup\py\pw_env_setup\env_setup.py" ^
78 --pw-root "%PW_ROOT%/" ^
79 --shell-file "%shell_file%"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070080) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070081 if exist "%shell_file%" (
82 call "%python%" "%_pw_start_script%"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070083 ) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070084 call "%python%" "%_pw_start_script%" --no-shell-file
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070085 goto finish
86 )
Alexei Frolovb8aadc32020-01-23 10:46:14 -080087)
88
Rob Mohrd596a532020-04-03 08:59:12 -070089set PW_CIPD_PACKAGE_FILES=%_PW_OLD_CIPD_PACKAGE_FILES%
90set PW_VIRTUALENV_REQUIREMENTS=%_PW_OLD_VIRTUALENV_REQUIREMENTS%
91set PW_VIRTUALENV_SETUP_PY_ROOTS=%_PW_OLD_VIRTUALENV_SETUP_PY_ROOTS%
92set PW_CARGO_PACKAGE_FILES=%_PW_OLD_CARGO_PACKAGE_FILES%
93
Wyatt Hepler61682e82020-03-19 11:36:48 -070094call "%shell_file%"
Alexei Frolovba4de1c2020-03-09 16:43:40 -070095
96:finish
Rob Mohr709472a2020-04-17 11:50:47 -070097::WINDOWS_ONLY