blob: 9532775f9b3505ab5785afbc85116efce003b5eb [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 Mohre34001c2020-07-29 09:05:55 -070059:: PW_ENVIRONMENT_ROOT allows developers to specify where the environment should
60:: be installed. _PW_ACTUAL_ENVIRONMENT_ROOT is where Pigweed keeps that
61:: information. This separation allows Pigweed to assume PW_ENVIRONMENT_ROOT
62:: came from the developer and not from a previous bootstrap possibly from
63:: another workspace.
Rob Mohrce87bc02020-07-15 11:16:17 -070064if "%PW_ENVIRONMENT_ROOT%"=="" (
Rob Mohre34001c2020-07-29 09:05:55 -070065 :: Not prefixing environment with "." since that doesn't hide it anyway.
66 set "_PW_ACTUAL_ENVIRONMENT_ROOT=%PW_ROOT%\environment"
67) else (
68 set "_PW_ACTUAL_ENVIRONMENT_ROOT=%PW_ENVIRONMENT_ROOT%"
Rob Mohrce87bc02020-07-15 11:16:17 -070069)
Rob Mohre34001c2020-07-29 09:05:55 -070070set "shell_file=%_PW_ACTUAL_ENVIRONMENT_ROOT%\activate.bat"
Rob Mohrce87bc02020-07-15 11:16:17 -070071
Rob Mohrd596a532020-04-03 08:59:12 -070072set _PW_OLD_CIPD_PACKAGE_FILES=%PW_CIPD_PACKAGE_FILES%
73set _PW_OLD_VIRTUALENV_REQUIREMENTS=%PW_VIRTUALENV_REQUIREMENTS%
74set _PW_OLD_VIRTUALENV_SETUP_PY_ROOTS=%PW_VIRTUALENV_SETUP_PY_ROOTS%
75set _PW_OLD_CARGO_PACKAGE_FILES=%PW_CARGO_PACKAGE_FILES%
76
Rob Mohrf7d96572020-07-24 06:29:54 -070077set 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 Mohrd596a532020-04-03 08:59:12 -070078set PW_VIRTUALENV_REQUIREMENTS=%PW_ROOT%\pw_env_setup\py\pw_env_setup\virtualenv_setup\requirements.txt;%PW_VIRTUALENV_REQUIREMENTS%
79set PW_VIRTUALENV_SETUP_PY_ROOTS=%PW_ROOT%;%PW_VIRTUALENV_SETUP_PY_ROOTS%
80set PW_CARGO_PACKAGE_FILES=%PW_ROOT%\pw_env_setup\py\pw_env_setup\cargo_setup\packages.txt;%PW_CARGO_PACKAGE_FILES%
81
Wyatt Hepler61682e82020-03-19 11:36:48 -070082set "_pw_start_script=%PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py"
Alexei Frolovb8aadc32020-01-23 10:46:14 -080083
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070084:: If PW_SKIP_BOOTSTRAP is set, only run the activation stage instead of the
85:: complete env_setup.
86if "%PW_SKIP_BOOTSTRAP%" == "" (
Wyatt Hepler61682e82020-03-19 11:36:48 -070087 :: Without the trailing slash in %PW_ROOT%/, batch combines that token with
88 :: the --shell-file argument.
89 call "%python%" "%PW_ROOT%\pw_env_setup\py\pw_env_setup\env_setup.py" ^
90 --pw-root "%PW_ROOT%/" ^
Rob Mohrce87bc02020-07-15 11:16:17 -070091 --shell-file "%shell_file%" ^
Rob Mohre34001c2020-07-29 09:05:55 -070092 --install-dir "%_PW_ACTUAL_ENVIRONMENT_ROOT%"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070093) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070094 if exist "%shell_file%" (
95 call "%python%" "%_pw_start_script%"
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070096 ) else (
Wyatt Hepler61682e82020-03-19 11:36:48 -070097 call "%python%" "%_pw_start_script%" --no-shell-file
Alexei Frolov4dcf99d2020-03-10 16:48:26 -070098 goto finish
99 )
Alexei Frolovb8aadc32020-01-23 10:46:14 -0800100)
101
Rob Mohrd596a532020-04-03 08:59:12 -0700102set PW_CIPD_PACKAGE_FILES=%_PW_OLD_CIPD_PACKAGE_FILES%
103set PW_VIRTUALENV_REQUIREMENTS=%_PW_OLD_VIRTUALENV_REQUIREMENTS%
104set PW_VIRTUALENV_SETUP_PY_ROOTS=%_PW_OLD_VIRTUALENV_SETUP_PY_ROOTS%
105set PW_CARGO_PACKAGE_FILES=%_PW_OLD_CARGO_PACKAGE_FILES%
106
Wyatt Hepler61682e82020-03-19 11:36:48 -0700107call "%shell_file%"
Alexei Frolovba4de1c2020-03-09 16:43:40 -0700108
109:finish
Rob Mohr709472a2020-04-17 11:50:47 -0700110::WINDOWS_ONLY