From 6c171610a3c57b50673971e5d0d9ae5e8866a78c Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 21 Apr 2022 09:46:28 -0700 Subject: [PATCH] Make mariner packages Framework dependent (#17151) --- build.psm1 | 20 +++++-- tools/packages.microsoft.com/mapping.json | 10 ++++ tools/packaging/packaging.psm1 | 63 +++++++++++++++++++++-- 3 files changed, 86 insertions(+), 7 deletions(-) diff --git a/build.psm1 b/build.psm1 index 89714cc2dfc8..2834b22a22dd 100644 --- a/build.psm1 +++ b/build.psm1 @@ -269,6 +269,8 @@ function Test-IsReleaseCandidate return $false } +$optimizedFddRegex = 'fxdependent-(linux|alpine|win|win7|osx)-(x64|x86|arm64|arm)' + function Start-PSBuild { [CmdletBinding(DefaultParameterSetName="Default")] param( @@ -303,6 +305,7 @@ function Start-PSBuild { # If this parameter is not provided it will get determined automatically. [ValidateSet("alpine-x64", "fxdependent", + "fxdependent-linux-x64", "fxdependent-win-desktop", "linux-arm", "linux-arm64", @@ -457,7 +460,7 @@ Fix steps: # Framework Dependent builds do not support ReadyToRun as it needs a specific runtime to optimize for. # The property is set in Powershell.Common.props file. # We override the property through the build command line. - if($Options.Runtime -like 'fxdependent*' -or $ForMinimalSize) { + if(($Options.Runtime -like 'fxdependent*' -or $ForMinimalSize) -and $Options.Runtime -notmatch $optimizedFddRegex) { $Arguments += "/property:PublishReadyToRun=false" } @@ -472,6 +475,9 @@ Fix steps: if (-not $SMAOnly -and $Options.Runtime -notlike 'fxdependent*') { # libraries should not have runtime $Arguments += "--runtime", $Options.Runtime + } elseif ($Options.Runtime -match $optimizedFddRegex) { + $runtime = $Options.Runtime -replace 'fxdependent-', '' + $Arguments += "--runtime", $runtime } if ($ReleaseTag) { @@ -495,7 +501,12 @@ Fix steps: # Handle TypeGen # .inc file name must be different for Windows and Linux to allow build on Windows and WSL. - $incFileName = "powershell_$($Options.Runtime).inc" + $runtime = $Options.Runtime + if ($Options.Runtime -match $optimizedFddRegex) { + $runtime = $Options.Runtime -replace 'fxdependent-', '' + } + + $incFileName = "powershell_$runtime.inc" if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/TypeCatalogGen/$incFileName")) { Write-Log -message "Run TypeGen (generating CorePsTypeCatalog.cs)" Start-TypeGen -IncFileName $incFileName @@ -513,7 +524,8 @@ Fix steps: # Relative paths do not work well if cwd is not changed to project Push-Location $Options.Top - if ($Options.Runtime -notlike 'fxdependent*') { + if ($Options.Runtime -notlike 'fxdependent*' -or $Options.Runtime -match $optimizedFddRegex) { + Write-Verbose "Building without shim" -Verbose $sdkToUse = 'Microsoft.NET.Sdk' if ($Options.Runtime -like 'win7-*' -and !$ForMinimalSize) { ## WPF/WinForm and the PowerShell GraphicalHost assemblies are included @@ -527,6 +539,7 @@ Fix steps: Start-NativeExecution { dotnet $Arguments } Write-Log -message "PowerShell output: $($Options.Output)" } else { + Write-Verbose "Building with shim" -Verbose $globalToolSrcFolder = Resolve-Path (Join-Path $Options.Top "../Microsoft.PowerShell.GlobalTool.Shim") | Select-Object -ExpandProperty Path if ($Options.Runtime -eq 'fxdependent') { @@ -811,6 +824,7 @@ function New-PSOptions { [ValidateSet("", "alpine-x64", "fxdependent", + "fxdependent-linux-x64", "fxdependent-win-desktop", "linux-arm", "linux-arm64", diff --git a/tools/packages.microsoft.com/mapping.json b/tools/packages.microsoft.com/mapping.json index c9ac168a43da..ba0b2def3176 100644 --- a/tools/packages.microsoft.com/mapping.json +++ b/tools/packages.microsoft.com/mapping.json @@ -15,6 +15,16 @@ "distribution" : ["trusty"], "PackageFormat" : "PACKAGE_NAME-POWERSHELL_RELEASE-1.rh.x86_64.rpm" }, + { + "url": "cbl-mariner-1.0-prod-Microsoft-x86_64-rpms", + "distribution" : ["bionic"], + "PackageFormat" : "PACKAGE_NAME-POWERSHELL_RELEASE-1.cm1.x86_64.rpm" + }, + { + "url": "cbl-mariner-2.0-prod-Microsoft-x86_64-rpms", + "distribution" : ["bionic"], + "PackageFormat" : "PACKAGE_NAME-POWERSHELL_RELEASE-1.cm1.x86_64.rpm" + }, { "distribution" : ["stretch"], "PackageFormat" : "PACKAGE_NAME_POWERSHELL_RELEASE-1.deb_amd64.deb" diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 3792e295cd45..f31a30f6cbf7 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -7,7 +7,11 @@ $RepoRoot = (Resolve-Path -Path "$PSScriptRoot/../..").Path $packagingStrings = Import-PowerShellDataFile "$PSScriptRoot\packaging.strings.psd1" Import-Module "$PSScriptRoot\..\Xml" -ErrorAction Stop -Force $DebianDistributions = @("deb") -$RedhatDistributions = @("rh","cm1") +$RedhatFullDistributions = @("rh") +$RedhatFddDistributions = @("cm1") +$RedhatDistributions = @() +$RedhatDistributions += $RedhatFullDistributions +$RedhatDistributions += $RedhatFddDistributions $AllDistributions = @() $AllDistributions += $DebianDistributions $AllDistributions += $RedhatDistributions @@ -33,7 +37,7 @@ function Start-PSPackage { [string]$Name = "powershell", # Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported - [ValidateSet("msix", "deb", "osxpkg", "rpm", "msi", "zip", "zip-pdb", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent", "fxdependent-win-desktop", "min-size")] + [ValidateSet("msix", "deb", "osxpkg", "rpm", "rpm-fxdependent", "msi", "zip", "zip-pdb", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent", "fxdependent-win-desktop", "min-size")] [string[]]$Type, # Generate windows downlevel package @@ -91,6 +95,8 @@ function Start-PSPackage { } else { New-PSOptions -Configuration "Release" -Runtime "Linux-ARM64" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } + } elseif ($Type.Count -eq 1 -and $Type[0] -eq "rpm-fxdependent") { + New-PSOptions -Configuration "Release" -Runtime 'fxdependent-linux-x64' -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } else { New-PSOptions -Configuration "Release" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } @@ -524,7 +530,25 @@ function Start-PSPackage { NoSudo = $NoSudo LTS = $LTS } - foreach ($Distro in $Script:RedhatDistributions) { + foreach ($Distro in $Script:RedhatFullDistributions) { + $Arguments["Distribution"] = $Distro + if ($PSCmdlet.ShouldProcess("Create RPM Package for $Distro")) { + Write-Verbose -Verbose "Creating RPM Package for $Distro" + New-UnixPackage @Arguments + } + } + } + 'rpm-fxdependent' { + $Arguments = @{ + Type = 'rpm' + PackageSourcePath = $Source + Name = $Name + Version = $Version + Force = $Force + NoSudo = $NoSudo + LTS = $LTS + } + foreach ($Distro in $Script:RedhatFddDistributions) { $Arguments["Distribution"] = $Distro if ($PSCmdlet.ShouldProcess("Create RPM Package for $Distro")) { Write-Verbose -Verbose "Creating RPM Package for $Distro" @@ -834,7 +858,7 @@ function New-UnixPackage { ) DynamicParam { - if ($Type -eq "deb" -or $Type -eq 'rpm') { + if ($Type -eq "deb" -or $Type -like 'rpm*') { # Add a dynamic parameter '-Distribution' when the specified package type is 'deb'. # The '-Distribution' parameter can be used to indicate which Debian distro this pacakge is targeting. $ParameterAttr = New-Object "System.Management.Automation.ParameterAttribute" @@ -1406,6 +1430,11 @@ function Get-PackageDependencies "icu" "openssl-libs" ) + if($Script:Options.Runtime -like 'fx*') { + $Dependencies += @( + "dotnet-runtime-7.0" + ) + } } elseif ($Distribution -eq 'macOS') { # do nothing } else { @@ -4414,6 +4443,7 @@ ${mainLinuxBuildFolder} = 'pwshLinuxBuild' ${minSizeLinuxBuildFolder} = 'pwshLinuxBuildMinSize' ${arm32LinuxBuildFolder} = 'pwshLinuxBuildArm32' ${arm64LinuxBuildFolder} = 'pwshLinuxBuildArm64' +${amd64MarinerBuildFolder} = 'pwshMarinerBuildAmd64' <# Used in Azure DevOps Yaml to package all the linux packages for a channel. @@ -4479,6 +4509,14 @@ function Invoke-AzDevOpsLinuxPackageCreation { ## Note that 'linux-arm64' can only be built on Ubuntu environment. Restore-PSOptions -PSOptionsPath "${env:SYSTEM_ARTIFACTSDIRECTORY}\${arm64LinuxBuildFolder}-meta\psoptions.json" Start-PSPackage -Type tar-arm64 @releaseTagParam -LTS:$LTS + } elseif ($BuildType -eq 'rpm') { + Restore-PSOptions -PSOptionsPath "${env:SYSTEM_ARTIFACTSDIRECTORY}\${amd64MarinerBuildFolder}-meta\psoptions.json" + + Write-Verbose -Verbose "---- rpm-fxdependent ----" + Write-Verbose -Verbose "options.Output: $($options.Output)" + Write-Verbose -Verbose "options.Top $($options.Top)" + + Start-PSPackage -Type rpm-fxdependent @releaseTagParam -LTS:$LTS } } catch { @@ -4558,6 +4596,23 @@ function Invoke-AzDevOpsLinuxPackageBuild { Start-PSBuild -Configuration Release -Restore -Runtime linux-arm64 -PSModuleRestore @releaseTagParam -Output $buildFolder -PSOptionsPath "${buildFolder}-meta/psoptions.json" # Remove symbol files. Remove-Item "${buildFolder}\*.pdb" -Force + } elseif ($BuildType -eq 'rpm') { + ## Build 'min-size' + $options = Get-PSOptions + Write-Verbose -Verbose "---- Min-Size ----" + Write-Verbose -Verbose "options.Output: $($options.Output)" + Write-Verbose -Verbose "options.Top $($options.Top)" + $binDir = Join-Path -Path $options.Top -ChildPath 'bin' + if (Test-Path -Path $binDir) { + Write-Verbose -Verbose "Remove $binDir, to get a clean build for min-size package" + Remove-Item -Path $binDir -Recurse -Force + } + + $buildParams['Runtime'] = 'fxdependent-linux-x64' + $buildFolder = "${env:SYSTEM_ARTIFACTSDIRECTORY}/${amd64MarinerBuildFolder}" + Start-PSBuild -Clean @buildParams @releaseTagParam -Output $buildFolder -PSOptionsPath "${buildFolder}-meta/psoptions.json" + # Remove symbol files, xml document files. + Remove-Item "${buildFolder}\*.pdb", "${buildFolder}\*.xml" -Force } } catch {