Skip to content

Commit 7082a4d

Browse files
authored
Verify architecture and version of produced exes (#5134)
* Verify architecture and version of produced exes * Program files location * Skip exe architecture check
1 parent 3df6f89 commit 7082a4d

File tree

3 files changed

+150
-102
lines changed

3 files changed

+150
-102
lines changed

eng/verify-nupkgs-exe-version.ps1

Lines changed: 0 additions & 8 deletions
This file was deleted.

eng/verify-nupkgs-exe.ps1

Lines changed: 0 additions & 90 deletions
This file was deleted.

eng/verify-nupkgs.ps1

Lines changed: 150 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ function Verify-Nuget-Packages {
9898
}
9999
}
100100
finally {
101-
if ($null -ne $unzipNugetPackageDir -and (Test-Path $unzipNugetPackageDir)) {
102-
Remove-Item -Force -Recurse $unzipNugetPackageDir | Out-Null
103-
}
101+
# if ($null -ne $unzipNugetPackageDir -and (Test-Path $unzipNugetPackageDir)) {
102+
# Remove-Item -Force -Recurse $unzipNugetPackageDir | Out-Null
103+
# }
104104
}
105105
}
106106

@@ -109,6 +109,7 @@ function Verify-Nuget-Packages {
109109
}
110110

111111
Write-Host "Completed Verify-Nuget-Packages."
112+
$unzipNugetPackageDirs
112113
}
113114

114115
function Unzip {
@@ -156,4 +157,149 @@ function Verify-Version {
156157
Match-VersionAgainstBranch -vsTestVersion $vsTestProductVersion -branchName $currentBranch -errors $errors
157158
}
158159

159-
Verify-Nuget-Packages
160+
function Verify-NugetPackageExe {
161+
param(
162+
[Parameter(Mandatory)]
163+
[ValidateSet("Debug", "Release")]
164+
[string] $configuration,
165+
$UnzipNugetPackages
166+
)
167+
168+
169+
$exclusions = @{
170+
"CodeCoverage\CodeCoverage.exe" = "x86"
171+
"Dynamic Code Coverage Tools\CodeCoverage.exe" = "x86"
172+
"amd64\CodeCoverage.exe" = "x64"
173+
174+
"IntelliTrace.exe" = "x86"
175+
"ProcessSnapshotCleanup.exe" = "x86-64"
176+
"TDEnvCleanup.exe" = "x86"
177+
178+
"TestPlatform\SettingsMigrator.exe" = "x86"
179+
180+
"dump\DumpMinitool.exe" = "x86-64"
181+
182+
"QTAgent32.exe" = "x86"
183+
"QTAgent32_35.exe" = "x86"
184+
"QTAgent32_40.exe" = "x86"
185+
"QTDCAgent32.exe" = "x86"
186+
187+
"V1\VSTestVideoRecorder.exe" = "x86"
188+
"VideoRecorder\VSTestVideoRecorder.exe" = "x86"
189+
}
190+
191+
$errs = @()
192+
$exes = $UnzipNugetPackages | Get-ChildItem -Filter *.exe -Recurse -Force
193+
if (0 -eq @($exes).Length) {
194+
throw "No exe files were found."
195+
}
196+
197+
# use wow programfiles because they always point to x64 programfiles where VS is installed
198+
$dumpBin = Get-ChildItem -Recurse -Force -Filter dumpbin.exe -path "$env:ProgramW6432\Microsoft Visual Studio\2022\Enterprise" | Select-Object -First 1
199+
if (-not $dumpBin) {
200+
throw "Did not find dumpbin.exe in '$env:ProgramW6432\Microsoft Visual Studio\2022\Enterprise'."
201+
}
202+
203+
$corFlags = Get-ChildItem -Recurse -Force -Filter CorFlags.exe -path "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows" | Select-Object -First 1
204+
if (-not $corFlags) {
205+
throw "Did not find CorFlags.exe in '${env:ProgramFiles(x86)}\Microsoft SDKs\Windows'."
206+
}
207+
208+
$exes | ForEach-Object {
209+
$m = & $dumpBin /headers $_.FullName | Select-String "machine \((.*)\)"
210+
if (-not $m.Matches.Success) {
211+
$err = "Did not find the platform of the exe $fullName)."
212+
}
213+
214+
$platform = $m.Matches.Groups[1].Value
215+
$fullName = $_.FullName
216+
$name = $_.Name
217+
218+
if ("x86" -eq $platform) {
219+
$corFlagsOutput = & $corFlags $fullName
220+
# this is an native x86 exe or a .net x86 that requires of prefers 32bit
221+
$platform = if ($corFlagsOutput -like "*does not have a valid managed header*" -or $corFlagsOutput -like "*32BITREQ : 1*" -or $corFlagsOutput -like "*32BITPREF : 1*") {
222+
# this is an native x86 exe or a .net x86 that requires of prefers 32bit
223+
"x86" } else {
224+
# this is a x86 executable that is built as AnyCpu and does not prefer 32-bit so it will run as x64 on 64-bit system.
225+
"x86-64" }
226+
}
227+
228+
if (($pair = $exclusions.GetEnumerator() | Where-Object { $fullName -like "*$($_.Name)" })) {
229+
if (1 -lt $($pair).Count) {
230+
$err = "Too many paths matched the query, only one match is allowed. Matches: $($pair.Name)"
231+
$errs += $err
232+
Write-Host -ForegroundColor Red Error: $err
233+
}
234+
235+
if ($platform -ne $pair.Value) {
236+
$err = "$fullName must have architecture $($pair.Value), but it was $platform."
237+
$errs += $err
238+
Write-Host -ForegroundColor Red Error: $err
239+
}
240+
}
241+
elseif ("x86" -eq $platform) {
242+
if ($name -notlike "*x86*") {
243+
$err = "$fullName has architecture $platform, and must contain x86 in the name of the executable."
244+
$errs += $err
245+
Write-Host -ForegroundColor Red Error: $err
246+
}
247+
}
248+
elseif ($platform -in "x64", "x86-64") {
249+
if ($name -like "*x86*" -or $name -like "*arm64*") {
250+
$err = "$fullName has architecture $platform, and must NOT contain x86 or arm64 in the name of the executable."
251+
$errs += $err
252+
Write-Host -ForegroundColor Red Error: $err
253+
}
254+
}
255+
elseif ("arm64" -eq $platform) {
256+
if ($name -notlike "*arm64*") {
257+
$err = "$fullName has architecture $platform, and must contain arm64 in the name of the executable."
258+
$errs += $err
259+
Write-Host -ForegroundColor Red Error: $err
260+
}
261+
}
262+
else {
263+
$err = "$fullName has unknown architecture $platform."
264+
$errs += $err
265+
Write-Host -ForegroundColor Red $err
266+
}
267+
268+
"Success: $name is $platform - $fullName"
269+
}
270+
271+
if ($errs) {
272+
throw "Fail!:`n$($errs -join "`n")"
273+
}
274+
}
275+
276+
function Verify-NugetPackageVersion {
277+
param(
278+
[Parameter(Mandatory)]
279+
[ValidateSet("Debug", "Release")]
280+
[string] $configuration,
281+
$UnzipNugetPackages
282+
)
283+
284+
$exes = $UnzipNugetPackages | Get-ChildItem -Filter vstest.console.exe -Recurse -Force
285+
if (0 -eq @($exes).Length) {
286+
throw "No vstest.console.exe was found."
287+
}
288+
289+
$exes | ForEach-Object {
290+
if ($_.VersionInfo.ProductVersion.Contains("+")) {
291+
throw "Some files contain '+' in the ProductVersion, this breaks DTAAgent in AzDO."
292+
}
293+
else {
294+
"$_ version $($_.VersionInfo.ProductVersion) is ok."
295+
}
296+
}
297+
298+
}
299+
300+
301+
$unzipNugetPackages = Verify-Nuget-Packages
302+
Start-sleep -Seconds 10
303+
# skipped, it is hard to find the right dumpbin.exe and corflags tools on server
304+
# Verify-NugetPackageExe -configuration $configuration -UnzipNugetPackages $unzipNugetPackages
305+
Verify-NugetPackageVersion -configuration $configuration -UnzipNugetPackages $unzipNugetPackages

0 commit comments

Comments
 (0)