-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbootstrap.cmd
More file actions
309 lines (276 loc) · 8.25 KB
/
Copy pathbootstrap.cmd
File metadata and controls
309 lines (276 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
@echo off
setlocal
set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%.") do set "ROOT=%%~fI"
set "CONAN_DIR=%ROOT%\conan"
set "CACHE_DIR=%CONAN_DIR%\cache"
set "PROFILE_OVERRIDE=%CONAN_DIR%\profile-override"
set "DEPS_DIR=%ROOT%\third-party"
set "BASE_RECIPE_DIR=%CONAN_DIR%\base-recipe"
set "CONAN_EXE="
set "CMAKE_EXE="
set "NINJA_EXE="
set "DO_EXPORT="
set "INSTALL_PROFILE="
set "BUILD_PROFILE="
set "TOOLCHAIN_PATH="
set "NATIVE_PROFILE=native"
set "BUILD_ENV_PROFILE=win-x64"
set "BUILD_TYPE=Release"
set "DEPS_ONLY="
:parse_args
if "%~1"=="" goto :after_args
if /I "%~1"=="-h" goto :usage_ok
if /I "%~1"=="--help" goto :usage_ok
if /I "%~1"=="setup" (
if defined DO_EXPORT (
echo error: setup was specified more than once.
goto :usage_error
)
set "DO_EXPORT=1"
shift
goto :parse_setup_args
)
if /I "%~1"=="build" (
if "%~2"=="" (
echo error: build requires a profile name.
goto :usage_error
)
if defined BUILD_PROFILE (
echo error: build was specified more than once.
goto :usage_error
)
set "INSTALL_PROFILE=%~2"
set "BUILD_PROFILE=%~2"
shift
shift
goto :parse_build_args
)
echo error: unknown command: %~1
goto :usage_error
:parse_setup_args
if "%~1"=="" goto :after_args
if /I "%~1"=="-h" goto :usage_ok
if /I "%~1"=="--help" goto :usage_ok
if /I "%~1"=="--toolchain" (
if "%~2"=="" (
echo error: --toolchain requires a toolchain path.
goto :usage_error
)
set "TOOLCHAIN_PATH=%~2"
shift
shift
goto :parse_setup_args
)
if /I "%~1"=="--cache" (
if "%~2"=="" (
echo error: --cache requires a cache path.
goto :usage_error
)
set "CACHE_DIR=%~f2"
shift
shift
goto :parse_setup_args
)
echo error: unknown setup argument: %~1
goto :usage_error
:parse_build_args
if "%~1"=="" goto :after_args
if /I "%~1"=="-h" goto :usage_ok
if /I "%~1"=="--help" goto :usage_ok
if /I "%~1"=="--toolchain" (
if "%~2"=="" (
echo error: --toolchain requires a toolchain path.
goto :usage_error
)
set "TOOLCHAIN_PATH=%~2"
shift
shift
goto :parse_build_args
)
if /I "%~1"=="--cache" (
if "%~2"=="" (
echo error: --cache requires a cache path.
goto :usage_error
)
set "CACHE_DIR=%~f2"
shift
shift
goto :parse_build_args
)
if /I "%~1"=="--deps-only" (
set "DEPS_ONLY=1"
shift
goto :parse_build_args
)
if /I "%~1"=="--debug" (
set "BUILD_TYPE=Debug"
shift
goto :parse_build_args
)
echo error: unknown build argument: %~1
goto :usage_error
:after_args
if not defined DO_EXPORT if not defined INSTALL_PROFILE goto :usage_error
if not defined TOOLCHAIN_PATH goto :toolchain_checked
if not exist "%TOOLCHAIN_PATH%\." (
echo error: toolchain path does not exist: %TOOLCHAIN_PATH%
exit /b 1
)
:toolchain_checked
if not defined INSTALL_PROFILE goto :profile_mode_checked
call :validate_profile_mode
if errorlevel 1 exit /b 1
:profile_mode_checked
set "CONAN_HOME=%CACHE_DIR%"
if not exist "%CACHE_DIR%\." mkdir "%CACHE_DIR%" || exit /b 1
if defined TOOLCHAIN_PATH (
set "CONAN_EXE=%TOOLCHAIN_PATH%\tool\conan\bin\conan.exe"
) else (
set "CONAN_EXE=conan"
)
call :check_executable "%CONAN_EXE%" "Conan executable"
if errorlevel 1 (
echo Pass --toolchain or make conan available on PATH.
exit /b 1
)
if not defined BUILD_PROFILE goto :cmake_checked
if defined DEPS_ONLY goto :cmake_checked
if defined TOOLCHAIN_PATH (
set "CMAKE_EXE=%TOOLCHAIN_PATH%\tool\cmake\bin\cmake.exe"
set "NINJA_EXE=%TOOLCHAIN_PATH%\tool\ninja\bin\ninja.exe"
) else (
set "CMAKE_EXE=cmake"
set "NINJA_EXE=ninja"
)
call :check_executable "%CMAKE_EXE%" "CMake executable"
if errorlevel 1 (
echo Pass --toolchain or make cmake available on PATH.
exit /b 1
)
call :check_executable "%NINJA_EXE%" "Ninja executable"
if errorlevel 1 (
echo Pass --toolchain or make ninja available on PATH.
exit /b 1
)
:cmake_checked
pushd "%ROOT%" || exit /b 1
set "BOOTSTRAP_RESULT=0"
if not defined DO_EXPORT goto :after_export
call :export_recipes
if errorlevel 1 set "BOOTSTRAP_RESULT=1"
:after_export
if not "%BOOTSTRAP_RESULT%"=="0" goto :finish
if not defined INSTALL_PROFILE goto :finish
if defined DEPS_ONLY (
call :install "%INSTALL_PROFILE%"
if errorlevel 1 set "BOOTSTRAP_RESULT=1"
goto :finish
)
if not defined BUILD_PROFILE goto :finish
call :build "%BUILD_PROFILE%"
if errorlevel 1 set "BOOTSTRAP_RESULT=1"
:finish
popd
exit /b %BOOTSTRAP_RESULT%
:check_executable
if exist "%~1" exit /b 0
where "%~1" >nul 2>nul
if not errorlevel 1 exit /b 0
echo error: %~2 does not exist or is not on PATH: %~1
exit /b 1
:validate_profile_mode
if /I "%INSTALL_PROFILE%"=="%NATIVE_PROFILE%" (
if defined TOOLCHAIN_PATH (
echo error: profile %NATIVE_PROFILE% cannot be used with --toolchain.
exit /b 1
)
exit /b 0
)
if not defined TOOLCHAIN_PATH (
echo error: without --toolchain, build profile must be %NATIVE_PROFILE%.
exit /b 1
)
exit /b 0
:export_recipes
if not exist "%BASE_RECIPE_DIR%\conanfile.py" (
echo error: base recipe does not exist: %BASE_RECIPE_DIR%
exit /b 1
)
if not exist "%DEPS_DIR%\." (
echo error: dependency recipes directory does not exist: %DEPS_DIR%
exit /b 1
)
call :export_recipe "%BASE_RECIPE_DIR%"
if errorlevel 1 exit /b 1
set "FOUND_RECIPE="
for /f "delims=" %%D in ('dir /b /ad /on "%DEPS_DIR%" 2^>nul') do (
if exist "%DEPS_DIR%\%%D\conanfile.py" (
set "FOUND_RECIPE=1"
call :export_recipe "%DEPS_DIR%\%%D"
if errorlevel 1 exit /b 1
)
)
if not defined FOUND_RECIPE (
echo error: no dependency recipes found in %DEPS_DIR%
exit /b 1
)
exit /b 0
:export_recipe
call :run_conan export "%~1" --user=ysm --channel=stable
exit /b %ERRORLEVEL%
:run_conan_with_profile
if not exist "%PROFILE_OVERRIDE%" (
echo error: project profile override does not exist: %PROFILE_OVERRIDE%
exit /b 1
)
if defined TOOLCHAIN_PATH (
if not exist "%TOOLCHAIN_PATH%\conan\%~1" (
echo error: toolchain host profile does not exist: %TOOLCHAIN_PATH%\conan\%~1
exit /b 1
)
if not exist "%TOOLCHAIN_PATH%\conan\%BUILD_ENV_PROFILE%" (
echo error: toolchain build profile does not exist: %TOOLCHAIN_PATH%\conan\%BUILD_ENV_PROFILE%
exit /b 1
)
call :run_conan %~2 "%ROOT%" -pr:h "%TOOLCHAIN_PATH%\conan\%~1" -pr:h "%PROFILE_OVERRIDE%" -pr:b "%TOOLCHAIN_PATH%\conan\%BUILD_ENV_PROFILE%" --no-remote --build=missing -s build_type=%BUILD_TYPE% -c:h "user.target:profile=%~1" --core-conf core.graph:compatibility_mode=optimized
) else (
call :run_conan profile detect -e
call :run_conan %~2 "%ROOT%" -pr:h default -pr:h "%PROFILE_OVERRIDE%" -s:h compiler.runtime=static -pr:b default --no-remote --build=missing -s build_type=%BUILD_TYPE% -c:h "user.target:profile=%NATIVE_PROFILE%" --core-conf core.graph:compatibility_mode=optimized
)
exit /b %ERRORLEVEL%
:install
call :run_conan_with_profile "%~1" install
call :run_conan cache clean --build
exit /b %ERRORLEVEL%
:build
call :run_conan_with_profile "%~1" build
exit /b %ERRORLEVEL%
:run_conan
echo + "%CONAN_EXE%" %*
if exist "%CONAN_EXE%" (
call "%CONAN_EXE%" %*
) else (
call %CONAN_EXE% %*
)
exit /b %ERRORLEVEL%
:usage_ok
call :usage
exit /b 0
:usage_error
call :usage
exit /b 2
:usage
echo Usage:
echo %~nx0 setup [--toolchain ^<toolchain_path^>] [--cache ^<path^>]
echo %~nx0 build ^<profile^> [--toolchain ^<toolchain_path^>] [--cache ^<path^>] [--deps-only] [--debug]
echo.
echo Build mode defaults to Release. Pass --debug to use Debug.
echo Pass --cache to set CONAN_HOME explicitly; the default is conan/cache.
echo Setup and build use ^<toolchain_path^>/tool/conan/bin/conan.exe when --toolchain is set, otherwise PATH.
echo Without --toolchain, build requires profile %NATIVE_PROFILE% and uses host profile default + conan/profile-override and build profile default.
echo With --toolchain, build uses ^<toolchain_path^>/conan/^<profile^> + conan/profile-override and a win-x64 build profile; profile %NATIVE_PROFILE% is not allowed.
echo conan build uses ^<toolchain_path^>/tool/cmake/bin/cmake.exe when --toolchain is set, otherwise PATH cmake.
echo Build and generator directories are build/^<profile^>-^<build-type^>.
echo Pass --deps-only to stop after conan install.
exit /b 0