ConcurrentDictionary<TKey, TValue> Exceptions to ThrowHelper (#7079)
[platform/upstream/coreclr.git] / build-test.cmd
1 @if not defined __echo @echo off
2 setlocal EnableDelayedExpansion
3
4 :: Set the default arguments for build
5 set __BuildArch=x64
6 set __VCBuildArch=x86_amd64
7 set __BuildType=Debug
8 set __BuildOS=Windows_NT
9 set __VSVersion=vs2015
10 set __VSToolsRoot=%VS140COMNTOOLS%
11
12 :: Define a prefix for most output progress messages that come from this script. That makes
13 :: it easier to see where these are coming from. Note that there is a trailing space here.
14 set __MsgPrefix=BUILDTEST: 
15
16 set "__ProjectDir=%~dp0"
17 :: remove trailing slash
18 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
19 set "__TestDir=%__ProjectDir%\tests"
20 set "__ProjectFilesDir=%__TestDir%"
21 set "__SourceDir=%__ProjectDir%\src"
22 set "__PackagesDir=%__ProjectDir%\packages"
23 set "__RootBinDir=%__ProjectDir%\bin"
24 set "__LogsDir=%__RootBinDir%\Logs"
25
26 REM __unprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
27 set "__args= %*"
28 set processedArgs=
29 set __unprocessedBuildArgs=
30 set __RunArgs=
31
32 :Arg_Loop
33 if "%1" == "" goto ArgsDone
34
35 if /i "%1" == "-?"    goto Usage
36 if /i "%1" == "-h"    goto Usage
37 if /i "%1" == "-help" goto Usage
38
39 if /i "%1" == "x64"                   (set __BuildArch=x64&set __VCBuildArch=x86_amd64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
40 if /i "%1" == "x86"                   (set __BuildArch=x86&set __VCBuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
41 if /i "%1" == "arm"                   (set __BuildArch=arm&set __VCBuildArch=x86_arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
42 if /i "%1" == "arm64"                 (set __BuildArch=arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
43
44 if /i "%1" == "debug"                 (set __BuildType=Debug&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
45 if /i "%1" == "release"               (set __BuildType=Release&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
46 if /i "%1" == "checked"               (set __BuildType=Checked&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
47
48 if /i "%1" == "skipmanaged"           (set __SkipManaged=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
49 if /i "%1" == "updateinvalidpackages" (set __UpdateInvalidPackagesArg=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
50 if /i "%1" == "toolset_dir"           (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
51
52 if [!processedArgs!]==[] (
53   call set __UnprocessedBuildArgs=!__args!
54 ) else (
55   call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
56 )
57
58 :ArgsDone
59
60 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
61 call                                 "%__VSToolsRoot%\VsDevCmd.bat"
62
63 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
64
65 rem arm64 builds currently use private toolset which has not been released yet
66 REM TODO, remove once the toolset is open.
67 if /i "%__BuildArch%" == "arm64" call :PrivateToolSet
68
69 echo %__MsgPrefix%Commencing CoreCLR repo test build
70
71 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
72 set "__TestRootDir=%__RootBinDir%\tests"
73 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
74 :: We have different managed and native intermediate dirs because the managed bits will include
75 :: the configuration information deeper in the intermediates path.
76 :: These variables are used by the msbuild project files.
77
78 if not defined __TestIntermediateDir (
79     set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
80 )
81 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
82 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
83
84 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
85 set "__CMakeBinDir=%__TestBinDir%"
86 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
87
88 if not exist "%__TestBinDir%"                   md "%__TestBinDir%"
89 if not exist "%__NativeTestIntermediatesDir%"   md "%__NativeTestIntermediatesDir%"
90 if not exist "%__ManagedTestIntermediatesDir%"  md "%__ManagedTestIntermediatesDir%"
91 if not exist "%__LogsDir%"                      md "%__LogsDir%"
92
93 echo %__MsgPrefix%Checking prerequisites
94
95 :: Eval the output from probe-win1.ps1
96 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
97
98 REM =========================================================================================
99 REM ===
100 REM === Restore Build Tools
101 REM ===
102 REM =========================================================================================
103 call %__ProjectDir%\init-tools.cmd 
104
105 REM =========================================================================================
106 REM ===
107 REM === Resolve runtime dependences
108 REM ===
109 REM =========================================================================================
110 call %__TestDir%\setup-runtime-dependencies.cmd /arch %__BuildArch% /outputdir %__BinDir%
111
112 if defined __UpdateInvalidPackagesArg (
113   goto skipnative
114 )
115
116 REM =========================================================================================
117 REM ===
118 REM === Native test build section
119 REM ===
120 REM =========================================================================================
121
122 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
123
124 if defined __ToolsetDir (
125  echo %__MsgPrefix%ToolsetDir is defined to be :%__ToolsetDir%
126  goto GenVSSolution :: Private ToolSet is Defined
127 )
128
129 :: Set the environment for the native build
130 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
131 call                                 "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
132 @if defined __echo @echo on
133
134 if not defined VSINSTALLDIR (
135     echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
136     exit /b 1
137 )
138 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
139
140 :GenVSSolution
141
142 pushd "%__NativeTestIntermediatesDir%"
143 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
144 @if defined __echo @echo on
145 popd
146
147 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
148     echo %__MsgPrefix%Failed to generate test native component build project!
149     exit /b 1
150 )
151
152 set __msbuildNativeArgs=-configuration=%__BuildType%
153
154 if defined __ToolsetDir (
155     set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
156 ) else (
157     set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
158 )
159
160 set __BuildLogRootName=Tests_Native
161 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
162 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
163 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
164 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
165 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
166 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
167
168 call %__ProjectDir%\run.cmd build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
169 if errorlevel 1 (
170     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
171     echo     %__BuildLog%
172     echo     %__BuildWrn%
173     echo     %__BuildErr%
174     exit /b 1
175 )
176
177 :skipnative
178
179 if defined __SkipManaged exit /b 0
180
181 REM =========================================================================================
182 REM ===
183 REM === Managed test build section
184 REM ===
185 REM =========================================================================================
186
187 echo %__MsgPrefix%Starting the Managed Tests Build
188
189 if not defined VSINSTALLDIR (
190     echo %__MsgPrefix%Error: buildtest.cmd should be run from a Visual Studio Command Prompt.  Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions.
191     exit /b 1
192 )
193
194 set __BuildLogRootName=Tests_Managed
195 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
196 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
197 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
198 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
199 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
200 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
201
202 if defined __UpdateInvalidPackagesArg (
203   set __up=-updateinvalidpackageversions
204 )
205
206 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__up% %__RunArgs% %__unprocessedBuildArgs%
207 if errorlevel 1 (
208     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
209     echo     %__BuildLog%
210     echo     %__BuildWrn%
211     echo     %__BuildErr%
212     exit /b 1
213 )
214
215 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
216
217 echo %__MsgPrefix%Creating test overlay...
218
219 set __BuildLogRootName=Tests_Overlay_Managed
220 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
221 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
222 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
223 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
224 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
225 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
226
227 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__unprocessedBuildArgs%
228 if errorlevel 1 (
229     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
230     echo     %__BuildLog%
231     echo     %__BuildWrn%
232     echo     %__BuildErr%
233     exit /b 1
234 )
235
236 REM =========================================================================================
237 REM ===
238 REM === All builds complete!
239 REM ===
240 REM =========================================================================================
241
242 echo %__MsgPrefix%Test build successful.
243 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
244 exit /b 0
245
246 :Usage
247 echo.
248 echo Usage:
249 echo     %0 [option1] [option2] ...
250 echo All arguments are optional. Options are case-insensitive. The options are:
251 echo.
252 echo. -? -h -help: view this message.
253 echo Build architecture: -buildArch: only x64 is currently allowed ^(default: x64^).
254 echo Build type: -buildType: one of Debug, Checked, Release ^(default: Debug^).
255 echo updateinvalidpackageversions: Runs the target to update package versions.
256 echo -- ... : all arguments following this tag will be passed directly to msbuild.
257 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
258 echo     0: Build only priority 0 cases as essential testcases (default)
259 echo     1: Build all tests with priority 0 and 1
260 echo     666: Build all tests with priority 0, 1 ... 666
261 echo -sequential: force a non-parallel build ^(default is to build in parallel
262 echo     using all processors^).
263 echo -ilasmroundtrip: enables ilasm round trip build and run of the tests before executing them.
264 echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file.
265 exit /b 1
266
267 :NoDIA
268 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
269 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
270 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
271 of the previous version to "%VSINSTALLDIR%" and then build.
272 :: DIA SDK not included in Express editions
273 echo Visual Studio 2013 Express does not include the DIA SDK. ^
274 You need Visual Studio 2013+ (Community is free).
275 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
276 exit /b 1
277
278
279 :PrivateToolSet
280
281 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
282
283 if /i "%__ToolsetDir%" == "" (
284     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
285     exit /b 1
286 )
287
288 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
289 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
290 set INCLUDE=^
291 %__ToolsetDir%\VC_sdk\inc;^
292 %__ToolsetDir%\sdpublic\sdk\inc;^
293 %__ToolsetDir%\sdpublic\shared\inc;^
294 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
295 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
296 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
297 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
298 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
299 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
300 %__ToolsetDir%\diasdk\include
301 exit /b 0