| 1 |
@REM Copyright (c) Microsoft. All rights reserved. |
| 2 |
@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
@setlocal EnableExtensions EnableDelayedExpansion |
| 5 |
@echo off |
| 6 |
|
| 7 |
set current-path=%~dp0 |
| 8 |
rem // remove trailing slash |
| 9 |
set current-path=%current-path:~0,-1% |
| 10 |
|
| 11 |
echo Current Path: %current-path% |
| 12 |
|
| 13 |
set build-root=%current-path%\..\.. |
| 14 |
rem // resolve to fully qualified path |
| 15 |
for %%i in ("%build-root%") do set build-root=%%~fi |
| 16 |
|
| 17 |
set repo_root=%build-root%\..\.. |
| 18 |
rem // resolve to fully qualified path |
| 19 |
for %%i in ("%repo_root%") do set repo_root=%%~fi |
| 20 |
|
| 21 |
echo Build Root: %build-root% |
| 22 |
echo Repo Root: %repo_root% |
| 23 |
|
| 24 |
rem ----------------------------------------------------------------------------- |
| 25 |
rem -- check prerequisites |
| 26 |
rem ----------------------------------------------------------------------------- |
| 27 |
|
| 28 |
rem ----------------------------------------------------------------------------- |
| 29 |
rem -- parse script arguments |
| 30 |
rem ----------------------------------------------------------------------------- |
| 31 |
|
| 32 |
rem // default build options |
| 33 |
set build-clean=0 |
| 34 |
set build-config=Debug |
| 35 |
set build-platform=Win32 |
| 36 |
set CMAKE_DIR=uamqp_win32 |
| 37 |
set MAKE_NUGET_PKG=no |
| 38 |
|
| 39 |
:args-loop |
| 40 |
if "%1" equ "" goto args-done |
| 41 |
if "%1" equ "-c" goto arg-build-clean |
| 42 |
if "%1" equ "--clean" goto arg-build-clean |
| 43 |
if "%1" equ "--config" goto arg-build-config |
| 44 |
if "%1" equ "--platform" goto arg-build-platform |
| 45 |
if "%1" equ "--make_nuget" goto arg-build-nuget |
| 46 |
call :usage && exit /b 1 |
| 47 |
|
| 48 |
:arg-build-clean |
| 49 |
set build-clean=1 |
| 50 |
goto args-continue |
| 51 |
|
| 52 |
:arg-build-config |
| 53 |
shift |
| 54 |
if "%1" equ "" call :usage && exit /b 1 |
| 55 |
set build-config=%1 |
| 56 |
goto args-continue |
| 57 |
|
| 58 |
:arg-build-platform |
| 59 |
shift |
| 60 |
if "%1" equ "" call :usage && exit /b 1 |
| 61 |
set build-platform=%1 |
| 62 |
if %build-platform% == x64 ( |
| 63 |
set CMAKE_DIR=uamqp_x64 |
| 64 |
) else if %build-platform% == arm ( |
| 65 |
set CMAKE_DIR=uamqp_arm |
| 66 |
) |
| 67 |
goto args-continue |
| 68 |
|
| 69 |
:arg-build-nuget |
| 70 |
shift |
| 71 |
if "%1" equ "" call :usage && exit /b 1 |
| 72 |
set MAKE_NUGET_PKG=%1 |
| 73 |
goto args-continue |
| 74 |
|
| 75 |
:args-continue |
| 76 |
shift |
| 77 |
goto args-loop |
| 78 |
|
| 79 |
:args-done |
| 80 |
|
| 81 |
rem ----------------------------------------------------------------------------- |
| 82 |
rem -- clean solutions |
| 83 |
rem ----------------------------------------------------------------------------- |
| 84 |
|
| 85 |
if %build-clean%==1 ( |
| 86 |
rem -- call nuget restore "%build-root%\iothub_client\samples\iothub_client_sample_amqp\windows\iothub_client_sample_amqp.sln" |
| 87 |
rem -- call :clean-a-solution "%build-root%\iothub_client\samples\iothub_client_sample_amqp\windows\iothub_client_sample_amqp.sln" |
| 88 |
rem -- if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 89 |
) |
| 90 |
|
| 91 |
rem ----------------------------------------------------------------------------- |
| 92 |
rem -- build with CMAKE and run tests |
| 93 |
rem ----------------------------------------------------------------------------- |
| 94 |
|
| 95 |
echo CMAKE Output Path: %build-root%\cmake\%CMAKE_DIR% |
| 96 |
|
| 97 |
if EXIST %build-root%\cmake\%CMAKE_DIR% ( |
| 98 |
rmdir /s/q %build-root%\cmake\%CMAKE_DIR% |
| 99 |
rem no error checking |
| 100 |
) |
| 101 |
|
| 102 |
echo %build-root%\cmake\%CMAKE_DIR% |
| 103 |
mkdir %build-root%\cmake\%CMAKE_DIR% |
| 104 |
rem no error checking |
| 105 |
pushd %build-root%\cmake\%CMAKE_DIR% |
| 106 |
|
| 107 |
echo ***checking msbuild*** |
| 108 |
where msbuild |
| 109 |
|
| 110 |
if %MAKE_NUGET_PKG% == yes ( |
| 111 |
echo ***Running CMAKE for Win32*** |
| 112 |
cmake %build-root% |
| 113 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 114 |
popd |
| 115 |
|
| 116 |
echo ***Running CMAKE for Win64*** |
| 117 |
if EXIST %build-root%\cmake\uamqp_x64 ( |
| 118 |
rmdir /s/q %build-root%\cmake\uamqp_x64 |
| 119 |
) |
| 120 |
mkdir %build-root%\cmake\uamqp_x64 |
| 121 |
pushd %build-root%\cmake\uamqp_x64 |
| 122 |
cmake %build-root% -A x64 |
| 123 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 124 |
popd |
| 125 |
|
| 126 |
echo ***Running CMAKE for ARM*** |
| 127 |
if EXIST %build-root%\cmake\uamqp_arm ( |
| 128 |
rmdir /s/q %build-root%\cmake\uamqp_arm |
| 129 |
) |
| 130 |
mkdir %build-root%\cmake\uamqp_arm |
| 131 |
pushd %build-root%\cmake\uamqp_arm |
| 132 |
cmake %build-root% -A ARM |
| 133 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 134 |
|
| 135 |
) else if %build-platform% == Win32 ( |
| 136 |
echo ***Running CMAKE for Win32*** |
| 137 |
cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -A Win32 -G %VSVERSION% |
| 138 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 139 |
) else if %build-platform% == arm ( |
| 140 |
echo ***Running CMAKE for ARM*** |
| 141 |
cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -A ARM -G %VSVERSION% |
| 142 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 143 |
) else ( |
| 144 |
echo ***Running CMAKE for Win64*** |
| 145 |
cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -A x64 -G %VSVERSION% |
| 146 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 147 |
) |
| 148 |
|
| 149 |
if %MAKE_NUGET_PKG% == yes ( |
| 150 |
echo ***Building all configurations*** |
| 151 |
msbuild /m %build-root%\cmake\uamqp_win32\uamqp.sln /p:Configuration=Release |
| 152 |
msbuild /m %build-root%\cmake\uamqp_win32\uamqp.sln /p:Configuration=Debug |
| 153 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 154 |
|
| 155 |
msbuild /m %build-root%\cmake\uamqp_x64\uamqp.sln /p:Configuration=Release |
| 156 |
msbuild /m %build-root%\cmake\uamqp_x64\uamqp.sln /p:Configuration=Debug |
| 157 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 158 |
|
| 159 |
msbuild /m %build-root%\cmake\uamqp_arm\uamqp.sln /p:Configuration=Release |
| 160 |
msbuild /m %build-root%\cmake\uamqp_arm\uamqp.sln /p:Configuration=Debug |
| 161 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 162 |
) else ( |
| 163 |
call :_run-msbuild "Build" uamqp.sln %2 %3 |
| 164 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 165 |
|
| 166 |
if %build-platform% neq arm ( |
| 167 |
echo Build Platform: %build-platform% |
| 168 |
|
| 169 |
if "%build-config%" == "Debug" ( |
| 170 |
ctest -C "debug" -V |
| 171 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 172 |
) |
| 173 |
) |
| 174 |
) |
| 175 |
popd |
| 176 |
goto :eof |
| 177 |
|
| 178 |
rem ----------------------------------------------------------------------------- |
| 179 |
rem -- subroutines |
| 180 |
rem ----------------------------------------------------------------------------- |
| 181 |
|
| 182 |
:clean-a-solution |
| 183 |
call :_run-msbuild "Clean" %1 %2 %3 |
| 184 |
goto :eof |
| 185 |
|
| 186 |
:build-a-solution |
| 187 |
call :_run-msbuild "Build" %1 %2 %3 |
| 188 |
goto :eof |
| 189 |
|
| 190 |
:run-unit-tests |
| 191 |
call :_run-tests %1 "UnitTests" |
| 192 |
goto :eof |
| 193 |
|
| 194 |
:usage |
| 195 |
echo build.cmd [options] |
| 196 |
echo options: |
| 197 |
echo -c, --clean delete artifacts from previous build before building |
| 198 |
echo --config ^<value^> [Debug] build configuration (e.g. Debug, Release) |
| 199 |
echo --platform ^<value^> [Win32] build platform (e.g. Win32, x64, arm, ...) |
| 200 |
goto :eof |
| 201 |
|
| 202 |
rem ----------------------------------------------------------------------------- |
| 203 |
rem -- helper subroutines |
| 204 |
rem ----------------------------------------------------------------------------- |
| 205 |
|
| 206 |
:_run-msbuild |
| 207 |
rem // optionally override configuration|platform |
| 208 |
setlocal EnableExtensions |
| 209 |
set build-target= |
| 210 |
if "%~1" neq "Build" set "build-target=/t:%~1" |
| 211 |
if "%~3" neq "" set build-config=%~3 |
| 212 |
if "%~4" neq "" set build-platform=%~4 |
| 213 |
|
| 214 |
msbuild /m %build-target% "/p:Configuration=%build-config%;Platform=%build-platform%" %2 |
| 215 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 216 |
goto :eof |
| 217 |
|
| 218 |
|
| 219 |
:_run-tests |
| 220 |
rem // discover tests |
| 221 |
set test-dlls-list= |
| 222 |
set test-dlls-path=%build-root%\%~1\build\windows\%build-platform%\%build-config% |
| 223 |
for /f %%i in ('dir /b %test-dlls-path%\*%~2*.dll') do set test-dlls-list="%test-dlls-path%\%%i" !test-dlls-list! |
| 224 |
|
| 225 |
if "%test-dlls-list%" equ "" ( |
| 226 |
echo No unit tests found in %test-dlls-path% |
| 227 |
exit /b 1 |
| 228 |
) |
| 229 |
|
| 230 |
rem // run tests |
| 231 |
echo Test DLLs: %test-dlls-list% |
| 232 |
echo. |
| 233 |
vstest.console.exe %test-dlls-list% |
| 234 |
|
| 235 |
if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! |
| 236 |
goto :eof |
| 237 |
|
| 238 |
echo done |