Fix rebuild issue with development package
[platform/upstream/coreclr.git] / build.cmd
1 @echo off
2 setlocal
3
4 :: Set the default arguments for build
5 set __BuildArch=x64
6 set __BuildType=debug
7
8 :: Set the various build properties here so that CMake and MSBuild can pick them up
9 set __ProjectDir=%~dp0
10 set __ProjectFilesDir=%~dp0
11 set __SourceDir=%__ProjectDir%\src
12 set __PackagesDir=%__SourceDir%\.nuget
13 set __RootBinDir=%__ProjectDir%\binaries
14 set __LogsDir=%__RootBinDir%\Logs
15 set __CMakeSlnDir=%__RootBinDir%\CMake
16 set __MSBCleanBuildArgs=
17
18 :Arg_Loop
19 if "%1" == "" goto ArgsDone
20 if /i "%1" == "/?" goto Usage
21 if /i "%1" == "x64"    (set __BuildArch=x64&&shift&goto Arg_Loop)
22
23 if /i "%1" == "debug"    (set __BuildType=debug&shift&goto Arg_Loop)
24 if /i "%1" == "release"   (set __BuildType=release&shift&goto Arg_Loop)
25
26 if /i "%1" == "clean"   (set __CleanBuild=1&shift&goto Arg_Loop)
27
28 if /i "%1" == "unixmscorlib" (set __UnixMscorlibOnly=1&shift&goto Arg_Loop)
29
30 echo Invalid commandline argument: %1
31 goto Usage
32
33 :ArgsDone
34
35 echo Commencing CoreCLR Repo build
36 echo.
37
38 :: Set the remaining variables based upon the determined build configuration
39 set __BinDir=%__RootBinDir%\Product\%__BuildArch%\%__BuildType%
40 set __PackagesBinDir=%__BinDir%\.nuget
41 set __ToolsDir=%__RootBinDir%\tools
42 set __TestWorkingDir=%__RootBinDir%\tests\%__BuildArch%\%__BuildType%
43 set __IntermediatesDir=%__RootBinDir%\intermediates\%__BuildArch%\%__BuildType%
44
45 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
46 set __CMakeBinDir=%__BinDir%
47 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
48
49 :: Switch to clean build mode if the binaries output folder does not exist
50 if not exist %__RootBinDir% set __CleanBuild=1
51
52 :: Configure environment if we are doing a clean build.
53 if not defined __CleanBuild goto CheckPrereqs
54 echo Doing a clean build
55 echo.
56
57 :: MSBuild projects would need a rebuild
58 set __MSBCleanBuildArgs=/t:rebuild
59
60 :: Cleanup the binaries drop folder
61 if exist %__BinDir% rd /s /q %__BinDir%
62 md %__BinDir%
63
64 :: Cleanup the CMake folder
65 if exist %__CMakeSlnDir% rd /s /q %__CMakeSlnDir%
66 md %__CMakeSlnDir%
67
68 :: Cleanup the logs folder
69 if exist %__LogsDir% rd /s /q %__LogsDir%
70 md %__LogsDir%
71
72 ::Cleanup intermediates folder
73 if exist %__IntermediatesDir% rd /s /q %__IntermediatesDir%
74
75 :: Check prerequisites
76 :CheckPrereqs
77 echo Checking pre-requisites...
78 echo.
79 ::
80 :: Check presence of CMake on the path
81 for %%X in (cmake.exe) do (set FOUNDCMake=%%~$PATH:X)
82 if defined FOUNDCMake goto CheckVS
83 echo CMake is a pre-requisite to build this repository but it was not found on the path. Please install CMake from http://www.cmake.org/download/ and ensure it is on your path.
84 goto :eof
85
86 :CheckVS
87 :: Check presence of VS
88 if defined VS120COMNTOOLS goto CheckVSExistence
89 echo Installation of VS 2013 is a pre-requisite to build this repository.
90 goto :eof
91
92 :CheckVSExistence
93 :: Does VS 2013 really exist?
94 if exist "%VS120COMNTOOLS%\..\IDE\devenv.exe" goto CheckMSBuild
95 echo Installation of VS 2013 is a pre-requisite to build this repository.
96 goto :eof
97
98 :CheckMSBuild    
99 :: Note: We've disabled node reuse because it causes file locking issues.
100 ::       The issue is that we extend the build with our own targets which
101 ::       means that that rebuilding cannot successfully delete the task
102 ::       assembly. 
103 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe"
104 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\12.0\Bin\MSBuild.exe"
105 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
106 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
107 if not exist %_msbuildexe% echo Error: Could not find MSBuild.exe.  Please see https://github.com/dotnet/coreclr/wiki/Developer%%20Guide for build instructions. && exit /b 1
108
109 :: All set to commence the build
110
111 setlocal
112 if defined __UnixMscorlibOnly goto PerformMScorlibBuild
113
114 echo Commencing build of native components for %__BuildArch%/%__BuildType%
115 echo.
116
117 :: Set the environment for the native build
118 call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
119
120 if exist "%VSINSTALLDIR%DIA SDK" goto GenVSSolution
121 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
122 This is due to bug in VS Intaller. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
123 at VS install location of previous version. Workaround is to copy DIA SDK folder from VS install location ^
124 of previous version to "%VSINSTALLDIR%" and then resume build.
125 goto :eof
126
127 :GenVSSolution
128 :: Regenerate the VS solution
129 pushd %__CMakeSlnDir%
130 call %__SourceDir%\pal\tools\gen-buildsys-win.bat %__ProjectDir%
131 popd
132
133 :BuildComponents
134 if exist %__CMakeSlnDir%\install.vcxproj goto BuildCoreCLR
135 echo Failed to generate native component build project!
136 goto :eof
137
138 REM Build CoreCLR
139 :BuildCoreCLR
140 set __CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildArch%__%__BuildType%.log
141 %_msbuildexe% %__CMakeSlnDir%\install.vcxproj %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=diag;LogFile="%__CoreCLRBuildLog%"
142 IF NOT ERRORLEVEL 1 goto PerformMScorlibBuild
143 echo Native component build failed. Refer %__CoreCLRBuildLog% for details.
144 goto :eof
145
146 :PerformMScorlibBuild
147 REM endlocal to rid us of environment changes from vcvarsall.bat
148 endlocal
149
150 REM setlocal to prepare for vsdevcmd.bat
151 setlocal
152 set __AdditionalMSBuildArgs=
153
154 if defined __UnixMscorlibOnly set __AdditionalMSBuildArgs=/p:OS=Unix /p:BuildNugetPackage=false
155
156 :: Set the environment for the managed build
157 call "%VS120COMNTOOLS%\VsDevCmd.bat"
158 echo Commencing build of mscorlib for %__BuildArch%/%__BuildType%
159 echo.
160 set __MScorlibBuildLog=%__LogsDir%\MScorlib_%__BuildArch%__%__BuildType%.log
161 %_msbuildexe% "%__ProjectFilesDir%build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__MScorlibBuildLog%" %__AdditionalMSBuildArgs%
162 IF NOT ERRORLEVEL 1 (
163   if defined __UnixMscorlibOnly goto :eof
164   goto PerformTestBuild
165 )
166
167 echo MScorlib build failed. Refer %__MScorlibBuildLog% for details.
168 goto :eof
169
170 :PerformTestBuild
171 echo.
172 echo Commencing build of tests for %__BuildArch%/%__BuildType%
173 echo.
174 call tests\buildtest.cmd
175 IF NOT ERRORLEVEL 1 goto SuccessfulBuild
176 echo Test binaries build failed. Refer %__MScorlibBuildLog% for details.
177 goto :eof
178
179 :SuccessfulBuild
180 ::Build complete
181 echo Repo successfully built.
182 echo.
183 echo Product binaries are available at %__BinDir%
184 echo Test binaries are available at %__TestWorkingDir%
185 goto :eof
186
187 :Usage
188 echo.
189 echo Usage:
190 echo %0 BuildArch BuildType [clean] where:
191 echo.
192 echo BuildArch can be: x64
193 echo BuildType can be: Debug, Release
194 echo Clean - optional argument to force a clean build.
195 goto :eof