Skip to content

Commit

Permalink
Make mariner packages Framework dependent (#17151)
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisEz13 committed Apr 21, 2022
1 parent 3446e55 commit 6c17161
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 7 deletions.
20 changes: 17 additions & 3 deletions build.psm1
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}

Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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') {
Expand Down Expand Up @@ -811,6 +824,7 @@ function New-PSOptions {
[ValidateSet("",
"alpine-x64",
"fxdependent",
"fxdependent-linux-x64",
"fxdependent-win-desktop",
"linux-arm",
"linux-arm64",
Expand Down
10 changes: 10 additions & 0 deletions tools/packages.microsoft.com/mapping.json
Expand Up @@ -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"
Expand Down
63 changes: 59 additions & 4 deletions tools/packaging/packaging.psm1
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6c17161

Please sign in to comment.