kvm-guest-drivers-windows

Форк
0
278 строк · 7.7 Кб
1
@echo off
2
setlocal enabledelayedexpansion
3

4
rem ================================================================================
5
rem Virtio-win master build script
6
rem
7
rem Usage: build.bat <project_or_solution_file_path> <target_os_versions> [<args>]
8
rem
9
rem where args can be one or more of
10
rem   Debug, dbg, chk       .. to build Debug rather than the default release flavor
11
rem   amd64, x64, 64        .. to build only 64-bit driver
12
rem   x86, 32               .. to build only 32-bit driver
13
rem   /Option               .. build command to pass to VS, for example /Rebuild
14
rem   Win10   .. target OS version
15
rem
16
rem By default the script performs an incremental build of both 32-bit and 64-bit
17
rem release drivers for all supported target OSes.
18
rem
19
rem To do a Static Driver Verifier build, append _SDV to the target OS version, for
20
rem example Win10_SDV.
21
rem ================================================================================
22

23
rem This is a list of supported build target specifications A_B where A is the
24
rem VS project configuration name and B is the corresponding platform identifier
25
rem used in log file names and intermediate directory names. Either of the two can
26
rem be used in the <target_os_version> command line argument.
27
set SUPPORTED_BUILD_SPECS=Win10_win10 Win11_win11
28

29
set BUILD_TARGETS=%~2
30
set BUILD_DIR=%~dp1
31
set BUILD_FILE=%~nx1
32
set BUILD_NAME=%~n1
33

34
rem We do an incremental Release build for all specs and all archs by default
35
set BUILD_FLAVOR=Release
36
set BUILD_COMMAND=/Build
37
set BUILD_SPEC=
38
set BUILD_ARCH=
39
set BUILD_FAILED=
40

41
rem Parse arguments
42
:argloop
43
shift /2
44
if "%2"=="" goto argend
45
set ARG=%2
46
if "%ARG:~0,1%"=="/" set BUILD_COMMAND=%ARG%& goto :argloop
47

48
if /I "%ARG%"=="Debug" set BUILD_FLAVOR=Debug& goto :argloop
49
if /I "%ARG%"=="dbg" set BUILD_FLAVOR=Debug& goto :argloop
50
if /I "%ARG%"=="chk" set BUILD_FLAVOR=Debug& goto :argloop
51

52
if /I "%ARG%"=="amd64" set BUILD_ARCH=amd64& goto :argloop
53
if /I "%ARG%"=="64" set BUILD_ARCH=amd64& goto :argloop
54
if /I "%ARG%"=="x64" set BUILD_ARCH=amd64& goto :argloop
55
if /I "%ARG%"=="32" set BUILD_ARCH=x86& goto :argloop
56
if /I "%ARG%"=="x86" set BUILD_ARCH=x86& goto :argloop
57
if /I "%ARG%"=="ARM64" set BUILD_ARCH=ARM64& goto :argloop
58

59
rem Assume that this is target OS version and split off the tag
60
call :split_target_tag "%ARG%"
61

62
rem Verify that this target OS is supported and valid
63
for %%N in (%SUPPORTED_BUILD_SPECS%) do (
64
  set T=%%N
65
  set CANDIDATE_SPEC=
66
  set FOUND_MATCH=
67

68
  for %%A in ("!T:_=" "!") do (
69
    if /I %%A=="%TARGET%" set CANDIDATE_SPEC=!T!!TAG!
70
    for %%B in (%BUILD_TARGETS%) do (
71
      if /I %%B==%%~A!TAG! set FOUND_MATCH=1
72
    )
73
  )
74

75
  if not "!FOUND_MATCH!"=="" if not "!CANDIDATE_SPEC!"=="" (
76
    set BUILD_SPEC=!CANDIDATE_SPEC!
77
    goto :argloop
78
  )
79
)
80

81
rem Silently exit if the build target could not be matched
82
rem
83
rem The reason for ignoring build target mismatch are projects
84
rem like NetKVM, viostor, and vioscsi, which build different
85
rem sln/vcxproj for different targets. Higher level script
86
rem does not have information about specific sln/vcproj and
87
rem platform bindings, therefore it invokes this script once
88
rem for each sln/vcproj to make it decide when the actual build
89
rem should be invoked.
90

91
goto :eof
92

93
rem Figure out which targets we're building
94
:argend
95
if "%BUILD_SPEC%"=="" (
96
  for %%B in (%BUILD_TARGETS%) do (
97
    call :split_target_tag "%%B"
98
    for %%N in (%SUPPORTED_BUILD_SPECS%) do (
99
      set T=%%N
100
      set BUILD_SPEC=
101
      for %%A in ("!T:_=" "!") do (
102
        if /I %%A=="!TARGET!" set BUILD_SPEC=!T!!TAG!
103
      )
104
      if not "!BUILD_SPEC!"=="" (
105
        call :build_target !BUILD_SPEC!
106
        if not "!BUILD_FAILED!"=="" goto :fail
107
      )
108
    )
109
  )
110
) else (
111
  call :build_target %BUILD_SPEC%
112
)
113
goto :eof
114

115
rem Figure out which archs we're building
116
:build_target
117
if "%BUILD_ARCH%"=="" (
118
  call :build_arch %1 x86
119
  if not "!BUILD_FAILED!"=="" goto :eof
120
  call :build_arch %1 amd64
121
) else (
122
  call :build_arch %1 %BUILD_ARCH%
123
)
124
goto :eof
125

126
rem Invoke Visual Studio
127
:build_arch
128
setlocal
129
set BUILD_ARCH=%2
130
set TAG=
131
for /f "tokens=1 delims=_" %%T in ("%1") do (
132
  set TARGET_PROJ_CONFIG=%%T
133
)
134
for /f "tokens=2 delims=_" %%T in ("%1") do (
135
  set TARGET_PLATFORM=%%T
136
)
137
for /f "tokens=3 delims=_" %%T in ("%1") do (
138
  set TAG=%%T
139
)
140

141
if /I "!TAG!"=="SDV" (
142
  rem There is no 32-bit SDV build
143
  if %BUILD_ARCH%==x86 goto :eof
144
  rem Check the SDV build suppression variable
145
  if not "%_BUILD_DISABLE_SDV%"=="" (
146
    echo Skipping %TARGET_PROJ_CONFIG% SDV build because _BUILD_DISABLE_SDV is set
147
    goto :eof
148
  )
149
)
150

151
rem Compose build log file name
152
if %BUILD_FLAVOR%=="Debug" (
153
  set BUILD_LOG_FILE=buildchk
154
) else (
155
  set BUILD_LOG_FILE=buildfre
156
)
157
set BUILD_LOG_FILE=%BUILD_LOG_FILE%_%TARGET_PLATFORM%_%BUILD_ARCH%.log
158

159
if %BUILD_ARCH%==amd64 set BUILD_ARCH=x64
160
set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%"
161

162
pushd %BUILD_DIR%
163
call "%~dp0\SetVsEnv.bat" %TARGET_PROJ_CONFIG%
164

165
if /I "!TAG!"=="SDV" (
166
  echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
167
  call :runsdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
168
  if exist "%CODEQL_BIN%" (
169
    echo Running CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
170
    call :runql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
171
  ) else (
172
      echo CodeQL binary is missing!
173
  )
174
  call :runca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
175
  call :rundvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
176
) else (
177
  echo Building %BUILD_FILE%, configuration %TARGET_VS_CONFIG%, command %BUILD_COMMAND%
178
  call :runbuild "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
179
)
180
popd
181
endlocal
182

183
IF ERRORLEVEL 1 (
184
  set BUILD_FAILED=1
185
)
186
goto :eof
187

188
:runbuild:
189
:: %1 - configuration (as "Win10 Release")
190
:: %2 - platform      (as x64)
191
:: %3 - build command (as "/Build")
192
set __TARGET__=%BUILD_COMMAND:/=%
193
::(n)ormal(d)etailed,(disg)nostic
194
set __VERBOSITY__=n
195
msbuild.exe -maxCpuCount %BUILD_FILE% /t:%__TARGET__% /p:Configuration="%~1" /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__%;LogFile=%BUILD_LOG_FILE%
196
goto :eof
197

198
:runsdv
199
echo "Removing previously created SDV artifacts"
200
rmdir /s/q sdv
201

202
msbuild.exe -maxCpuCount %BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2
203

204
IF ERRORLEVEL 1 (
205
  set BUILD_FAILED=1
206
)
207

208
msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2
209

210
IF ERRORLEVEL 1 (
211
  set BUILD_FAILED=1
212
)
213

214
msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2
215

216
IF ERRORLEVEL 1 (
217
  set BUILD_FAILED=1
218
)
219

220
goto :eof
221

222
:runql
223

224
echo "Removing previously created rules database"
225
rmdir /s/q codeql_db
226

227
echo call "%~dp0\SetVsEnv.bat" %~1 > %~dp1\codeql.build.bat
228
echo msbuild.exe -maxCpuCount %~dp1\%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1\codeql.build.bat
229

230
call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1\codeql.build.bat" %~dp1\codeql_db -j 0
231

232
IF ERRORLEVEL 1 (
233
  set CODEQL_FAILED=1
234
  set BUILD_FAILED=1
235
)
236

237
IF "%CODEQL_FAILED%" NEQ "1" (
238
  call %CODEQL_BIN% database analyze %~dp1\codeql_db %CODEQL_DRIVER_SUITES%\windows_driver_recommended.qls %CODEQL_DRIVER_SUITES%\windows_driver_mustfix.qls --format=sarifv2.1.0 --output=%~dp1\%BUILD_NAME%.sarif -j 0
239
)
240

241
IF ERRORLEVEL 1 (
242
  set BUILD_FAILED=1
243
)
244

245
goto :eof
246

247
:runca
248
msbuild.exe -maxCpuCount %BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1\%BUILD_NAME%.CodeAnalysis.log
249

250
IF ERRORLEVEL 1 (
251
  set BUILD_FAILED=1
252
)
253

254
goto :eof
255

256
:rundvl
257
msbuild.exe -maxCpuCount %BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2
258

259
IF ERRORLEVEL 1 (
260
  set BUILD_FAILED=1
261
)
262

263
goto :eof
264

265
:split_target_tag
266
set TARGET=
267
set TAG=
268
for /f "tokens=1 delims=_" %%T in (%1) do (
269
    set TARGET=%%T
270
)
271
for /f "tokens=2 delims=_" %%T in (%1) do (
272
    set TAG=_%%T
273
)
274
goto :eof
275

276
:fail
277

278
exit /B 1
279

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.