From 08d5518d70de7dc642c81de5a4f566e859bbc3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 8 Jul 2024 11:58:51 +0200 Subject: [PATCH 1/3] Verify architecture and version of produced exes --- eng/verify-nupkgs-exe-version.ps1 | 8 -- eng/verify-nupkgs-exe.ps1 | 90 ------------------ eng/verify-nupkgs.ps1 | 152 +++++++++++++++++++++++++++++- 3 files changed, 148 insertions(+), 102 deletions(-) delete mode 100644 eng/verify-nupkgs-exe-version.ps1 delete mode 100644 eng/verify-nupkgs-exe.ps1 diff --git a/eng/verify-nupkgs-exe-version.ps1 b/eng/verify-nupkgs-exe-version.ps1 deleted file mode 100644 index 7535b9aef3..0000000000 --- a/eng/verify-nupkgs-exe-version.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -Get-ChildItem S:\p\vstest3\artifacts\packages\Debug\Shipping -Filter vstest.console.exe -Recurse -Force | ForEach-Object { - if ($_.VersionInfo.ProductVersion.Contains("+")) { - throw "Some files contain '+' in the ProductVersion, this breaks DTAAgent in AzDO." - } - else { - "$_ version $($_.VersionInfo.ProductVersion) is ok." - } -} \ No newline at end of file diff --git a/eng/verify-nupkgs-exe.ps1 b/eng/verify-nupkgs-exe.ps1 deleted file mode 100644 index 459a4dcb43..0000000000 --- a/eng/verify-nupkgs-exe.ps1 +++ /dev/null @@ -1,90 +0,0 @@ -$exclusions = @{ - "CodeCoverage\CodeCoverage.exe" = "x86" - "Dynamic Code Coverage Tools\CodeCoverage.exe" = "x86" - "amd64\CodeCoverage.exe" = "x64" - - "IntelliTrace.exe" = "x86" - "ProcessSnapshotCleanup.exe" = "x86-64" - "TDEnvCleanup.exe" = "x86" - - "TestPlatform\SettingsMigrator.exe" = "x86" - - "dump\DumpMinitool.exe" = "x86-64" - - "QTAgent32.exe" = "x86" - "QTAgent32_35.exe" = "x86" - "QTAgent32_40.exe" = "x86" - "QTDCAgent32.exe" = "x86" - - "V1\VSTestVideoRecorder.exe" = "x86" - "VideoRecorder\VSTestVideoRecorder.exe" = "x86" -} - -$errs = @() -Get-ChildItem S:\p\vstest3\artifacts\packages\Debug\Shipping -Filter *.exe -Recurse -Force | ForEach-Object { - $m = & "C:\Program Files\Microsoft Visual Studio\2022\IntPreview\VC\Tools\MSVC\14.38.32919\bin\HostX86\x86\dumpbin.exe" /headers $_.FullName | Select-String "machine \((.*)\)" - if (-not $m.Matches.Success) { - $err = "Did not find the platform of the exe $fullName)." - } - - $platform = $m.Matches.Groups[1].Value - $fullName = $_.FullName - $name = $_.Name - - if ("x86" -eq $platform) { - $corFlags = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\CorFlags.exe" - $corFlagsOutput = & $corFlags $fullName - # this is an native x86 exe or a .net x86 that requires of prefers 32bit - $platform = if ($corFlagsOutput -like "*does not have a valid managed header*" -or $corFlagsOutput -like "*32BITREQ : 1*" -or $corFlagsOutput -like "*32BITPREF : 1*") { - # this is an native x86 exe or a .net x86 that requires of prefers 32bit - "x86" } else { - # 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. - "x86-64" } - } - - if (($pair = $exclusions.GetEnumerator() | Where-Object { $fullName -like "*$($_.Name)" })) { - if (1 -lt $($pair).Count) { - $err = "Too many paths matched the query, only one match is allowed. Matches: $($pair.Name)" - $errs += $err - Write-Host -ForegroundColor Red Error: $err - } - - if ($platform -ne $pair.Value) { - $err = "$fullName must have architecture $($pair.Value), but it was $platform." - $errs += $err - Write-Host -ForegroundColor Red Error: $err - } - } - elseif ("x86" -eq $platform) { - if ($name -notlike "*x86*") { - $err = "$fullName has architecture $platform, and must contain x86 in the name of the executable." - $errs += $err - Write-Host -ForegroundColor Red Error: $err - } - } - elseif ($platform -in "x64", "x86-64") { - if ($name -like "*x86*" -or $name -like "*arm64*") { - $err = "$fullName has architecture $platform, and must NOT contain x86 or arm64 in the name of the executable." - $errs += $err - Write-Host -ForegroundColor Red Error: $err - } - } - elseif ("arm64" -eq $platform) { - if ($name -notlike "*arm64*") { - $err = "$fullName has architecture $platform, and must contain arm64 in the name of the executable." - $errs += $err - Write-Host -ForegroundColor Red Error: $err - } - } - else { - $err = "$fullName has unknown architecture $platform." - $errs += $err - Write-Host -ForegroundColor Red $err - } - - "Success: $name is $platform - $fullName" -} - -if ($errs) { - throw "Fail!:`n$($errs -join "`n")" -} \ No newline at end of file diff --git a/eng/verify-nupkgs.ps1 b/eng/verify-nupkgs.ps1 index c87d4ceaab..cc4fb5d5b3 100644 --- a/eng/verify-nupkgs.ps1 +++ b/eng/verify-nupkgs.ps1 @@ -98,9 +98,9 @@ function Verify-Nuget-Packages { } } finally { - if ($null -ne $unzipNugetPackageDir -and (Test-Path $unzipNugetPackageDir)) { - Remove-Item -Force -Recurse $unzipNugetPackageDir | Out-Null - } + # if ($null -ne $unzipNugetPackageDir -and (Test-Path $unzipNugetPackageDir)) { + # Remove-Item -Force -Recurse $unzipNugetPackageDir | Out-Null + # } } } @@ -109,6 +109,7 @@ function Verify-Nuget-Packages { } Write-Host "Completed Verify-Nuget-Packages." + $unzipNugetPackageDirs } function Unzip { @@ -156,4 +157,147 @@ function Verify-Version { Match-VersionAgainstBranch -vsTestVersion $vsTestProductVersion -branchName $currentBranch -errors $errors } -Verify-Nuget-Packages +function Verify-NugetPackageExe { + param( + [Parameter(Mandatory)] + [ValidateSet("Debug", "Release")] + [string] $configuration, + $UnzipNugetPackages + ) + + + $exclusions = @{ + "CodeCoverage\CodeCoverage.exe" = "x86" + "Dynamic Code Coverage Tools\CodeCoverage.exe" = "x86" + "amd64\CodeCoverage.exe" = "x64" + + "IntelliTrace.exe" = "x86" + "ProcessSnapshotCleanup.exe" = "x86-64" + "TDEnvCleanup.exe" = "x86" + + "TestPlatform\SettingsMigrator.exe" = "x86" + + "dump\DumpMinitool.exe" = "x86-64" + + "QTAgent32.exe" = "x86" + "QTAgent32_35.exe" = "x86" + "QTAgent32_40.exe" = "x86" + "QTDCAgent32.exe" = "x86" + + "V1\VSTestVideoRecorder.exe" = "x86" + "VideoRecorder\VSTestVideoRecorder.exe" = "x86" + } + + $errs = @() + $exes = $UnzipNugetPackages | Get-ChildItem -Filter *.exe -Recurse -Force + if (0 -eq @($exes).Length) { + throw "No exe files were found." + } + + $dumpBin = Get-ChildItem -Recurse -Force -Filter dumpbin.exe -path "$env:ProgramFiles\Microsoft Visual Studio\2022\Enterprise" | Select-Object -First 1 + if (-not $dumpBin) { + throw "Did not find dumpbin.exe in '$env:ProgramFiles\Microsoft Visual Studio\2022\Enterprise'." + } + + $corFlags = Get-ChildItem -Recurse -Force -Filter CorFlags.exe -path "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows" | Select-Object -First 1 + if (-not $corFlags) { + throw "Did not find CorFlags.exe in '${env:ProgramFiles(x86)}\Microsoft SDKs\Windows'." + } + + $exes | ForEach-Object { + $m = & $dumpBin /headers $_.FullName | Select-String "machine \((.*)\)" + if (-not $m.Matches.Success) { + $err = "Did not find the platform of the exe $fullName)." + } + + $platform = $m.Matches.Groups[1].Value + $fullName = $_.FullName + $name = $_.Name + + if ("x86" -eq $platform) { + $corFlagsOutput = & $corFlags $fullName + # this is an native x86 exe or a .net x86 that requires of prefers 32bit + $platform = if ($corFlagsOutput -like "*does not have a valid managed header*" -or $corFlagsOutput -like "*32BITREQ : 1*" -or $corFlagsOutput -like "*32BITPREF : 1*") { + # this is an native x86 exe or a .net x86 that requires of prefers 32bit + "x86" } else { + # 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. + "x86-64" } + } + + if (($pair = $exclusions.GetEnumerator() | Where-Object { $fullName -like "*$($_.Name)" })) { + if (1 -lt $($pair).Count) { + $err = "Too many paths matched the query, only one match is allowed. Matches: $($pair.Name)" + $errs += $err + Write-Host -ForegroundColor Red Error: $err + } + + if ($platform -ne $pair.Value) { + $err = "$fullName must have architecture $($pair.Value), but it was $platform." + $errs += $err + Write-Host -ForegroundColor Red Error: $err + } + } + elseif ("x86" -eq $platform) { + if ($name -notlike "*x86*") { + $err = "$fullName has architecture $platform, and must contain x86 in the name of the executable." + $errs += $err + Write-Host -ForegroundColor Red Error: $err + } + } + elseif ($platform -in "x64", "x86-64") { + if ($name -like "*x86*" -or $name -like "*arm64*") { + $err = "$fullName has architecture $platform, and must NOT contain x86 or arm64 in the name of the executable." + $errs += $err + Write-Host -ForegroundColor Red Error: $err + } + } + elseif ("arm64" -eq $platform) { + if ($name -notlike "*arm64*") { + $err = "$fullName has architecture $platform, and must contain arm64 in the name of the executable." + $errs += $err + Write-Host -ForegroundColor Red Error: $err + } + } + else { + $err = "$fullName has unknown architecture $platform." + $errs += $err + Write-Host -ForegroundColor Red $err + } + + "Success: $name is $platform - $fullName" + } + + if ($errs) { + throw "Fail!:`n$($errs -join "`n")" + } +} + +function Verify-NugetPackageVersion { + param( + [Parameter(Mandatory)] + [ValidateSet("Debug", "Release")] + [string] $configuration, + $UnzipNugetPackages + ) + + $exes = $UnzipNugetPackages | Get-ChildItem -Filter vstest.console.exe -Recurse -Force + if (0 -eq @($exes).Length) { + throw "No vstest.console.exe was found." + } + + $exes | ForEach-Object { + if ($_.VersionInfo.ProductVersion.Contains("+")) { + throw "Some files contain '+' in the ProductVersion, this breaks DTAAgent in AzDO." + } + else { + "$_ version $($_.VersionInfo.ProductVersion) is ok." + } + } + +} + + +$unzipNugetPackages = Verify-Nuget-Packages +Start-sleep -Seconds 10 +Verify-NugetPackageExe -configuration $configuration -UnzipNugetPackages $unzipNugetPackages +Verify-NugetPackageVersion -configuration $configuration -UnzipNugetPackages $unzipNugetPackages From 8765bd73a7536cb226c37e05440cef515f074b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 8 Jul 2024 17:23:13 +0200 Subject: [PATCH 2/3] Program files location --- eng/verify-nupkgs.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eng/verify-nupkgs.ps1 b/eng/verify-nupkgs.ps1 index cc4fb5d5b3..02f5847d3c 100644 --- a/eng/verify-nupkgs.ps1 +++ b/eng/verify-nupkgs.ps1 @@ -194,9 +194,10 @@ function Verify-NugetPackageExe { throw "No exe files were found." } - $dumpBin = Get-ChildItem -Recurse -Force -Filter dumpbin.exe -path "$env:ProgramFiles\Microsoft Visual Studio\2022\Enterprise" | Select-Object -First 1 + # use wow programfiles because they always point to x64 programfiles where VS is installed + $dumpBin = Get-ChildItem -Recurse -Force -Filter dumpbin.exe -path "$env:ProgramW6432\Microsoft Visual Studio\2022\Enterprise" | Select-Object -First 1 if (-not $dumpBin) { - throw "Did not find dumpbin.exe in '$env:ProgramFiles\Microsoft Visual Studio\2022\Enterprise'." + throw "Did not find dumpbin.exe in '$env:ProgramW6432\Microsoft Visual Studio\2022\Enterprise'." } $corFlags = Get-ChildItem -Recurse -Force -Filter CorFlags.exe -path "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows" | Select-Object -First 1 From 2dfc178876ad81fb430b64d112eca1bec7405409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 9 Jul 2024 11:01:58 +0200 Subject: [PATCH 3/3] Skip exe architecture check --- eng/verify-nupkgs.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/verify-nupkgs.ps1 b/eng/verify-nupkgs.ps1 index 02f5847d3c..0702663de1 100644 --- a/eng/verify-nupkgs.ps1 +++ b/eng/verify-nupkgs.ps1 @@ -300,5 +300,6 @@ function Verify-NugetPackageVersion { $unzipNugetPackages = Verify-Nuget-Packages Start-sleep -Seconds 10 -Verify-NugetPackageExe -configuration $configuration -UnzipNugetPackages $unzipNugetPackages +# skipped, it is hard to find the right dumpbin.exe and corflags tools on server +# Verify-NugetPackageExe -configuration $configuration -UnzipNugetPackages $unzipNugetPackages Verify-NugetPackageVersion -configuration $configuration -UnzipNugetPackages $unzipNugetPackages