From 9827d879929c3674588631833413c9d0dd163594 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 12:14:42 -0800 Subject: [PATCH 01/15] checkpoint --- tools/packaging/packaging.psm1 | 143 ++++++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 3 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index daa493f19eb..6c05bbf71ac 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -20,6 +20,18 @@ $script:netCoreRuntime = 'net7.0' $script:iconFileName = "Powershell_black_64.png" $script:iconPath = Join-Path -path $PSScriptRoot -ChildPath "../../assets/$iconFileName" -Resolve +class R2RVerification { + [ValidateSet('NoR2R','R2R','SdkOnly')] + [string] + $R2RState = 'R2R' + + [string] + $Architecture = 'x64' + + [string] + $OperatingSystem = 'Windows' +} + function Start-PSPackage { [CmdletBinding(DefaultParameterSetName='Version',SupportsShouldProcess=$true)] param( @@ -326,6 +338,11 @@ function Start-PSPackage { PackageSourcePath = $Source PackageVersion = $Version Force = $Force + R2RVerification = [R2RVerification]@{ + R2RState = "R2R" + OperatingSystem = "Windows" + Architecture = "x64" + } } if ($PSCmdlet.ShouldProcess("Create Zip Package")) { @@ -352,6 +369,11 @@ function Start-PSPackage { PackageSourcePath = $Source PackageVersion = $Version Force = $Force + R2RVerification = [R2RVerification]@{ + R2RState = SdkOnly + OperatingSystem = "Windows" + Architecture = "x64" + } } if ($PSCmdlet.ShouldProcess("Create Zip Package")) { @@ -379,6 +401,9 @@ function Start-PSPackage { PackageSourcePath = $Source PackageVersion = $Version Force = $Force + R2RVerification = [R2RVerification]@{ + R2RState = NoR2R + } } if ($PSCmdlet.ShouldProcess("Create Zip Package")) { @@ -1682,15 +1707,52 @@ function New-StagingFolder [Parameter(Mandatory)] [string] $StagingPath, + [Parameter(Mandatory)] [string] $PackageSourcePath, + [string] - $Filter = '*' + $Filter = '*', + + [R2RVerification] + $R2RVerification = [R2RVerification]::new() ) Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $StagingPath Copy-Item -Recurse $PackageSourcePath $StagingPath -Filter $Filter + + $smaPath = Join-Path $StagingPath 'System.Management.Automation.dll' + $smaInfo = Get-PEInfo -Path $smaPath + switch($R2RVerification.R2RState) { + 'R2R' { + if (!$smaInfo.CrossGen -or $smaInfo.Architecture -ne $R2RVerification.Architecture -or $smaInfo.OS -ne $R2RVerification.OperatingSystem) { + throw "System.Management.Automation.dll is not ReadyToRun for $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actualy ($($smaInfo.CrossGen) $($smaInfo.OS) $($smaInfo.Architecture) )" + } + $mismatchedCrossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | + Get-PEInfo | + Where-Object { $_.CrossGen -and $_.OS -ne $R2RVerification.OperatingSystem -and $_.Architecture -ne $R2RVerification.Architecture }) + if ($mismatchedCrossGenedFiles.Count -gt 0) { + foreach($file in $mismatchedCrossGenedFiles) { + Write-Warning "Misconfigured ReadyToRun file found. Expected $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actual ($($file.OS) $($file.Architecture) ) " + } + throw "Unexpected ReadyToRun files found." + } + } + 'NoR2R' { + $crossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | + Get-PEInfo | + Where-Object { $_.CrossGen }) + if ($crossGenedFiles.Count -gt 0) { + throw "Unexpected ReadyToRun files found: $($crossGenedFiles | ForEach-Object { $_.Path })" + } + } + 'SdkOnly' { + if($smaInfo.CrossGen) { + throw "System.Management.Automation.dll should not be ReadyToRun" + } + } + } } # Function to create a zip file for Nano Server and xcopy deployment @@ -1718,7 +1780,9 @@ function New-ZipPackage [switch] $Force, - [string] $CurrentLocation = (Get-Location) + [string] $CurrentLocation = (Get-Location), + + [R2RVerification] $R2RVerification = [R2RVerification]::new() ) $ProductSemanticVersion = Get-PackageSemanticVersion -Version $PackageVersion @@ -1745,7 +1809,7 @@ function New-ZipPackage if ($PSCmdlet.ShouldProcess("Create zip package")) { $staging = "$PSScriptRoot/staging" - New-StagingFolder -StagingPath $staging -PackageSourcePath $PackageSourcePath + New-StagingFolder -StagingPath $staging -PackageSourcePath $PackageSourcePath -R2RVerification $R2RVerification Compress-Archive -Path $staging\* -DestinationPath $zipLocationPath } @@ -4825,3 +4889,76 @@ function Test-PackageManifest { } } } + +# Get the PE information for a file +function Get-PEInfo { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $File) + BEGIN { + # retrieved from ILCompiler.PEWriter.MachineOSOverride + enum MachineOSOverride { + Windows = 0 + SunOS = 6546 + NetBSD = 6547 + Apple = 17988 + Linux = 31609 + FreeBSD = 44484 + } + + # The information we want + class PsPeInfo { + [string]$File + [bool]$CrossGen + [MachineOSOverride]$OS + [System.Reflection.PortableExecutable.Machine]$Architecture + [System.Reflection.PortableExecutable.CorFlags]$Flags + } + + } + PROCESS { + $filePath = (get-item $file).fullname + $CrossGenFlag = 4 + try { + $stream = [System.IO.FileStream]::new($FilePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read) + $peReader = [System.Reflection.PortableExecutable.PEReader]::new($stream) + $flags = $peReader.PEHeaders.CorHeader.Flags + if (-not $flags) { + throw "Null Flags" + } + $machine = $peReader.PEHeaders.CoffHeader.Machine + if (-not $machine) { + throw "Null Machine" + } + } catch { + $er = [system.management.automation.errorrecord]::new(([InvalidOperationException]::new($_)), "Get-PEInfo:InvalidOperation", "InvalidOperation", $filePath) + $PSCmdlet.WriteError($er) + return + } finally { + if ($peReader) { + $peReader.Dispose() + } + } + + [ushort]$r2rOsArch = $machine + + $RealOS = "unknown" + $realarch = "unknown" + foreach ($os in [enum]::GetValues([MachineOSOverride])) { + foreach ($architecture in [Enum]::GetValues([System.Reflection.PortableExecutable.Machine])) { + if (([ushort]$architecture -BXOR [ushort]$os) -eq [ushort]$r2rOsArch) { + $realOS = $os + $realArch = $architecture + + [PsPeInfo]@{ + File = $File + OS = $realos + Architecture = $realarch + CrossGen = [bool]($flags -band $CrossGenFlag) + Flags = $flags + } + return + } + } + } + } +} From 7e851305bd296fff83c328d0a318423eea104074 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 16:21:23 -0800 Subject: [PATCH 02/15] missed windows cross compile --- build.psm1 | 4 ++++ tools/packaging/packaging.psm1 | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 4e1fd0f3f9a..915d4ee0d1d 100644 --- a/build.psm1 +++ b/build.psm1 @@ -795,6 +795,10 @@ function Restore-PSPackage $RestoreArguments += "quiet" } + if ($Options.Runtime -like 'win*') { + $RestoreArguments += "/property:EnableWindowsTargeting=True" + } + if ($InteractiveAuth) { $RestoreArguments += "--interactive" } diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 6c05bbf71ac..67de08cbe91 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -54,7 +54,6 @@ function Start-PSPackage { # Generate windows downlevel package [ValidateSet("win7-x86", "win7-x64", "win-arm", "win-arm64")] - [ValidateScript({$Environment.IsWindows})] [string] $WindowsRuntime, [ValidateSet('osx-x64', 'osx-arm64')] From e7a4538fa7888153296f6e15931741b6a6cc85f0 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 16:25:40 -0800 Subject: [PATCH 03/15] Add verification of R2R at packaging --- tools/packaging/packaging.psm1 | 112 ++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 15 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 67de08cbe91..85bf00c698f 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -25,9 +25,10 @@ class R2RVerification { [string] $R2RState = 'R2R' - [string] - $Architecture = 'x64' + [System.Reflection.PortableExecutable.Machine] + $Architecture = [System.Reflection.PortableExecutable.Machine]::Amd64 + [ValidateSet('Linux','Apple','Windows')] [string] $OperatingSystem = 'Windows' } @@ -332,6 +333,10 @@ function Start-PSPackage { switch ($Type) { "zip" { + $os, $architecture = ($Script:Options.Runtime -split '-') + $peOS = ConvertTo-PEOperatingSystem -OperatingSystem $os + $peArch = ConvertTo-PEArchitecture -Architecture $architecture + $Arguments = @{ PackageNameSuffix = $NameSuffix PackageSourcePath = $Source @@ -339,8 +344,8 @@ function Start-PSPackage { Force = $Force R2RVerification = [R2RVerification]@{ R2RState = "R2R" - OperatingSystem = "Windows" - Architecture = "x64" + OperatingSystem = $peOS + Architecture = $peArch } } @@ -371,7 +376,7 @@ function Start-PSPackage { R2RVerification = [R2RVerification]@{ R2RState = SdkOnly OperatingSystem = "Windows" - Architecture = "x64" + Architecture = "amd64" } } @@ -386,6 +391,9 @@ function Start-PSPackage { PackageNameSuffix = 'gc' Version = $Version Force = $Force + R2RVerification = [R2RVerification]@{ + R2RState = SdkOnly + } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -415,6 +423,9 @@ function Start-PSPackage { PackageNameSuffix = 'fxdependent' Version = $Version Force = $Force + R2RVerification = [R2RVerification]@{ + R2RState = NoR2R + } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -424,8 +435,10 @@ function Start-PSPackage { } "msi" { $TargetArchitecture = "x64" + $r2rArchitecture = "amd64" if ($Runtime -match "-x86") { $TargetArchitecture = "x86" + $r2rArchitecture = "i386" } Write-Verbose "TargetArchitecture = $TargetArchitecture" -Verbose @@ -436,7 +449,11 @@ function Start-PSPackage { AssetsPath = "$RepoRoot\assets" ProductTargetArchitecture = $TargetArchitecture Force = $Force - } + R2RVerification = [R2RVerification]@{ + R2RState = NoR2R + Architecture = $r2rArchitecture + } + } if ($PSCmdlet.ShouldProcess("Create MSI Package")) { New-MSIPackage @Arguments @@ -478,7 +495,20 @@ function Start-PSPackage { } if ($MacOSRuntime) { - $Arguments['Architecture'] = $MacOSRuntime.Split('-')[1] + $architecture = $MacOSRuntime.Split('-')[1] + $Arguments['Architecture'] = $architecture + } + + if ($Script:Options.Runtime -match '(linux|osx).*') { + $os, $architecture = ($Script:Options.Runtime -split '-') + $peOS = ConvertTo-PEOperatingSystem -OperatingSystem $os + $peArch = ConvertTo-PEArchitecture -Architecture $architecture + + $Arguments['R2RVerification'] = [R2RVerification]@{ + R2RState = "R2R" + OperatingSystem = $peOS + Architecture = $peArch + } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -493,6 +523,9 @@ function Start-PSPackage { Force = $Force Architecture = "arm32" ExcludeSymbolicLinks = $true + R2RVerification = [R2RVerification]@{ + R2RState = SdkOnly + } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -507,6 +540,9 @@ function Start-PSPackage { Force = $Force Architecture = "arm64" ExcludeSymbolicLinks = $true + R2RVerification = [R2RVerification]@{ + R2RState = SdkOnly + } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -521,6 +557,9 @@ function Start-PSPackage { Force = $Force Architecture = "alpine-x64" ExcludeSymbolicLinks = $true + R2RVerification = [R2RVerification]@{ + R2RState = SdkOnly + } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -652,7 +691,9 @@ function New-TarballPackage { [switch] $ExcludeSymbolicLinks, - [string] $CurrentLocation = (Get-Location) + [string] $CurrentLocation = (Get-Location), + + [R2RVerification] $R2RVerification ) if ($PackageNameSuffix) { @@ -681,7 +722,7 @@ function New-TarballPackage { } $Staging = "$PSScriptRoot/staging" - New-StagingFolder -StagingPath $Staging -PackageSourcePath $PackageSourcePath + New-StagingFolder -StagingPath $Staging -PackageSourcePath $PackageSourcePath -R2RVerification $R2RVerification if (Get-Command -Name tar -CommandType Application -ErrorAction Ignore) { if ($Force -or $PSCmdlet.ShouldProcess("Create tarball package")) { @@ -1715,22 +1756,26 @@ function New-StagingFolder $Filter = '*', [R2RVerification] - $R2RVerification = [R2RVerification]::new() + $R2RVerification ) Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $StagingPath Copy-Item -Recurse $PackageSourcePath $StagingPath -Filter $Filter $smaPath = Join-Path $StagingPath 'System.Management.Automation.dll' - $smaInfo = Get-PEInfo -Path $smaPath + $smaInfo = Get-PEInfo -File $smaPath switch($R2RVerification.R2RState) { + $null { + Write-Verbose "Skipping R2R verification" -Verbose + } 'R2R' { + Write-Verbose "Verifying R2R was done..." -Verbose if (!$smaInfo.CrossGen -or $smaInfo.Architecture -ne $R2RVerification.Architecture -or $smaInfo.OS -ne $R2RVerification.OperatingSystem) { throw "System.Management.Automation.dll is not ReadyToRun for $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actualy ($($smaInfo.CrossGen) $($smaInfo.OS) $($smaInfo.Architecture) )" } $mismatchedCrossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | - Get-PEInfo | - Where-Object { $_.CrossGen -and $_.OS -ne $R2RVerification.OperatingSystem -and $_.Architecture -ne $R2RVerification.Architecture }) + Get-PEInfo | + Where-Object { $_.CrossGen -and $_.OS -ne $R2RVerification.OperatingSystem -and $_.Architecture -ne $R2RVerification.Architecture }) if ($mismatchedCrossGenedFiles.Count -gt 0) { foreach($file in $mismatchedCrossGenedFiles) { Write-Warning "Misconfigured ReadyToRun file found. Expected $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actual ($($file.OS) $($file.Architecture) ) " @@ -1739,14 +1784,16 @@ function New-StagingFolder } } 'NoR2R' { + Write-Verbose "Verifying no R2R was done..." -Verbose $crossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | - Get-PEInfo | - Where-Object { $_.CrossGen }) + Get-PEInfo | + Where-Object { $_.CrossGen }) if ($crossGenedFiles.Count -gt 0) { throw "Unexpected ReadyToRun files found: $($crossGenedFiles | ForEach-Object { $_.Path })" } } 'SdkOnly' { + Write-Verbose "Verifying no R2R was done on SMA..." -Verbose if($smaInfo.CrossGen) { throw "System.Management.Automation.dll should not be ReadyToRun" } @@ -4961,3 +5008,38 @@ function Get-PEInfo { } } } + +function ConvertTo-PEArchitecture { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline = $true)] + [string] + $Architecture + ) + + PROCESS { + switch ($Architecture) { + "x86" { "I386" } + "x64" { "AMD64" } + default { $Architecture } + } + } +} + +function ConvertTo-PEOperatingSystem { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline = $true)] + [string] + $OperatingSystem + ) + + PROCESS { + switch -regex ($OperatingSystem) { + "win.*" { "Windows" } + "Linux" { "Linux" } + "OSX" { "Apple" } + default { $OperatingSystem } + } + } +} From 860758c15c40616acf8226392a5d376fd9ef79a8 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 16:40:53 -0800 Subject: [PATCH 04/15] Fix R2RState --- tools/packaging/packaging.psm1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 85bf00c698f..3b099b39bb1 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -343,7 +343,7 @@ function Start-PSPackage { PackageVersion = $Version Force = $Force R2RVerification = [R2RVerification]@{ - R2RState = "R2R" + R2RState = 'R2R' OperatingSystem = $peOS Architecture = $peArch } @@ -374,7 +374,7 @@ function Start-PSPackage { PackageVersion = $Version Force = $Force R2RVerification = [R2RVerification]@{ - R2RState = SdkOnly + R2RState = 'SdkOnly' OperatingSystem = "Windows" Architecture = "amd64" } @@ -392,7 +392,7 @@ function Start-PSPackage { Version = $Version Force = $Force R2RVerification = [R2RVerification]@{ - R2RState = SdkOnly + R2RState = 'SdkOnly' } } @@ -409,7 +409,7 @@ function Start-PSPackage { PackageVersion = $Version Force = $Force R2RVerification = [R2RVerification]@{ - R2RState = NoR2R + R2RState = 'NoR2R' } } @@ -424,7 +424,7 @@ function Start-PSPackage { Version = $Version Force = $Force R2RVerification = [R2RVerification]@{ - R2RState = NoR2R + R2RState = 'NoR2R' } } @@ -450,7 +450,7 @@ function Start-PSPackage { ProductTargetArchitecture = $TargetArchitecture Force = $Force R2RVerification = [R2RVerification]@{ - R2RState = NoR2R + R2RState = 'NoR2R' Architecture = $r2rArchitecture } } @@ -524,7 +524,7 @@ function Start-PSPackage { Architecture = "arm32" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ - R2RState = SdkOnly + R2RState = 'SdkOnly' } } @@ -541,7 +541,7 @@ function Start-PSPackage { Architecture = "arm64" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ - R2RState = SdkOnly + R2RState = 'SdkOnly' } } @@ -558,7 +558,7 @@ function Start-PSPackage { Architecture = "alpine-x64" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ - R2RState = SdkOnly + R2RState = 'SdkOnly' } } From bd527d2a8e3f121d7b1e55be164d3671ff49ec60 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 16:54:28 -0800 Subject: [PATCH 05/15] fix build failures --- tools/packaging/packaging.psm1 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 3b099b39bb1..88b2b33ba5b 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -342,8 +342,18 @@ function Start-PSPackage { PackageSourcePath = $Source PackageVersion = $Version Force = $Force - R2RVerification = [R2RVerification]@{ - R2RState = 'R2R' + } + + if ($architecture -in 'x86', 'x64') { + $Arguments += @{ R2RVerification = [R2RVerification]@{ + R2RState = 'R2R' + OperatingSystem = $peOS + Architecture = $peArch + } + } + } else { + $Arguments += @{ R2RVerification = [R2RVerification]@{ + R2RState = 'SdkOnly' OperatingSystem = $peOS Architecture = $peArch } @@ -449,10 +459,6 @@ function Start-PSPackage { AssetsPath = "$RepoRoot\assets" ProductTargetArchitecture = $TargetArchitecture Force = $Force - R2RVerification = [R2RVerification]@{ - R2RState = 'NoR2R' - Architecture = $r2rArchitecture - } } if ($PSCmdlet.ShouldProcess("Create MSI Package")) { From c1747ea20990de3d65061804321e13c02f69efbf Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 17:08:05 -0800 Subject: [PATCH 06/15] fix brackets --- tools/packaging/packaging.psm1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 88b2b33ba5b..7a050e0ad15 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -353,9 +353,10 @@ function Start-PSPackage { } } else { $Arguments += @{ R2RVerification = [R2RVerification]@{ - R2RState = 'SdkOnly' - OperatingSystem = $peOS - Architecture = $peArch + R2RState = 'SdkOnly' + OperatingSystem = $peOS + Architecture = $peArch + } } } From 8f8b1c57186e55bd100769f87d4bc57a33bc791c Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 17:22:10 -0800 Subject: [PATCH 07/15] fix build issues --- tools/packaging/packaging.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 7a050e0ad15..9c74aeafd20 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -344,7 +344,7 @@ function Start-PSPackage { Force = $Force } - if ($architecture -in 'x86', 'x64') { + if ($architecture -in 'x86', 'x64', 'arm') { $Arguments += @{ R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = $peOS @@ -4976,7 +4976,7 @@ function Get-PEInfo { $peReader = [System.Reflection.PortableExecutable.PEReader]::new($stream) $flags = $peReader.PEHeaders.CorHeader.Flags if (-not $flags) { - throw "Null Flags" + Write-Warning "$filePath is not a managed assembly" } $machine = $peReader.PEHeaders.CoffHeader.Machine if (-not $machine) { From e47b4c6f8f3f0c19fd6f8f64784c0b91e8bc1a2c Mon Sep 17 00:00:00 2001 From: travis plunk Date: Thu, 9 Feb 2023 17:23:50 -0800 Subject: [PATCH 08/15] fix build issue --- tools/packaging/packaging.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 9c74aeafd20..5a45a60abba 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -344,7 +344,7 @@ function Start-PSPackage { Force = $Force } - if ($architecture -in 'x86', 'x64', 'arm') { + if ($architecture -in 'x86', 'x64', 'arm', 'arm64') { $Arguments += @{ R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = $peOS From 8ac125f60c2d331a06e39b990d8bd2c4852887f1 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 10 Feb 2023 10:12:05 -0800 Subject: [PATCH 09/15] Make some fields nullable in PsPeInfo --- tools/packaging/packaging.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 5a45a60abba..185b2444158 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -4962,9 +4962,9 @@ function Get-PEInfo { class PsPeInfo { [string]$File [bool]$CrossGen - [MachineOSOverride]$OS + [Nullable[MachineOSOverride]]$OS [System.Reflection.PortableExecutable.Machine]$Architecture - [System.Reflection.PortableExecutable.CorFlags]$Flags + [Nullable[System.Reflection.PortableExecutable.CorFlags]]$Flags } } @@ -4994,7 +4994,7 @@ function Get-PEInfo { [ushort]$r2rOsArch = $machine - $RealOS = "unknown" + $RealOS = $null $realarch = "unknown" foreach ($os in [enum]::GetValues([MachineOSOverride])) { foreach ($architecture in [Enum]::GetValues([System.Reflection.PortableExecutable.Machine])) { From cf7b752f07eaf962dafacad668f6b131eb71bb75 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 10 Feb 2023 11:04:57 -0800 Subject: [PATCH 10/15] Don't read SMA if we are Skipping R2R verification --- tools/packaging/packaging.psm1 | 58 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 185b2444158..a1a68f91ec4 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -1770,39 +1770,41 @@ function New-StagingFolder Copy-Item -Recurse $PackageSourcePath $StagingPath -Filter $Filter $smaPath = Join-Path $StagingPath 'System.Management.Automation.dll' - $smaInfo = Get-PEInfo -File $smaPath - switch($R2RVerification.R2RState) { - $null { - Write-Verbose "Skipping R2R verification" -Verbose - } - 'R2R' { - Write-Verbose "Verifying R2R was done..." -Verbose - if (!$smaInfo.CrossGen -or $smaInfo.Architecture -ne $R2RVerification.Architecture -or $smaInfo.OS -ne $R2RVerification.OperatingSystem) { - throw "System.Management.Automation.dll is not ReadyToRun for $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actualy ($($smaInfo.CrossGen) $($smaInfo.OS) $($smaInfo.Architecture) )" + if ($R2RVerification) { + $smaInfo = Get-PEInfo -File $smaPath + switch ($R2RVerification.R2RState) { + $null { + Write-Verbose "Skipping R2R verification" -Verbose } - $mismatchedCrossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | - Get-PEInfo | + 'R2R' { + Write-Verbose "Verifying R2R was done..." -Verbose + if (!$smaInfo.CrossGen -or $smaInfo.Architecture -ne $R2RVerification.Architecture -or $smaInfo.OS -ne $R2RVerification.OperatingSystem) { + throw "System.Management.Automation.dll is not ReadyToRun for $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actualy ($($smaInfo.CrossGen) $($smaInfo.OS) $($smaInfo.Architecture) )" + } + $mismatchedCrossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | + Get-PEInfo | Where-Object { $_.CrossGen -and $_.OS -ne $R2RVerification.OperatingSystem -and $_.Architecture -ne $R2RVerification.Architecture }) - if ($mismatchedCrossGenedFiles.Count -gt 0) { - foreach($file in $mismatchedCrossGenedFiles) { - Write-Warning "Misconfigured ReadyToRun file found. Expected $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actual ($($file.OS) $($file.Architecture) ) " + if ($mismatchedCrossGenedFiles.Count -gt 0) { + foreach ($file in $mismatchedCrossGenedFiles) { + Write-Warning "Misconfigured ReadyToRun file found. Expected $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actual ($($file.OS) $($file.Architecture) ) " + } + throw "Unexpected ReadyToRun files found." } - throw "Unexpected ReadyToRun files found." } - } - 'NoR2R' { - Write-Verbose "Verifying no R2R was done..." -Verbose - $crossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | - Get-PEInfo | + 'NoR2R' { + Write-Verbose "Verifying no R2R was done..." -Verbose + $crossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | + Get-PEInfo | Where-Object { $_.CrossGen }) - if ($crossGenedFiles.Count -gt 0) { - throw "Unexpected ReadyToRun files found: $($crossGenedFiles | ForEach-Object { $_.Path })" + if ($crossGenedFiles.Count -gt 0) { + throw "Unexpected ReadyToRun files found: $($crossGenedFiles | ForEach-Object { $_.Path })" + } } - } - 'SdkOnly' { - Write-Verbose "Verifying no R2R was done on SMA..." -Verbose - if($smaInfo.CrossGen) { - throw "System.Management.Automation.dll should not be ReadyToRun" + 'SdkOnly' { + Write-Verbose "Verifying no R2R was done on SMA..." -Verbose + if ($smaInfo.CrossGen) { + throw "System.Management.Automation.dll should not be ReadyToRun" + } } } } @@ -1933,6 +1935,8 @@ function New-PdbZipPackage if ($PSCmdlet.ShouldProcess("Create zip package")) { $staging = "$PSScriptRoot/staging" + + # We should NOT R2R verify the PDB zip New-StagingFolder -StagingPath $staging -PackageSourcePath $PackageSourcePath -Filter *.pdb Compress-Archive -Path $staging\* -DestinationPath $zipLocationPath From 5d86d7a697b9fc52ec6ae028f5eaa9c1f33edfe2 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 10 Feb 2023 11:28:44 -0800 Subject: [PATCH 11/15] map ARM runtime to ArmThumb2 architecture --- tools/packaging/packaging.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index a1a68f91ec4..46dc252ed62 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -5032,6 +5032,7 @@ function ConvertTo-PEArchitecture { switch ($Architecture) { "x86" { "I386" } "x64" { "AMD64" } + "arm" { "ArmThumb2" } default { $Architecture } } } From d9eec19a6e987abc15340bb2bbd41f4d6343d876 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 10 Feb 2023 11:35:04 -0800 Subject: [PATCH 12/15] mark that tar-arm* are actually R2R builds --- tools/packaging/packaging.psm1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 46dc252ed62..7463bce2324 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -531,7 +531,9 @@ function Start-PSPackage { Architecture = "arm32" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ - R2RState = 'SdkOnly' + R2RState = 'R2R' + OperatingSystem = "Linux" + Architecture = "arm" } } @@ -548,7 +550,9 @@ function Start-PSPackage { Architecture = "arm64" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ - R2RState = 'SdkOnly' + R2RState = 'R2R' + OperatingSystem = "Linux" + Architecture = "arm64" } } From 59ef547b67dbdf22ce79c4a0669c2129db7ca4aa Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 10 Feb 2023 12:27:09 -0800 Subject: [PATCH 13/15] fix ARM arch again --- tools/packaging/packaging.psm1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 7463bce2324..106e34f9bc6 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -523,6 +523,7 @@ function Start-PSPackage { } } "tar-arm" { + $peArch = ConvertTo-PEArchitecture -Architecture 'arm' $Arguments = @{ PackageSourcePath = $Source Name = $Name @@ -533,7 +534,7 @@ function Start-PSPackage { R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = "Linux" - Architecture = "arm" + Architecture = $peArch } } From f5deab3e3ef6df5e093a9bc466772bef04233138 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 10 Feb 2023 13:57:30 -0800 Subject: [PATCH 14/15] fix alpine --- tools/packaging/packaging.psm1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 106e34f9bc6..9d12bcaa698 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -570,7 +570,9 @@ function Start-PSPackage { Architecture = "alpine-x64" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ - R2RState = 'SdkOnly' + R2RState = 'R2R' + OperatingSystem = "Linux" + Architecture = "amd64" } } From 52d1128901b5167f7498134fd315478e09a4b9fe Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 14 Feb 2023 10:59:39 -0800 Subject: [PATCH 15/15] Update tools/packaging/packaging.psm1 Co-authored-by: Aditya Patwardhan --- tools/packaging/packaging.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 9d12bcaa698..85336f039b3 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -1786,7 +1786,7 @@ function New-StagingFolder 'R2R' { Write-Verbose "Verifying R2R was done..." -Verbose if (!$smaInfo.CrossGen -or $smaInfo.Architecture -ne $R2RVerification.Architecture -or $smaInfo.OS -ne $R2RVerification.OperatingSystem) { - throw "System.Management.Automation.dll is not ReadyToRun for $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actualy ($($smaInfo.CrossGen) $($smaInfo.OS) $($smaInfo.Architecture) )" + throw "System.Management.Automation.dll is not ReadyToRun for $($R2RVerification.OperatingSystem) $($R2RVerification.Architecture). Actually ($($smaInfo.CrossGen) $($smaInfo.OS) $($smaInfo.Architecture) )" } $mismatchedCrossGenedFiles = @(Get-ChildItem -Path $StagingPath -Filter '*.dll' -Recurse | Get-PEInfo |