@@ -504,6 +504,29 @@ function Start-PSPackage {
504
504
}
505
505
}
506
506
}
507
+ ' osxpkg' {
508
+ $HostArchitecture = " x86_64"
509
+ if ($MacOSRuntime -match " -arm64" ) {
510
+ $HostArchitecture = " arm64"
511
+ }
512
+ Write-Verbose " HostArchitecture = $HostArchitecture " - Verbose
513
+
514
+ $Arguments = @ {
515
+ Type = ' osxpkg'
516
+ PackageSourcePath = $Source
517
+ Name = $Name
518
+ Version = $Version
519
+ Force = $Force
520
+ NoSudo = $NoSudo
521
+ LTS = $LTS
522
+ HostArchitecture = $HostArchitecture
523
+ }
524
+
525
+
526
+ if ($PSCmdlet.ShouldProcess (" Create macOS Package" )) {
527
+ New-UnixPackage @Arguments
528
+ }
529
+ }
507
530
default {
508
531
$Arguments = @ {
509
532
Type = $_
@@ -803,6 +826,19 @@ function New-UnixPackage {
803
826
$Dict = New-Object " System.Management.Automation.RuntimeDefinedParameterDictionary"
804
827
$Dict.Add (" Distribution" , $Parameter ) > $null
805
828
return $Dict
829
+ } elseif ($Type -eq " osxpkg" ) {
830
+ # Add a dynamic parameter '-HostArchitecture' when the specified package type is 'osxpkg'.
831
+ # The '-HostArchitecture' parameter is used to indicate which Mac processor this package is targeting,
832
+ # Intel (x86_64) or Apple Silicon (arm64).
833
+ $ParameterAttr = New-Object " System.Management.Automation.ParameterAttribute"
834
+ $ValidateSetAttr = New-Object " System.Management.Automation.ValidateSetAttribute" - ArgumentList " x86_64" , " arm64"
835
+ $Attributes = New-Object " System.Collections.ObjectModel.Collection`` 1[System.Attribute]"
836
+ $Attributes.Add ($ParameterAttr ) > $null
837
+ $Attributes.Add ($ValidateSetAttr ) > $null
838
+ $Parameter = New-Object " System.Management.Automation.RuntimeDefinedParameter" - ArgumentList (" HostArchitecture" , [string ], $Attributes )
839
+ $Dict = New-Object " System.Management.Automation.RuntimeDefinedParameterDictionary"
840
+ $Dict.Add (" HostArchitecture" , $Parameter ) > $null
841
+ return $Dict
806
842
}
807
843
}
808
844
@@ -856,6 +892,7 @@ function New-UnixPackage {
856
892
throw ($ErrorMessage -f " macOS" )
857
893
}
858
894
895
+ $HostArchitecture = $PSBoundParameters [' HostArchitecture' ]
859
896
$DebDistro = ' macOS'
860
897
}
861
898
}
@@ -1013,7 +1050,7 @@ function New-UnixPackage {
1013
1050
if ($Environment.IsMacOS ) {
1014
1051
if ($PSCmdlet.ShouldProcess (" Add distribution information and Fix PackageName" ))
1015
1052
{
1016
- $createdPackage = New-MacOsDistributionPackage - FpmPackage $createdPackage - IsPreview:$IsPreview
1053
+ $createdPackage = New-MacOsDistributionPackage - FpmPackage $createdPackage - HostArchitecture $HostArchitecture - IsPreview:$IsPreview
1017
1054
}
1018
1055
}
1019
1056
@@ -1063,6 +1100,11 @@ function New-MacOsDistributionPackage
1063
1100
param (
1064
1101
[Parameter (Mandatory , HelpMessage = ' The FileInfo of the file created by FPM' )]
1065
1102
[System.IO.FileInfo ]$FpmPackage ,
1103
+
1104
+ [Parameter (HelpMessage = ' x86_64 for Intel or arm64 for Apple Silicon' )]
1105
+ [ValidateSet (" x86_64" , " arm64" )]
1106
+ [string ] $HostArchitecture = " x86_64" ,
1107
+
1066
1108
[Switch ] $IsPreview
1067
1109
)
1068
1110
@@ -1112,7 +1154,8 @@ function New-MacOsDistributionPackage
1112
1154
# 2 - package path
1113
1155
# 3 - minimum os version
1114
1156
# 4 - Package Identifier
1115
- $PackagingStrings.OsxDistributionTemplate -f " PowerShell - $packageVersion " , $packageVersion , $packageName , ' 10.14' , $packageId | Out-File - Encoding ascii - FilePath $distributionXmlPath - Force
1157
+ # 5 - host architecture (x86_64 for Intel or arm64 for Apple Silicon)
1158
+ $PackagingStrings.OsxDistributionTemplate -f " PowerShell - $packageVersion " , $packageVersion , $packageName , ' 10.14' , $packageId , $HostArchitecture | Out-File - Encoding ascii - FilePath $distributionXmlPath - Force
1116
1159
1117
1160
Write-Log " Applying distribution.xml to package..."
1118
1161
Push-Location $tempDir
0 commit comments