1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion
4 :: Set the default arguments for build
6 set __VCBuildArch=x86_amd64
8 set __BuildOS=Windows_NT
10 set __VSToolsRoot=%VS140COMNTOOLS%
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:
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"
26 REM __unprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
29 set __unprocessedBuildArgs=
31 set __BuildAgainstPackages=
32 set __BuildAgainstPackagesArg=
36 if "%1" == "" goto ArgsDone
38 if /i "%1" == "-?" goto Usage
39 if /i "%1" == "-h" goto Usage
40 if /i "%1" == "-help" goto Usage
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)
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)
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)
57 if [!processedArgs!]==[] (
58 call set __UnprocessedBuildArgs=!__args!
60 call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
65 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
66 call "%__VSToolsRoot%\VsDevCmd.bat"
68 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
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
74 echo %__MsgPrefix%Commencing CoreCLR repo test build
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.
83 if not defined __TestIntermediateDir (
84 set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
86 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
87 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
89 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
90 set "__CMakeBinDir=%__TestBinDir%"
91 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
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%"
98 echo %__MsgPrefix%Checking prerequisites
100 :: Eval the output from probe-win1.ps1
101 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
103 REM =========================================================================================
105 REM === Restore Build Tools
107 REM =========================================================================================
108 call "%__ProjectDir%\init-tools.cmd"
110 REM =========================================================================================
112 REM === Resolve runtime dependences
114 REM =========================================================================================
115 call "%__TestDir%\setup-runtime-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir%
117 if defined __UpdateInvalidPackagesArg (
121 REM =========================================================================================
123 REM === Native test build section
125 REM =========================================================================================
127 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
129 if defined __ToolsetDir (
130 echo %__MsgPrefix%ToolsetDir is defined to be :%__ToolsetDir%
131 goto GenVSSolution :: Private ToolSet is Defined
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
139 if not defined VSINSTALLDIR (
140 echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
143 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
147 pushd "%__NativeTestIntermediatesDir%"
148 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
149 @if defined _echo @echo on
152 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
153 echo %__MsgPrefix%Failed to generate test native component build project!
157 set __msbuildNativeArgs=-configuration=%__BuildType%
159 if defined __ToolsetDir (
160 set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
162 set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
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%"
173 call "%__ProjectDir%\run.cmd" build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
175 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
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%"
192 if not defined __BuildAgainstPackages goto SkipRestoreProduct
193 REM =========================================================================================
195 REM === Restore product binaries from packages
197 REM =========================================================================================
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"
204 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -UpdateDependencies -BatchRestorePackages -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
206 set __BuildLogRootName=Tests_GenerateRuntimeLayout
208 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
210 echo BinPlace of mscorlib.dll failed
214 if defined __RuntimeId (
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
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%
225 echo %__MsgPrefix% Created the runtime layout for %__RuntimeId% in %CORE_OVERLAY%
228 echo %__MsgPrefix% Created the runtime layout with all dependencies in %CORE_ROOT%
232 if defined __SkipManaged exit /b 0
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=normal;LogFile="%__BuildLog%"
239 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
240 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
242 REM =========================================================================================
244 REM === Managed test build section
246 REM =========================================================================================
248 echo %__MsgPrefix%Starting the Managed Tests Build
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.
255 if defined __UpdateInvalidPackagesArg (
256 set __up=-updateinvalidpackageversions
259 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__up% %__RunArgs% %__unprocessedBuildArgs%
261 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
268 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
270 echo %__MsgPrefix%Creating test overlay...
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%"
280 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__unprocessedBuildArgs%
282 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
289 REM =========================================================================================
291 REM === All builds complete!
293 REM =========================================================================================
295 echo %__MsgPrefix%Test build successful.
296 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
302 echo %0 [option1] [option2] ...
303 echo All arguments are optional. Options are case-insensitive. The options are:
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.
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
345 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
347 if /i "%__ToolsetDir%" == "" (
348 echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
352 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
353 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
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