make macOS package use a consistent path (#7006)

Address mac portions of PowerShell/PowerShell-RFC#115 (comment)

Make path when stable /usr/local/microsoft/powershell/6
when not stable (preview) /usr/local/microsoft/powershell/6-preview and symlink name pwsh-preview
allow side-by-side install of stable and preview
Also:

fix an issue where the utime work around for mac requires sudo
refactor some code into common functions
This commit is contained in:
Travis Plunk
2018-06-06 10:28:22 -07:00
committed by GitHub
parent 92cb949cac
commit cecdd1ef80
2 changed files with 68 additions and 14 deletions
+65 -11
View File
@@ -32,7 +32,9 @@ function Start-PSPackage {
[Switch] $Force,
[Switch] $SkipReleaseChecks
[Switch] $SkipReleaseChecks,
[switch] $NoSudo
)
DynamicParam {
@@ -318,6 +320,7 @@ function Start-PSPackage {
Name = $Name
Version = $Version
Force = $Force
NoSudo = $NoSudo
}
foreach ($Distro in $Script:DebianDistributions) {
$Arguments["Distribution"] = $Distro
@@ -333,6 +336,7 @@ function Start-PSPackage {
Name = $Name
Version = $Version
Force = $Force
NoSudo = $NoSudo
}
if ($PSCmdlet.ShouldProcess("Create $_ Package")) {
@@ -534,7 +538,10 @@ function New-UnixPackage {
[string]$Iteration = "1",
[Switch]
$Force
$Force,
[switch]
$NoSudo
)
DynamicParam {
@@ -555,6 +562,10 @@ function New-UnixPackage {
}
End {
# This allows sudo install to be optional; needed when running in containers / as root
# Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly
$sudo = if (!$NoSudo) { "sudo" }
# Validate platform
$ErrorMessage = "Must be on {0} to build '$Type' packages!"
switch ($Type) {
@@ -601,7 +612,7 @@ function New-UnixPackage {
}
# Determine if the version is a preview version
$IsPreview = $Version.Contains("-preview")
$IsPreview = Test-IsPreview -Version $Version
# Preview versions have preview in the name
$Name = if ($IsPreview) { "powershell-preview" } else { "powershell" }
@@ -655,7 +666,7 @@ function New-UnixPackage {
if ($Environment.IsMacOS) {
if (Test-Path $symlink_dest) {
Write-Warning "Move $symlink_dest to $hack_dest (fpm utime bug)"
Move-Item $symlink_dest $hack_dest
Start-NativeExecution ([ScriptBlock]::Create("$sudo mv $symlink_dest $hack_dest"))
}
}
@@ -723,7 +734,7 @@ function New-UnixPackage {
# this is continuation of a fpm hack for a weird bug
if (Test-Path $hack_dest) {
Write-Warning "Move $hack_dest to $symlink_dest (fpm utime bug)"
Move-Item $hack_dest $symlink_dest
Start-NativeExecution ([ScriptBlock]::Create("$sudo mv $hack_dest $symlink_dest"))
}
}
if ($AfterScriptInfo.AfterInstallScript) {
@@ -741,7 +752,7 @@ function New-UnixPackage {
if ($Environment.IsMacOS) {
if ($pscmdlet.ShouldProcess("Add distribution information and Fix PackageName"))
{
$createdPackage = New-MacOsDistributionPackage -FpmPackage $createdPackage
$createdPackage = New-MacOsDistributionPackage -FpmPackage $createdPackage -IsPreview:$IsPreview
}
}
@@ -761,7 +772,8 @@ function New-MacOsDistributionPackage
{
param(
[Parameter(Mandatory,HelpMessage='The FileInfo of the file created by FPM')]
[System.IO.FileInfo]$FpmPackage
[System.IO.FileInfo]$FpmPackage,
[Switch] $IsPreview
)
if(!$Environment.IsMacOS)
@@ -800,12 +812,15 @@ function New-MacOsDistributionPackage
# Create the distribution xml
$distributionXmlPath = Join-Path -Path $tempDir -ChildPath 'powershellDistribution.xml'
$packageId = Get-MacOSPackageId -IsPreview:$IsPreview.IsPresent
# format distribution template with:
# 0 - title
# 1 - version
# 2 - package path
# 2 - minimum os version
$PackagingStrings.OsxDistributionTemplate -f "PowerShell - $packageVersion", $packageVersion, $packageName, '10.12' | Out-File -Encoding ascii -FilePath $distributionXmlPath -Force
# 3 - minimum os version
# 4 - Package Identifier
$PackagingStrings.OsxDistributionTemplate -f "PowerShell - $packageVersion", $packageVersion, $packageName, '10.12', $packageId | Out-File -Encoding ascii -FilePath $distributionXmlPath -Force
Write-Log "Applying distribution.xml to package..."
Push-Location $tempDir
@@ -1086,6 +1101,24 @@ function New-ManGzip
ManFile = $ManFile
}
}
# Returns the macOS Package Identifier
function Get-MacOSPackageId
{
param(
[switch]
$IsPreview
)
if($IsPreview.IsPresent)
{
return 'com.microsoft.powershell-preview'
}
else
{
return 'com.microsoft.powershell'
}
}
function New-MacOSLauncher
{
param(
@@ -1093,6 +1126,9 @@ function New-MacOSLauncher
[String]$Version
)
$IsPreview = Test-IsPreview -Version $Version
$packageId = Get-MacOSPackageId -IsPreview:$IsPreview
# Define folder for launch application.
$macosapp = "$PSScriptRoot/macos/launcher/ROOT/Applications/Powershell.app"
@@ -1107,7 +1143,7 @@ function New-MacOSLauncher
# Set values in plist.
$plist = "$macosapp/Contents/Info.plist"
Start-NativeExecution {
defaults write $plist CFBundleIdentifier com.microsoft.powershell
defaults write $plist CFBundleIdentifier $packageId
defaults write $plist CFBundleVersion $Version
defaults write $plist CFBundleShortVersionString $Version
defaults write $plist CFBundleGetInfoString $Version
@@ -2212,6 +2248,24 @@ function New-MSIPatch
Remove-Item -Path $filesToCleanup -Force -Recurse -ErrorAction SilentlyContinue
}
<#
.Synopsis
Tests if a version is preview
.EXAMPLE
Test-IsPreview -version '6.1.0-sometthing' # returns true
Test-IsPreview -version '6.1.0' # returns false
#>
function Test-IsPreview
{
param(
[parameter(Mandatory)]
[string]
$Version
)
return $Version -like '*-*'
}
<#
.Synopsis
Creates a Windows installer MSI package and assumes that the binaries are already built using 'Start-PSBuild'.
@@ -2283,7 +2337,7 @@ function New-MSIPackage
$ProductSemanticVersion = Get-PackageSemanticVersion -Version $ProductVersion
$simpleProductVersion = '6'
$isPreview = $ProductSemanticVersion -like '*-*'
$isPreview = Test-IsPreview -Version $ProductSemanticVersion
if($isPreview)
{
$simpleProductVersion += '-preview'
+3 -3
View File
@@ -60,7 +60,7 @@ OsxDistributionTemplate = @'
<os-version min="{3}" />
</allowed-os-versions>
<options customize="never" require-scripts="false"/>
<product id="com.microsoft.powershell" version="{1}" />
<product id="{4}" version="{1}" />
<choices-outline>
<line choice="default">
<line choice="powershell"/>
@@ -68,9 +68,9 @@ OsxDistributionTemplate = @'
</choices-outline>
<choice id="default"/>
<choice id="powershell" visible="false">
<pkg-ref id="com.microsoft.powershell"/>
<pkg-ref id="{4}"/>
</choice>
<pkg-ref id="com.microsoft.powershell" version="{1}" onConclusion="none">{2}</pkg-ref>
<pkg-ref id="{4}" version="{1}" onConclusion="none">{2}</pkg-ref>
</installer-gui-script>
'@
NuspecTemplate = @'