Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

58 changes: 22 additions & 36 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ function Get-MacOSPackageId
}
}

# Dynamically build macOS launcher application.
function New-MacOSLauncher
{
param(
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget to include this change to the strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been corrected.

$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
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tools/packaging/packaging.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ case "$1" in
remove-shell "{0}"
;;
esac
'@
MacOSLauncherScript = @'
#!/usr/bin/env bash
open {0}
'@
MacOSLauncherPlistTemplate = @'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>PowerShell.sh</string>
<key>CFBundleGetInfoString</key>
<string>{1}</string>
<key>CFBundleIconFile</key>
<string>{2}</string>
<key>CFBundleIdentifier</key>
<string>{0}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>PowerShell</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>{1}</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>{1}</string>
</dict>
</plist>
'@
# see https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html
OsxDistributionTemplate = @'
Expand Down