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=
33 if "%1" == "" goto ArgsDone
35 if /i "%1" == "-?" goto Usage
36 if /i "%1" == "-h" goto Usage
37 if /i "%1" == "-help" goto Usage
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)
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)
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)
52 if [!processedArgs!]==[] (
53 call set __UnprocessedBuildArgs=!__args!
55 call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
60 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
61 call "%__VSToolsRoot%\VsDevCmd.bat"
63 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
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
69 echo %__MsgPrefix%Commencing CoreCLR repo test build
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.
78 if not defined __TestIntermediateDir (
79 set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
81 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
82 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
84 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
85 set "__CMakeBinDir=%__TestBinDir%"
86 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
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%"
93 echo %__MsgPrefix%Checking prerequisites
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
98 REM =========================================================================================
100 REM === Restore Build Tools
102 REM =========================================================================================
103 call %__ProjectDir%\init-tools.cmd
105 REM =========================================================================================
107 REM === Resolve runtime dependences
109 REM =========================================================================================
110 call %__TestDir%\setup-runtime-dependencies.cmd /arch %__BuildArch% /outputdir %__BinDir%
112 if defined __UpdateInvalidPackagesArg (
116 REM =========================================================================================
118 REM === Native test build section
120 REM =========================================================================================
122 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
124 if defined __ToolsetDir (
125 echo %__MsgPrefix%ToolsetDir is defined to be :%__ToolsetDir%
126 goto GenVSSolution :: Private ToolSet is Defined
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
134 if not defined VSINSTALLDIR (
135 echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
138 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
142 pushd "%__NativeTestIntermediatesDir%"
143 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
144 @if defined __echo @echo on
147 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
148 echo %__MsgPrefix%Failed to generate test native component build project!
152 set __msbuildNativeArgs=-configuration=%__BuildType%
154 if defined __ToolsetDir (
155 set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
157 set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
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%"
168 call %__ProjectDir%\run.cmd build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
170 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
179 if defined __SkipManaged exit /b 0
181 REM =========================================================================================
183 REM === Managed test build section
185 REM =========================================================================================
187 echo %__MsgPrefix%Starting the Managed Tests Build
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.
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%"
202 if defined __UpdateInvalidPackagesArg (
203 set __up=-updateinvalidpackageversions
206 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__up% %__RunArgs% %__unprocessedBuildArgs%
208 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
215 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
217 echo %__MsgPrefix%Creating test overlay...
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%"
227 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__unprocessedBuildArgs%
229 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
236 REM =========================================================================================
238 REM === All builds complete!
240 REM =========================================================================================
242 echo %__MsgPrefix%Test build successful.
243 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
249 echo %0 [option1] [option2] ...
250 echo All arguments are optional. Options are case-insensitive. The options are:
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.
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
281 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
283 if /i "%__ToolsetDir%" == "" (
284 echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
288 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
289 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
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