Skip to content

Commit c0aac11

Browse files
committed
Enable side-by-side Unix packages
1 parent 5235fed commit c0aac11

2 files changed

Lines changed: 56 additions & 16 deletions

File tree

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
bin/
22
obj/
3-
debug/
4-
Packages/
53
project.lock.json
64
*-tests.xml
5+
/debug/
6+
/staging/
7+
/Packages/
78

89
# dotnet cli install/uninstall scripts
910
dotnet-install.ps1
@@ -44,8 +45,7 @@ powershell.version
4445
/nuget-artifacts
4546

4647
# generated man files
47-
/assets/powershell.1
48-
/assets/powershell.1.gz
48+
/assets/powershell.1*
4949

5050
# resgen output
5151
gen

build.psm1

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ function Start-PSPackage {
816816
[string]$Version,
817817

818818
# Package name
819+
[ValidatePattern("^powershell")]
819820
[string]$Name = "powershell",
820821

821822
# Ubuntu, CentOS, and OS X, and Windows packages are supported
@@ -828,6 +829,8 @@ function Start-PSPackage {
828829
$Version = (git --git-dir="$PSScriptRoot/.git" describe) -Replace '^v'
829830
}
830831

832+
Write-Warning "Please ensure you have previously run Start-PSBuild -Clean -CrossGen!"
833+
831834
$Source = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish))
832835
Write-Verbose "Packaging $Source"
833836

@@ -891,7 +894,9 @@ function New-UnixPackage {
891894
[Parameter(Mandatory)]
892895
[string]$Source,
893896

897+
# Must start with 'powershell' but may have any suffix
894898
[Parameter(Mandatory)]
899+
[ValidatePattern("^powershell")]
895900
[string]$Name,
896901

897902
[Parameter(Mandatory)]
@@ -912,11 +917,38 @@ PowerShell is an automation and configuration management platform.
912917
It consists of a cross-platform command-line shell and associated scripting language.
913918
"@
914919

920+
# Suffix is used for side-by-side package installation
921+
$Suffix = $Name -replace "^powershell"
922+
if (!$Suffix) {
923+
Write-Warning "Suffix not given, building primary PowerShell package!"
924+
$Suffix = $Version
925+
}
926+
927+
# Setup staging directory so we don't change the original source directory
928+
$Staging = "$PSScriptRoot/staging"
929+
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $Staging
930+
Copy-Item -Recurse $Source $Staging
931+
932+
# Rename files to given name if not "powershell"
933+
if ($Name -ne "powershell") {
934+
$Files = @("powershell",
935+
"powershell.dll",
936+
"powershell.deps.json",
937+
"powershell.pdb",
938+
"powershell.runtimeconfig.json",
939+
"powershell.xml")
940+
941+
foreach ($File in $Files) {
942+
$NewName = $File -replace "^powershell", $Name
943+
Move-Item "$Staging/$File" "$Staging/$NewName"
944+
}
945+
}
946+
915947
# Follow the Filesystem Hierarchy Standard for Linux and OS X
916948
$Destination = if ($IsLinux) {
917-
"/opt/microsoft/powershell"
949+
"/opt/microsoft/powershell/$Suffix"
918950
} elseif ($IsOSX) {
919-
"/usr/local/microsoft/powershell"
951+
"/usr/local/microsoft/powershell/$Suffix"
920952
}
921953

922954
# Destination for symlink to powershell executable
@@ -926,13 +958,13 @@ It consists of a cross-platform command-line shell and associated scripting lang
926958
"/usr/local/bin"
927959
}
928960

929-
New-Item -Force -ItemType SymbolicLink -Path /tmp/powershell -Target $Destination/powershell >$null
961+
New-Item -Force -ItemType SymbolicLink -Path "/tmp/$Name" -Target "$Destination/$Name" >$null
930962

931963
# there is a weird bug in fpm
932964
# if the target of the powershell symlink exists, `fpm` aborts
933965
# with a `utime` error on OS X.
934966
# so we move it to make symlink broken
935-
$symlink_dest = "$Destination/powershell"
967+
$symlink_dest = "$Destination/$Name"
936968
$hack_dest = "./_fpm_symlink_hack_powershell"
937969
if ($IsOSX) {
938970
if (Test-Path $symlink_dest) {
@@ -942,19 +974,27 @@ It consists of a cross-platform command-line shell and associated scripting lang
942974
}
943975

944976
# run ronn to convert man page to roff
945-
$RoffFile = Join-Path $PSScriptRoot "/assets/powershell.1"
946-
$RonnFile = "$RoffFile.ronn"
947-
$GzipFile = "$RoffFile.gz"
948-
$ManFile = Join-Path "/usr/local/share/man/man1" (Split-Path -Leaf $GzipFile)
977+
$RonnFile = Join-Path $PSScriptRoot "/assets/powershell.1.ronn"
978+
$RoffFile = $RonnFile -replace "\.ronn$"
949979

950980
# Run ronn on assets file
981+
# Run does not play well with files named powershell6.0.1, so we generate and then rename
951982
Start-NativeExecution { ronn --roff $RonnFile }
952983

984+
# Setup for side-by-side man pages (noop if primary package)
985+
$FixedRoffFile = $RoffFile -replace "powershell.1$", "$Name.1"
986+
if ($Name -ne "powershell") {
987+
Move-Item $RoffFile $FixedRoffFile
988+
}
989+
953990
# gzip in assets directory
954-
Start-NativeExecution { gzip -f $RoffFile }
991+
$GzipFile = "$FixedRoffFile.gz"
992+
Start-NativeExecution { gzip -f $FixedRoffFile }
993+
994+
$ManFile = Join-Path "/usr/local/share/man/man1" (Split-Path -Leaf $GzipFile)
955995

956996
# Change permissions for packaging
957-
Start-NativeExecution { chmod -R go=u $Source $GzipFile }
997+
Start-NativeExecution { chmod -R go=u $Staging $GzipFile }
958998

959999
$libunwind = switch ($Type) {
9601000
"deb" { "libunwind8" }
@@ -985,9 +1025,9 @@ It consists of a cross-platform command-line shell and associated scripting lang
9851025
"--deb-build-depends", "g++",
9861026
"-t", $Type,
9871027
"-s", "dir",
988-
"$Source/=$Destination/",
1028+
"$Staging/=$Destination/",
9891029
"$GzipFile=$ManFile",
990-
"/tmp/powershell=$Link"
1030+
"/tmp/$Name=$Link"
9911031
)
9921032

9931033
# Build package

0 commit comments

Comments
 (0)