diff --git a/tools/packaging/macos/launcher/ROOT/Applications/PowerShell.app/Contents/Info.plist b/tools/packaging/macos/launcher/ROOT/Applications/PowerShell.app/Contents/Info.plist deleted file mode 100644 index 42a5ce3fa37..00000000000 --- a/tools/packaging/macos/launcher/ROOT/Applications/PowerShell.app/Contents/Info.plist +++ /dev/null @@ -1,28 +0,0 @@ - - - - - CFBundleExecutable - PowerShell.sh - CFBundleGetInfoString - - CFBundleIconFile - - CFBundleIdentifier - - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - PowerShell - CFBundlePackageType - APPL - CFBundleShortVersionString - - CFBundleSupportedPlatforms - - MacOSX - - CFBundleVersion - - - diff --git a/tools/packaging/macos/launcher/ROOT/Applications/PowerShell.app/Contents/MacOS/PowerShell.sh b/tools/packaging/macos/launcher/ROOT/Applications/PowerShell.app/Contents/MacOS/PowerShell.sh deleted file mode 100755 index d20a8780b4a..00000000000 --- a/tools/packaging/macos/launcher/ROOT/Applications/PowerShell.app/Contents/MacOS/PowerShell.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -open /usr/local/bin/pwsh diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 3ab3da7abf8..de9e01e2987 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -1165,6 +1165,7 @@ function Get-MacOSPackageId } } +# Dynamically build macOS launcher application. function New-MacOSLauncher { param( @@ -1175,38 +1176,33 @@ function New-MacOSLauncher $IsPreview = Test-IsPreview -Version $Version $packageId = Get-MacOSPackageId -IsPreview:$IsPreview - # Define folder for launch application. - $macosapp = "$PSScriptRoot/macos/launcher/ROOT/Applications/Powershell.app" + # Define folder for launcher application. + $suffix = if ($IsPreview) { "-preview" } + $macosapp = "$PSScriptRoot/macos/launcher/ROOT/Applications/PowerShell$suffix.app" - # Update icns file. + # Create folder structure for launcher application. + New-Item -Force -ItemType Directory -Path "$macosapp/Contents/MacOS" | Out-Null + New-Item -Force -ItemType Directory -Path "$macosapp/Contents/Resources" | Out-Null + + # Define icns file information. $iconfile = "$PSScriptRoot/../../assets/Powershell.icns" $iconfilebase = (Get-Item -Path $iconfile).BaseName - # Create Resources folder, ignore error if exists. - New-Item -Force -ItemType Directory -Path "$macosapp/Contents/Resources" | Out-Null + # Copy icns file. Copy-Item -Force -Path $iconfile -Destination "$macosapp/Contents/Resources" - # Set values in plist. + # Create plist file. $plist = "$macosapp/Contents/Info.plist" - Start-NativeExecution { - defaults write $plist CFBundleIdentifier $packageId - defaults write $plist CFBundleVersion $Version - defaults write $plist CFBundleShortVersionString $Version - defaults write $plist CFBundleGetInfoString $Version - defaults write $plist CFBundleIconFile $iconfilebase - } - - # Convert to XML plist, needed because defaults native - # app auto converts it to binary format when it modify - # the plist file. - Start-NativeExecution { - plutil -convert xml1 $plist - } + $plistcontent = $packagingStrings.MacOSLauncherPlistTemplate -f $packageId, $Version, $iconfilebase + $plistcontent | Out-File -Force -Path $plist -Encoding utf8 - # Set permissions for plist and shell script. Note that - # defaults native app sets 700 when writing to the plist - # file from above. Both of these will be reset post fpm. + # Create shell script. + $executablepath = if ($IsPreview) { "/usr/local/bin/pwsh-preview" } else { "/usr/local/bin/pwsh" } $shellscript = "$macosapp/Contents/MacOS/PowerShell.sh" + $shellscriptcontent = $packagingStrings.MacOSLauncherScript -f $executablepath + $shellscriptcontent | Out-File -Force -Path $shellscript -Encoding utf8 + + # Set permissions for plist and shell script. Start-NativeExecution { chmod 644 $plist chmod 755 $shellscript @@ -1224,20 +1220,10 @@ function Clear-MacOSLauncher # the launcher app in the build structure and updating # it which locks out subsequent package builds due to # increase permissions. - $macosapp = "$PSScriptRoot/macos/launcher/ROOT/Applications/Powershell.app" - $plist = "$macosapp/Contents/Info.plist" - $tempguid = (New-Guid).Guid - Start-NativeExecution { - defaults write $plist CFBundleIdentifier $tempguid - plutil -convert xml1 $plist - } - # Restore default permissions. - $shellscript = "$macosapp/Contents/MacOS/PowerShell.sh" - Start-NativeExecution { - chmod 644 $shellscript - chmod 644 $plist - } + # Remove launcher application. + $macosfolder = "$PSScriptRoot/macos" + Remove-Item -Force -Recurse -Path $macosfolder } function New-StagingFolder diff --git a/tools/packaging/packaging.strings.psd1 b/tools/packaging/packaging.strings.psd1 index f120b88f14f..f69c44dcf73 100644 --- a/tools/packaging/packaging.strings.psd1 +++ b/tools/packaging/packaging.strings.psd1 @@ -47,6 +47,40 @@ case "$1" in remove-shell "{0}" ;; esac +'@ + MacOSLauncherScript = @' +#!/usr/bin/env bash +open {0} +'@ +MacOSLauncherPlistTemplate = @' + + + + + CFBundleExecutable + PowerShell.sh + CFBundleGetInfoString + {1} + CFBundleIconFile + {2} + CFBundleIdentifier + {0} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + PowerShell + CFBundlePackageType + APPL + CFBundleShortVersionString + {1} + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + {1} + + '@ # see https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html OsxDistributionTemplate = @'