Skip to content

Commit 49288e4

Browse files
Make Linux package universal. (PowerShell#15109)
Co-authored-by: Aditya Patwardhan <adityap@microsoft.com>
1 parent 637912e commit 49288e4

6 files changed

Lines changed: 152 additions & 117 deletions

File tree

.vsts-ci/linux.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ stages:
8989
parameters:
9090
pool: ubuntu-16.04
9191

92+
- stage: PackageLinux
93+
displayName: Package Linux
94+
dependsOn: ["BuildLinux"]
95+
jobs:
96+
- template: linux/templates/packaging.yml
97+
parameters:
98+
pool: ubuntu-16.04
99+
92100
- stage: CodeCovTestPackage
93101
displayName: CodeCoverage and Test Packages
94102
dependsOn: [] # by specifying an empty array, this stage doesn't depend on the stage before it
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
parameters:
2+
pool: 'ubuntu-16.04'
3+
parentJobs: []
4+
name: 'Linux'
5+
6+
jobs:
7+
- job: ${{ parameters.name }}_packaging
8+
dependsOn:
9+
${{ parameters.parentJobs }}
10+
pool:
11+
vmImage: ${{ parameters.pool }}
12+
13+
displayName: ${{ parameters.name }} packaging
14+
15+
steps:
16+
- pwsh: |
17+
Get-ChildItem -Path env:
18+
displayName: Capture Environment
19+
condition: succeededOrFailed()
20+
21+
- task: DownloadBuildArtifacts@0
22+
displayName: 'Download build artifacts'
23+
inputs:
24+
downloadType: specific
25+
itemPattern: |
26+
build/**/*
27+
downloadPath: '$(System.ArtifactsDirectory)'
28+
29+
- pwsh: |
30+
Get-ChildItem "$(System.ArtifactsDirectory)\*" -Recurse
31+
displayName: 'Capture Artifacts Directory'
32+
continueOnError: true
33+
34+
- pwsh: |
35+
Import-Module .\build.psm1
36+
Start-PSBootstrap -Package
37+
displayName: Bootstrap
38+
39+
- pwsh: |
40+
Import-Module ./build.psm1
41+
displayName: 'Capture Artifacts Directory'
42+
continueOnError: true
43+
44+
- task: ExtractFiles@1
45+
displayName: 'Extract Build ZIP'
46+
inputs:
47+
archiveFilePatterns: '$(System.ArtifactsDirectory)/build/build.zip'
48+
destinationFolder: '$(System.ArtifactsDirectory)/bins'
49+
50+
- bash: |
51+
find "$(System.ArtifactsDirectory)/bins" -type d -exec chmod +rwx {} \;
52+
find "$(System.ArtifactsDirectory)/bins" -type f -exec chmod +rw {} \;
53+
displayName: 'Fix permissions'
54+
continueOnError: true
55+
56+
- pwsh: |
57+
Get-ChildItem "$(System.ArtifactsDirectory)\bins\*" -Recurse -ErrorAction SilentlyContinue
58+
displayName: 'Capture Extracted Build ZIP'
59+
continueOnError: true
60+
61+
- pwsh: |
62+
Import-Module .\tools\ci.psm1
63+
Restore-PSOptions -PSOptionsPath '$(System.ArtifactsDirectory)\build\psoptions.json'
64+
$options = (Get-PSOptions)
65+
$rootPath = '$(System.ArtifactsDirectory)\bins'
66+
$originalRootPath = Split-Path -path $options.Output
67+
$path = Join-Path -path $rootPath -ChildPath (split-path -leaf -path $originalRootPath)
68+
$pwshPath = Join-Path -path $path -ChildPath 'pwsh'
69+
chmod a+x $pwshPath
70+
$options.Output = $pwshPath
71+
Set-PSOptions $options
72+
Invoke-CIFinish
73+
displayName: Packaging Tests
74+
condition: succeeded()
75+
76+
- pwsh: |
77+
Get-ChildItem "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}\*.deb" -Recurse | ForEach-Object {
78+
$packagePath = $_.FullName
79+
Write-Host "Uploading $packagePath"
80+
Write-Host "##vso[artifact.upload containerfolder=deb;artifactname=deb]$packagePath"
81+
}
82+
Get-ChildItem "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}\*.rpm" -Recurse | ForEach-Object {
83+
$packagePath = $_.FullName
84+
Write-Host "Uploading $packagePath"
85+
Write-Host "##vso[artifact.upload containerfolder=rpm;artifactname=rpm]$packagePath"
86+
}
87+
Get-ChildItem "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}\*.tar.gz" -Recurse | ForEach-Object {
88+
$packagePath = $_.FullName
89+
Write-Host "Uploading $packagePath"
90+
Write-Host "##vso[artifact.upload containerfolder=rpm;artifactname=rpm]$packagePath"
91+
}
92+
displayName: Upload packages

.vsts-ci/templates/ci-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ jobs:
2020
displayName: Set Build Name for Non-PR
2121
condition: ne(variables['Build.Reason'], 'PullRequest')
2222

23-
- template: /tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml
23+
- ${{ if ne(variables['AzDevOpsFeed'], '') }}:
24+
- template: /tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml
2425

2526
- pwsh: |
2627
if (Test-Path -Path $HOME/.dotnet) {

tools/ci.psm1

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ function New-LinuxPackage
717717

718718
# Only build packages for PowerShell/PowerShell repository
719719
# branches, not pull requests
720-
$packages = @(Start-PSPackage @packageParams -SkipReleaseChecks)
720+
$packages = @(Start-PSPackage @packageParams -SkipReleaseChecks -Type deb, rpm, tar)
721721
foreach($package in $packages)
722722
{
723723
if (Test-Path $package)
@@ -729,21 +729,18 @@ function New-LinuxPackage
729729
Write-Error -Message "Package NOT found: $package"
730730
}
731731

732-
if($isFullBuild)
732+
if ($package -isnot [System.IO.FileInfo])
733733
{
734-
if ($package -isnot [System.IO.FileInfo])
735-
{
736-
$packageObj = Get-Item $package
737-
Write-Error -Message "The PACKAGE is not a FileInfo object"
738-
}
739-
else
740-
{
741-
$packageObj = $package
742-
}
743-
744-
Write-Log -message "Artifacts directory: ${env:BUILD_ARTIFACTSTAGINGDIRECTORY}"
745-
Copy-Item $packageObj.FullName -Destination "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}" -Force
734+
$packageObj = Get-Item $package
735+
Write-Error -Message "The PACKAGE is not a FileInfo object"
746736
}
737+
else
738+
{
739+
$packageObj = $package
740+
}
741+
742+
Write-Log -message "Artifacts directory: ${env:BUILD_ARTIFACTSTAGINGDIRECTORY}"
743+
Copy-Item $packageObj.FullName -Destination "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}" -Force
747744
}
748745

749746
if ($IsLinux)

tools/packaging/packaging.psm1

Lines changed: 15 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ $RepoRoot = (Resolve-Path -Path "$PSScriptRoot/../..").Path
66

77
$packagingStrings = Import-PowerShellDataFile "$PSScriptRoot\packaging.strings.psd1"
88
Import-Module "$PSScriptRoot\..\Xml" -ErrorAction Stop -Force
9-
$DebianDistributions = @("ubuntu.16.04", "ubuntu.18.04", "ubuntu.20.04", "debian.9", "debian.10", "debian.11")
10-
$RedhatDistributions = @("rhel.7","centos.8")
9+
$DebianDistributions = @("deb")
10+
$RedhatDistributions = @("rh")
1111
$script:netCoreRuntime = 'net6.0'
1212
$script:iconFileName = "Powershell_black_64.png"
1313
$script:iconPath = Join-Path -path $PSScriptRoot -ChildPath "../../assets/$iconFileName" -Resolve
@@ -577,10 +577,6 @@ function New-TarballPackage {
577577
$Staging = "$PSScriptRoot/staging"
578578
New-StagingFolder -StagingPath $Staging -PackageSourcePath $PackageSourcePath
579579

580-
if (-not $ExcludeSymbolicLinks.IsPresent) {
581-
New-PSSymbolicLinks -Distribution 'ubuntu.16.04' -Staging $Staging
582-
}
583-
584580
if (Get-Command -Name tar -CommandType Application -ErrorAction Ignore) {
585581
if ($Force -or $PSCmdlet.ShouldProcess("Create tarball package")) {
586582
$options = "-czf"
@@ -840,9 +836,6 @@ function New-UnixPackage {
840836
}
841837

842838
$packageVersion = Get-LinuxPackageSemanticVersion -Version $Version
843-
if (!$Environment.IsRedHatFamily -and !$Environment.IsSUSEFamily) {
844-
throw ($ErrorMessage -f "Redhat or SUSE Family")
845-
}
846839
}
847840
"osxpkg" {
848841
$packageVersion = $Version
@@ -904,8 +897,7 @@ function New-UnixPackage {
904897
if ($PSCmdlet.ShouldProcess("Create package file system"))
905898
{
906899
# Generate After Install and After Remove scripts
907-
$AfterScriptInfo = New-AfterScripts -Link $Link -Distribution $DebDistro
908-
New-PSSymbolicLinks -Distribution $DebDistro -Staging $Staging
900+
$AfterScriptInfo = New-AfterScripts -Link $Link -Distribution $DebDistro -Destination $Destination
909901

910902
# there is a weird bug in fpm
911903
# if the target of the powershell symlink exists, `fpm` aborts
@@ -1265,42 +1257,18 @@ function Get-FpmArguments
12651257
return $Arguments
12661258
}
12671259

1268-
function Test-Distribution
1269-
{
1270-
param(
1271-
[String]
1272-
$Distribution
1273-
)
1274-
1275-
if ( $Environment.IsDebianFamily -and !$Distribution )
1276-
{
1277-
throw "$Distribution is required for a Debian based distribution."
1278-
}
1279-
1280-
if ( $Environment.IsDebianFamily -and $Script:DebianDistributions -notcontains $Distribution)
1281-
{
1282-
throw "$Distribution should be one of the following: $Script:DebianDistributions"
1283-
}
1284-
1285-
if ( $Environment.IsRedHatFamily -and $Script:RedHatDistributions -notcontains $Distribution)
1286-
{
1287-
throw "$Distribution should be one of the following: $Script:RedHatDistributions"
1288-
}
1289-
1290-
return $true
1291-
}
12921260
function Get-PackageDependencies
12931261
{
12941262
param(
12951263
[String]
1296-
[ValidateScript({Test-Distribution -Distribution $_})]
1264+
[ValidateSet('rh','deb','macOS')]
12971265
$Distribution
12981266
)
12991267

13001268
End {
13011269
# These should match those in the Dockerfiles, but exclude tools like Git, which, and curl
13021270
$Dependencies = @()
1303-
if ($Environment.IsDebianFamily) {
1271+
if ($Distribution -eq 'deb') {
13041272
$Dependencies = @(
13051273
"libc6",
13061274
"libgcc1",
@@ -1311,16 +1279,11 @@ function Get-PackageDependencies
13111279
"libssl1.1|libssl1.0.2|libssl1.0.0"
13121280
)
13131281

1314-
} elseif ($Environment.IsRedHatFamily) {
1282+
} elseif ($Distribution -eq 'rh') {
13151283
$Dependencies = @(
13161284
"openssl-libs",
13171285
"libicu"
13181286
)
1319-
} elseif ($Environment.IsSUSEFamily) {
1320-
$Dependencies = @(
1321-
"libopenssl1_0_0",
1322-
"libicu"
1323-
)
13241287
}
13251288

13261289
return $Dependencies
@@ -1362,22 +1325,26 @@ function New-AfterScripts
13621325

13631326
[Parameter(Mandatory)]
13641327
[string]
1365-
$Distribution
1328+
$Distribution,
1329+
1330+
[Parameter(Mandatory)]
1331+
[string]
1332+
$Destination
13661333
)
13671334

13681335
Write-Verbose -Message "AfterScript Distribution: $Distribution" -Verbose
13691336

13701337
if ($Environment.IsRedHatFamily) {
13711338
$AfterInstallScript = [io.path]::GetTempFileName()
13721339
$AfterRemoveScript = [io.path]::GetTempFileName()
1373-
$packagingStrings.RedHatAfterInstallScript -f "$Link" | Out-File -FilePath $AfterInstallScript -Encoding ascii
1374-
$packagingStrings.RedHatAfterRemoveScript -f "$Link" | Out-File -FilePath $AfterRemoveScript -Encoding ascii
1340+
$packagingStrings.RedHatAfterInstallScript -f "$Link", $Destination | Out-File -FilePath $AfterInstallScript -Encoding ascii
1341+
$packagingStrings.RedHatAfterRemoveScript -f "$Link", $Destination | Out-File -FilePath $AfterRemoveScript -Encoding ascii
13751342
}
13761343
elseif ($Environment.IsDebianFamily -or $Environment.IsSUSEFamily) {
13771344
$AfterInstallScript = [io.path]::GetTempFileName()
13781345
$AfterRemoveScript = [io.path]::GetTempFileName()
1379-
$packagingStrings.UbuntuAfterInstallScript -f "$Link" | Out-File -FilePath $AfterInstallScript -Encoding ascii
1380-
$packagingStrings.UbuntuAfterRemoveScript -f "$Link" | Out-File -FilePath $AfterRemoveScript -Encoding ascii
1346+
$packagingStrings.UbuntuAfterInstallScript -f "$Link", $Destination | Out-File -FilePath $AfterInstallScript -Encoding ascii
1347+
$packagingStrings.UbuntuAfterRemoveScript -f "$Link", $Destination | Out-File -FilePath $AfterRemoveScript -Encoding ascii
13811348
}
13821349
elseif ($Environment.IsMacOS) {
13831350
# NOTE: The macos pkgutil doesn't support uninstall actions so we did not implement it.
@@ -1392,60 +1359,6 @@ function New-AfterScripts
13921359
}
13931360
}
13941361

1395-
function New-PSSymbolicLinks
1396-
{
1397-
param(
1398-
[Parameter(Mandatory)]
1399-
[string]
1400-
$Distribution,
1401-
1402-
[Parameter(Mandatory)]
1403-
[string]
1404-
$Staging
1405-
)
1406-
1407-
Write-Verbose -Message "PSSymLinks-Distribution: $Distribution" -Verbose
1408-
1409-
if ($Environment.IsRedHatFamily) {
1410-
switch -regex ($Distribution)
1411-
{
1412-
# add two symbolic links to system shared libraries that libmi.so is dependent on to handle
1413-
# platform specific changes. This is the only set of platforms needed for this currently
1414-
# as Ubuntu has these specific library files in the platform and macOS builds for itself
1415-
# against the correct versions.
1416-
'centos\.8' {
1417-
New-Item -Force -ItemType SymbolicLink -Target "/lib64/libssl.so.1.1" -Path "$Staging/libssl.so.1.0.0" > $null
1418-
New-Item -Force -ItemType SymbolicLink -Target "/lib64/libcrypto.so.1.1.1" -Path "$Staging/libcrypto.so.1.0.0" > $null
1419-
}
1420-
default {
1421-
New-Item -Force -ItemType SymbolicLink -Target "/lib64/libssl.so.10" -Path "$Staging/libssl.so.1.0.0" > $null
1422-
New-Item -Force -ItemType SymbolicLink -Target "/lib64/libcrypto.so.10" -Path "$Staging/libcrypto.so.1.0.0" > $null
1423-
}
1424-
}
1425-
}
1426-
elseif ($Environment.IsDebianFamily -or $Environment.IsSUSEFamily) {
1427-
switch -regex ($Distribution)
1428-
{
1429-
# add two symbolic links to system shared libraries that libmi.so is dependent on to handle
1430-
# platform specific changes. This appears to be a change in Debian 9; Debian 8 did not need these
1431-
# symlinks.
1432-
'debian\.9' {
1433-
New-Item -Force -ItemType SymbolicLink -Target "/usr/lib/x86_64-linux-gnu/libssl.so.1.0.2" -Path "$Staging/libssl.so.1.0.0" > $null
1434-
New-Item -Force -ItemType SymbolicLink -Target "/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2" -Path "$Staging/libcrypto.so.1.0.0" > $null
1435-
}
1436-
'debian\.(10|11)' {
1437-
New-Item -Force -ItemType SymbolicLink -Target "/usr/lib/x86_64-linux-gnu/libssl.so.1.1" -Path "$Staging/libssl.so.1.0.0" > $null
1438-
New-Item -Force -ItemType SymbolicLink -Target "/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1" -Path "$Staging/libcrypto.so.1.0.0" > $null
1439-
}
1440-
default {
1441-
# Default to old behavior before this change
1442-
New-Item -Force -ItemType SymbolicLink -Target "/lib64/libssl.so.10" -Path "$Staging/libssl.so.1.0.0" > $null
1443-
New-Item -Force -ItemType SymbolicLink -Target "/lib64/libcrypto.so.10" -Path "$Staging/libcrypto.so.1.0.0" > $null
1444-
}
1445-
}
1446-
}
1447-
}
1448-
14491362
function New-ManGzip
14501363
{
14511364
param(

0 commit comments

Comments
 (0)