Add the missing ICU APIs to the ICU shim (#7840)
[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 set __BuildAgainstPackages=
32 set __BuildAgainstPackagesArg=
33 set __RuntimeId=
34
35 :Arg_Loop
36 if "%1" == "" goto ArgsDone
37
38 if /i "%1" == "-?"    goto Usage
39 if /i "%1" == "-h"    goto Usage
40 if /i "%1" == "-help" goto Usage
41
42 if /i "%1" == "x64"                   (set __BuildArch=x64&set __VCBuildArch=x86_amd64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
43 if /i "%1" == "x86"                   (set __BuildArch=x86&set __VCBuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
44 if /i "%1" == "arm"                   (set __BuildArch=arm&set __VCBuildArch=x86_arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
45 if /i "%1" == "arm64"                 (set __BuildArch=arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
46
47 if /i "%1" == "debug"                 (set __BuildType=Debug&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
48 if /i "%1" == "release"               (set __BuildType=Release&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
49 if /i "%1" == "checked"               (set __BuildType=Checked&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
50
51 if /i "%1" == "skipmanaged"           (set __SkipManaged=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
52 if /i "%1" == "updateinvalidpackages" (set __UpdateInvalidPackagesArg=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
53 if /i "%1" == "toolset_dir"           (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
54 if /i "%1" == "buildagainstpackages"  (set __BuildAgainstPackages=1&set __BuildAgainstPackagesArg=-BuildTestsAgainstPackages&shift&goto Arg_Loop)
55 if /i "%1" == "runtimeid"             (set __RuntimeId=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
56
57 if [!processedArgs!]==[] (
58   call set __UnprocessedBuildArgs=!__args!
59 ) else (
60   call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
61 )
62
63 :ArgsDone
64
65 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
66 call                                 "%__VSToolsRoot%\VsDevCmd.bat"
67
68 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
69
70 rem arm64 builds currently use private toolset which has not been released yet
71 REM TODO, remove once the toolset is open.
72 if /i "%__BuildArch%" == "arm64" call :PrivateToolSet
73
74 echo %__MsgPrefix%Commencing CoreCLR repo test build
75
76 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
77 set "__TestRootDir=%__RootBinDir%\tests"
78 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
79 :: We have different managed and native intermediate dirs because the managed bits will include
80 :: the configuration information deeper in the intermediates path.
81 :: These variables are used by the msbuild project files.
82
83 if not defined __TestIntermediateDir (
84     set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
85 )
86 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
87 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
88
89 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
90 set "__CMakeBinDir=%__TestBinDir%"
91 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
92
93 if not exist "%__TestBinDir%"                   md "%__TestBinDir%"
94 if not exist "%__NativeTestIntermediatesDir%"   md "%__NativeTestIntermediatesDir%"
95 if not exist "%__ManagedTestIntermediatesDir%"  md "%__ManagedTestIntermediatesDir%"
96 if not exist "%__LogsDir%"                      md "%__LogsDir%"
97
98 echo %__MsgPrefix%Checking prerequisites
99
100 :: Eval the output from probe-win1.ps1
101 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
102
103 REM =========================================================================================
104 REM ===
105 REM === Restore Build Tools
106 REM ===
107 REM =========================================================================================
108 call %__ProjectDir%\init-tools.cmd 
109
110 REM =========================================================================================
111 REM ===
112 REM === Resolve runtime dependences
113 REM ===
114 REM =========================================================================================
115 call %__TestDir%\setup-runtime-dependencies.cmd /arch %__BuildArch% /outputdir %__BinDir%
116
117 if defined __UpdateInvalidPackagesArg (
118   goto skipnative
119 )
120
121 REM =========================================================================================
122 REM ===
123 REM === Native test build section
124 REM ===
125 REM =========================================================================================
126
127 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
128
129 if defined __ToolsetDir (
130  echo %__MsgPrefix%ToolsetDir is defined to be :%__ToolsetDir%
131  goto GenVSSolution :: Private ToolSet is Defined
132 )
133
134 :: Set the environment for the native build
135 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
136 call                                 "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
137 @if defined _echo @echo on
138
139 if not defined VSINSTALLDIR (
140     echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
141     exit /b 1
142 )
143 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
144
145 :GenVSSolution
146
147 pushd "%__NativeTestIntermediatesDir%"
148 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
149 @if defined _echo @echo on
150 popd
151
152 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
153     echo %__MsgPrefix%Failed to generate test native component build project!
154     exit /b 1
155 )
156
157 set __msbuildNativeArgs=-configuration=%__BuildType%
158
159 if defined __ToolsetDir (
160     set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
161 ) else (
162     set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
163 )
164
165 set __BuildLogRootName=Tests_Native
166 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
167 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
168 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
169 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
170 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
171 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
172
173 call %__ProjectDir%\run.cmd build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
174 if errorlevel 1 (
175     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
176     echo     %__BuildLog%
177     echo     %__BuildWrn%
178     echo     %__BuildErr%
179     exit /b 1
180 )
181
182 :skipnative
183
184 set __BuildLogRootName=Restore_Product
185 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
186 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
187 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
188 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
189 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
190 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
191
192 if not defined __BuildAgainstPackages goto SkipRestoreProduct
193 REM =========================================================================================
194 REM ===
195 REM === Restore product binaries from packages
196 REM ===
197 REM =========================================================================================
198
199 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
200 if not defined XunitTestBinBase       set  XunitTestBinBase=%__TestWorkingDir%
201 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
202 set "CORE_OVERLAY=%XunitTestBinBase%\Tests\coreoverlay"
203
204 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\build.proj  -UpdateDependencies -BatchRestorePackages -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
205
206 set __BuildLogRootName=Tests_GenerateRuntimeLayout
207
208 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
209 if errorlevel 1 (
210     echo BinPlace of mscorlib.dll failed
211     exit /b 1
212 )
213
214 if defined __RuntimeId (
215
216     if not exist %__PackagesDir%\TestNativeBins (
217         echo %__MsgPrefix%Error: Ensure you have run sync.cmd -ab before building a non-Windows test overlay against packages
218         exit /b 1
219     )
220
221     call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -CreateNonWindowsTestOverlay -RuntimeId="%__RuntimeId%"  -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
222     for /R %__PackagesDir%\TestNativeBins\%__RuntimeId% %%f in (*.so) do copy %%f %Core_Overlay%
223     for /R %__PackagesDir%\TestNativeBins\%__RuntimeId% %%f in (*.dylib) do copy %%f %Core_Overlay%
224
225     echo %__MsgPrefix% Created the runtime layout for %__RuntimeId% in %CORE_OVERLAY%
226 )
227
228 echo %__MsgPrefix% Created the runtime layout with all dependencies in %CORE_ROOT%
229
230 :SkipRestoreProduct
231
232 if defined __SkipManaged exit /b 0
233
234 set __BuildLogRootName=Tests_Managed
235 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
236 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
237 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
238 set __msbuildLog=/flp:Verbosity=diag;LogFile="%__BuildLog%"
239 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
240 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
241
242 REM =========================================================================================
243 REM ===
244 REM === Managed test build section
245 REM ===
246 REM =========================================================================================
247
248 echo %__MsgPrefix%Starting the Managed Tests Build
249
250 if not defined VSINSTALLDIR (
251     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.
252     exit /b 1
253 )
254
255 if defined __UpdateInvalidPackagesArg (
256   set __up=-updateinvalidpackageversions
257 )
258
259 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__up% %__RunArgs% %__unprocessedBuildArgs%
260 if errorlevel 1 (
261     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
262     echo     %__BuildLog%
263     echo     %__BuildWrn%
264     echo     %__BuildErr%
265     exit /b 1
266 )
267
268 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
269
270 echo %__MsgPrefix%Creating test overlay...
271
272 set __BuildLogRootName=Tests_Overlay_Managed
273 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
274 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
275 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
276 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
277 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
278 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
279
280 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__unprocessedBuildArgs%
281 if errorlevel 1 (
282     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
283     echo     %__BuildLog%
284     echo     %__BuildWrn%
285     echo     %__BuildErr%
286     exit /b 1
287 )
288
289 REM =========================================================================================
290 REM ===
291 REM === All builds complete!
292 REM ===
293 REM =========================================================================================
294
295 echo %__MsgPrefix%Test build successful.
296 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
297 exit /b 0
298
299 :Usage
300 echo.
301 echo Usage:
302 echo     %0 [option1] [option2] ...
303 echo All arguments are optional. Options are case-insensitive. The options are:
304 echo.
305 echo. -? -h -help: view this message.
306 echo Build architecture: -buildArch: only x64 is currently allowed ^(default: x64^).
307 echo Build type: -buildType: one of Debug, Checked, Release ^(default: Debug^).
308 echo updateinvalidpackageversions: Runs the target to update package versions.
309 echo buildagainstpackages: builds tests against restored packages, instead of against a built product.
310 echo runtimeid ^<ID^>: Builds a test overlay for the specified OS (Only supported when building against packages). Supported IDs are:
311 echo     debian.8-x64: Builds overlay for Debian 8
312 echo     fedora.23-x64: Builds overlay for Fedora 23
313 echo     opensuse.13.2-x64: Builds overlay for OpenSUSE 13.2
314 echo     opensuse.42.1-x64: Builds overlay for OpenSUSE 42.1
315 echo     osx.10.10-x64: Builds overlay for OSX 10.10
316 echo     rhel.7-x64: Builds overlay for RHEL 7 or CentOS
317 echo     ubuntu.14.04-x64: Builds overlay for Ubuntu 14.04
318 echo     ubuntu.16.04-x64: Builds overlay for Ubuntu 16.04
319 echo     ubuntu.16.10-x64: Builds overlay for Ubuntu 16.10
320 echo -- ... : all arguments following this tag will be passed directly to msbuild.
321 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
322 echo     0: Build only priority 0 cases as essential testcases (default)
323 echo     1: Build all tests with priority 0 and 1
324 echo     666: Build all tests with priority 0, 1 ... 666
325 echo -sequential: force a non-parallel build ^(default is to build in parallel
326 echo     using all processors^).
327 echo -ilasmroundtrip: enables ilasm round trip build and run of the tests before executing them.
328 echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file.
329 exit /b 1
330
331 :NoDIA
332 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
333 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
334 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
335 of the previous version to "%VSINSTALLDIR%" and then build.
336 :: DIA SDK not included in Express editions
337 echo Visual Studio 2013 Express does not include the DIA SDK. ^
338 You need Visual Studio 2013+ (Community is free).
339 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
340 exit /b 1
341
342
343 :PrivateToolSet
344
345 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
346
347 if /i "%__ToolsetDir%" == "" (
348     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
349     exit /b 1
350 )
351
352 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
353 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
354 set INCLUDE=^
355 %__ToolsetDir%\VC_sdk\inc;^
356 %__ToolsetDir%\sdpublic\sdk\inc;^
357 %__ToolsetDir%\sdpublic\shared\inc;^
358 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
359 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
360 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
361 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
362 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
363 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
364 %__ToolsetDir%\diasdk\include
365 exit /b 0