GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — PowerShell/tools/packaging/packaging.psm1 at master · PowerShell/PowerShell Expand file tree/ Copy pathpackaging.psm1More file actions 4651 lines (3896 loc) · 171 KB / Copy pathpackaging.psm1File metadata and controls4651 lines (3896 loc) · 171 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. . "$PSScriptRoot\..\buildCommon\startNativeExecution.ps1" $Environment = Get-EnvironmentInformation $RepoRoot = (Resolve-Path -Path "$PSScriptRoot/../..").Path $packagingStrings = Import-PowerShellDataFile "$PSScriptRoot\packaging.strings.psd1" Import-Module "$PSScriptRoot\..\Xml" -ErrorAction Stop -Force $DebianDistributions = @("deb") $RedhatFullDistributions = @("rh") $RedhatFddDistributions = @("cm", "azl4") $RedhatDistributions = @() $RedhatDistributions += $RedhatFullDistributions $RedhatDistributions += $RedhatFddDistributions $AllDistributions = @() $AllDistributions += $DebianDistributions $AllDistributions += $RedhatDistributions $AllDistributions += 'macOs' $script:netCoreRuntime = 'net11.0' $script:iconFileName = "Powershell_black_64.png" $script:iconPath = Join-Path -path $PSScriptRoot -ChildPath "../../assets/$iconFileName" -Resolve class R2RVerification { [ValidateSet('NoR2R','R2R','SdkOnly')] [string] $R2RState = 'R2R' [System.Reflection.PortableExecutable.Machine] $Architecture = [System.Reflection.PortableExecutable.Machine]::Amd64 [ValidateSet('Linux','Apple','Windows')] [string] $OperatingSystem = 'Windows' } function Start-PSPackage { [CmdletBinding(DefaultParameterSetName='Version',SupportsShouldProcess=$true)] param( # PowerShell packages use Semantic Versioning https://semver.org/ [Parameter(ParameterSetName = "Version")] [string]$Version, [Parameter(ParameterSetName = "ReleaseTag")] [ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d{1,2})?)?$")] [ValidateNotNullOrEmpty()] [string]$ReleaseTag, # Package name [ValidatePattern("^powershell")] [string]$Name = "powershell", # Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported [ValidateSet("msix", "deb", "deb-arm64", "osxpkg", "rpm", "rpm-fxdependent", "rpm-fxdependent-arm64", "zip", "zip-pdb", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent", "fxdependent-win-desktop", "min-size-x64", "min-size-arm64", "tar-alpine-fxdependent")] [string[]]$Type, # Generate windows downlevel package [ValidateSet("win7-x86", "win7-x64", "win-arm", "win-arm64")] [string] $WindowsRuntime, [ValidateSet('osx-x64', 'osx-arm64')] [ValidateScript({$Environment.IsMacOS})] [string] $MacOSRuntime, [string] $PackageBinPath, [switch] $Private, [Switch] $Force, [Switch] $SkipReleaseChecks, [switch] $NoSudo, [switch] $LTS ) # Runtime and Configuration settings required by the package ($Runtime, $Configuration) = if ($WindowsRuntime) { $WindowsRuntime, "Release" } elseif ($MacOSRuntime) { $MacOSRuntime, "Release" } elseif ($Type.Count -eq 1 -and $Type[0] -eq "tar-alpine") { New-PSOptions -Configuration "Release" -Runtime "linux-musl-x64" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "tar-arm") { New-PSOptions -Configuration "Release" -Runtime "linux-arm" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "tar-arm64") { if ($IsMacOS) { New-PSOptions -Configuration "Release" -Runtime "osx-arm64" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } else { New-PSOptions -Configuration "Release" -Runtime "linux-arm64" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "rpm-fxdependent") { New-PSOptions -Configuration "Release" -Runtime 'fxdependent-linux-x64' -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "rpm-fxdependent-arm64") { New-PSOptions -Configuration "Release" -Runtime 'fxdependent-linux-arm64' -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "tar-alpine-fxdependent") { New-PSOptions -Configuration "Release" -Runtime 'fxdependent-noopt-linux-musl-x64' -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "deb-arm64") { New-PSOptions -Configuration "Release" -Runtime 'linux-arm64' -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } elseif ($Type.Count -eq 1 -and $Type[0] -eq "min-size-arm64") { $runtimeToUse = if ($IsMacOS) { "osx-arm64" } elseif ($IsLinux) { "linux-arm64" } else { "win-arm64" } New-PSOptions -Configuration "Release" -Runtime $runtimeToUse -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } else { New-PSOptions -Configuration "Release" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } if ($Environment.IsWindows) { # Runtime will be one of win7-x64, win7-x86, "win-arm" and "win-arm64" on Windows. # Build the name suffix for universal win-plat packages. switch ($Runtime) { "win-arm64" { $NameSuffix = "win-arm64" } default { $NameSuffix = $_ -replace 'win\d+', 'win' } } } if ($Type -eq 'fxdependent') { $NameSuffix = "win-fxdependent" Write-Log "Packaging : '$Type'; Packaging Configuration: '$Configuration', Runtime: '$Runtime'" } elseif ($Type -eq 'fxdependent-win-desktop') { $NameSuffix = "win-fxdependentWinDesktop" Write-Log "Packaging : '$Type'; Packaging Configuration: '$Configuration', Runtime: '$Runtime'" } elseif ($MacOSRuntime) { $NameSuffix = $MacOSRuntime Write-Log "Packaging : '$Type'; Packaging Configuration: '$Configuration', Runtime: '$Runtime'" } else { Write-Log "Packaging RID: '$Runtime'; Packaging Configuration: '$Configuration'" } $Script:Options = Get-PSOptions $actualParams = @('-PSModuleRestore') # Require PSModuleRestore for packaging $PSModuleRestoreCorrect = $Script:Options.PSModuleRestore $precheckFailed = if ($Type -like 'fxdependent*' -or $Type -eq 'tar-alpine') { ## We do not check on runtime for framework dependent package. -not $Script:Options -or ## Start-PSBuild hasn't been executed yet -not $PSModuleRestoreCorrect -or ## Last build didn't specify '-PSModuleRestore' correctly $Script:Options.Configuration -ne $Configuration -or ## Last build was with configuration other than 'Release' $Script:Options.Framework -ne $script:netCoreRuntime ## Last build wasn't for CoreCLR } else { -not $Script:Options -or ## Start-PSBuild hasn't been executed yet -not $PSModuleRestoreCorrect -or ## Last build didn't specify '-PSModuleRestore' correctly $Script:Options.Runtime -ne $Runtime -or ## Last build wasn't for the required RID $Script:Options.Configuration -ne $Configuration -or ## Last build was with configuration other than 'Release' $Script:Options.Framework -ne $script:netCoreRuntime ## Last build wasn't for CoreCLR } # Make sure the most recent build satisfies the package requirement if ($precheckFailed) { # It's possible that the most recent build doesn't satisfy the package requirement but # an earlier build does. # It's also possible that the last build actually satisfies the package requirement but # then `Start-PSPackage` runs from a new PS session or `build.psm1` was reloaded. # # In these cases, the user will be asked to build again even though it's technically not # necessary. However, we want it that way -- being very explict when generating packages. # This check serves as a simple gate to ensure that the user knows what he is doing, and # also ensure `Start-PSPackage` does what the user asks/expects, because once packages # are generated, it'll be hard to verify if they were built from the correct content. Write-Warning -Message "Start-PSPackage: The build PreCheck has failed." if (-not $Script:Options) { Write-Warning -Message "Start-PSPackage: build options variable is null indicating Start-PSBuild hasn't been run yet." } if (-not $PSModuleRestoreCorrect) { Write-Warning -Message "Start-PSPackage: PSModuleRestoreCorrect variable is null indicating build -PSModuleRestore was not performed." } if ($Script:Options.Configuration -ne $Configuration) { Write-Warning -Message "Start-PSPackage: Build configuration is incorrect: Expected: $Configuration Actual: $($Script:Options.Configuration)" } if ($Script:Options.Framework -ne $script:netCoreRuntime) { Write-Warning -Message "Start-PSPackage: Build .NET version is incorrect: Expected: $($script:netCoreRuntime) Actual: $($Script:Options.Framework)" } if (($Type -notlike 'fxdependent*' -and $Type -ne 'tar-alpine') -and ($Script:Options.Runtime -ne $Runtime)) { Write-Warning -Message "Start-PSPackage: Build RID does not match expected RID: Expected: $Runtime Actual: $($Script:Options.Runtime)" } $params = @('-Clean', '-PSModuleRestore') $actualParams += '-Runtime ' + $Script:Options.Runtime if ($Type -eq 'fxdependent') { $params += '-Runtime', 'fxdependent' } elseif ($Type -eq 'fxdependent-win-desktop') { $params += '-Runtime', 'fxdependent-win-desktop' } else { $params += '-Runtime', $Runtime } $params += '-Configuration', $Configuration $actualParams += '-Configuration ' + $Script:Options.Configuration Write-Warning "Build started with unexpected parameters 'Start-PSBuild $actualParams" throw "Please ensure you have run 'Start-PSBuild $params'!" } if ($SkipReleaseChecks.IsPresent) { Write-Warning "Skipping release checks." } elseif (!$Script:Options.RootInfo.IsValid){ throw $Script:Options.RootInfo.Warning } # If ReleaseTag is specified, use the given tag to calculate Version if ($PSCmdlet.ParameterSetName -eq "ReleaseTag") { $Version = $ReleaseTag -Replace '^v' } # Use Git tag if not given a version if (-not $Version) { $Version = (git --git-dir="$RepoRoot/.git" describe) -Replace '^v' } $Source = if ($PackageBinPath) { $PackageBinPath } else { Split-Path -Path $Script:Options.Output -Parent } Write-Verbose -Verbose "Source: $Source" # Copy the ThirdPartyNotices.txt so it's part of the package Copy-Item "$RepoRoot/ThirdPartyNotices.txt" -Destination $Source -Force # Copy the default.help.txt so it's part of the package Copy-Item "$RepoRoot/assets/default.help.txt" -Destination "$Source/en-US" -Force if (-not $SkipGenerateReleaseFiles -and -not $env:TF_BUILD) { # Make sure psoptions.json file exists so appropriate files.wsx is generated $psOptionsPath = (Join-Path -Path $Source "psoptions.json") if (-not (Test-Path -Path $psOptionsPath)) { $createdOptionsFile = New-Item -Path $psOptionsPath -Force Write-Verbose -Verbose "Created psoptions file: $createdOptionsFile" } # Make sure _manifest\spdx_2.2\manifest.spdx.json file exists so appropriate files.wxs is generated $manifestSpdxPath = (Join-Path -Path $Source "_manifest\spdx_2.2\manifest.spdx.json") if (-not (Test-Path -Path $manifestSpdxPath)) { $createdSpdxPath = New-Item -Path $manifestSpdxPath -Force Write-Verbose -Verbose "Created manifest.spdx.json file: $createdSpdxPath" } $manifestSpdxPathSha = (Join-Path -Path $Source "_manifest\spdx_2.2\manifest.spdx.json.sha256") if (-not (Test-Path -Path $manifestSpdxPathSha)) { $createdSpdxPathSha = New-Item -Path $manifestSpdxPathSha -Force Write-Verbose -Verbose "Created manifest.spdx.json.sha256 file: $createdSpdxPathSha" } $bsiJsonPath = (Join-Path -Path $Source "_manifest\spdx_2.2\bsi.json") if (-not (Test-Path -Path $bsiJsonPath)) { $createdBsiJsonPath = New-Item -Path $bsiJsonPath -Force Write-Verbose -Verbose "Created bsi.json file: $createdBsiJsonPath" } $manifestCatPath = (Join-Path -Path $Source "_manifest\spdx_2.2\manifest.cat") if (-not (Test-Path -Path $manifestCatPath)) { $createdCatPath = New-Item -Path $manifestCatPath -Force Write-Verbose -Verbose "Created manifest.cat file: $createdCatPath" } } Write-Log "Packaging Source: '$Source'" # Decide package output type if (-not $Type) { $Type = if ($Environment.IsLinux) { if ($Environment.LinuxInfo.ID -match "ubuntu") { "deb", "tar" } elseif ($Environment.IsRedHatFamily) { "rpm" } elseif ($Environment.IsSUSEFamily) { "rpm" } else { throw "Building packages for $($Environment.LinuxInfo.PRETTY_NAME) is unsupported!" } } elseif ($Environment.IsMacOS) { "osxpkg", "tar" } elseif ($Environment.IsWindows) { "zip", "msix" } Write-Warning "-Type was not specified, continuing with $Type!" } Write-Log "Packaging Type: $Type" switch ($Type) { "zip" { $os, $architecture = ($Script:Options.Runtime -split '-') $peOS = ConvertTo-PEOperatingSystem -OperatingSystem $os $peArch = ConvertTo-PEArchitecture -Architecture $architecture $Arguments = @{ PackageNameSuffix = $NameSuffix PackageSourcePath = $Source PackageVersion = $Version Force = $Force } if ($architecture -in 'x86', 'x64', 'arm', 'arm64') { $Arguments += @{ R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = $peOS Architecture = $peArch } } } else { $Arguments += @{ R2RVerification = [R2RVerification]@{ R2RState = 'SdkOnly' OperatingSystem = $peOS Architecture = $peArch } } } if ($PSCmdlet.ShouldProcess("Create Zip Package")) { New-ZipPackage @Arguments } } "zip-pdb" { $Arguments = @{ PackageNameSuffix = $NameSuffix PackageSourcePath = $Source PackageVersion = $Version Force = $Force } if ($PSCmdlet.ShouldProcess("Create Symbols Zip Package")) { New-PdbZipPackage @Arguments } } { $_ -like "min-size*" } { # Add suffix '-gc' because this package is for the Guest Config team. if ($Environment.IsWindows) { $Arguments = @{ PackageNameSuffix = "$NameSuffix-gc" PackageSourcePath = $Source PackageVersion = $Version Force = $Force R2RVerification = [R2RVerification]@{ R2RState = 'SdkOnly' } } if ($PSCmdlet.ShouldProcess("Create min-size Zip Package")) { New-ZipPackage @Arguments } } elseif ($Environment.IsLinux) { $Arguments = @{ PackageSourcePath = $Source Name = $Name PackageNameSuffix = 'gc' Architecture = $Runtime.Split('-')[1] Version = $Version Force = $Force R2RVerification = [R2RVerification]@{ R2RState = 'SdkOnly' } } if ($PSCmdlet.ShouldProcess("Create min-size tar.gz Package")) { New-TarballPackage @Arguments } } else { throw "The 'min-size*' package types are supported only on Windows and Linux." } } { $_ -like "fxdependent*" } { if ($Environment.IsWindows) { $Arguments = @{ PackageNameSuffix = $NameSuffix PackageSourcePath = $Source PackageVersion = $Version Force = $Force R2RVerification = [R2RVerification]@{ R2RState = 'NoR2R' } } if ($PSCmdlet.ShouldProcess("Create Zip Package")) { New-ZipPackage @Arguments } } elseif ($Environment.IsLinux) { $Arguments = @{ PackageSourcePath = $Source Name = $Name PackageNameSuffix = 'fxdependent' Version = $Version Force = $Force R2RVerification = [R2RVerification]@{ R2RState = 'NoR2R' } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { New-TarballPackage @Arguments } } } "tar-alpine-fxdependent" { if ($Environment.IsLinux) { $Arguments = @{ PackageSourcePath = $Source Name = $Name PackageNameSuffix = 'musl-noopt-fxdependent' Version = $Version Force = $Force R2RVerification = [R2RVerification]@{ R2RState = 'NoR2R' OperatingSystem = "Linux" } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { New-TarballPackage @Arguments } } } "msix" { $Arguments = @{ ProductNameSuffix = $NameSuffix ProductSourcePath = $Source ProductVersion = $Version Architecture = $WindowsRuntime.Split('-')[1] Force = $Force Private = $Private LTS = $LTS } if ($PSCmdlet.ShouldProcess("Create MSIX Package")) { New-MSIXPackage @Arguments } } "tar" { $Arguments = @{ PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force } if ($MacOSRuntime) { $architecture = $MacOSRuntime.Split('-')[1] $Arguments['Architecture'] = $architecture } if ($Script:Options.Runtime -match '(linux|osx).*') { $os, $architecture = ($Script:Options.Runtime -split '-') $peOS = ConvertTo-PEOperatingSystem -OperatingSystem $os $peArch = ConvertTo-PEArchitecture -Architecture $architecture $Arguments['R2RVerification'] = [R2RVerification]@{ R2RState = "R2R" OperatingSystem = $peOS Architecture = $peArch } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { New-TarballPackage @Arguments } } "tar-arm" { $peArch = ConvertTo-PEArchitecture -Architecture 'arm' $Arguments = @{ PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force Architecture = "arm32" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = "Linux" Architecture = $peArch } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { New-TarballPackage @Arguments } } "tar-arm64" { $Arguments = @{ PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force Architecture = "arm64" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = "Linux" Architecture = "arm64" } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { New-TarballPackage @Arguments } } "tar-alpine" { $Arguments = @{ PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force Architecture = "musl-x64" ExcludeSymbolicLinks = $true R2RVerification = [R2RVerification]@{ R2RState = 'R2R' OperatingSystem = "Linux" Architecture = "amd64" } } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { New-TarballPackage @Arguments } } 'deb' { $Arguments = @{ Type = 'deb' PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = "amd64" } foreach ($Distro in $Script:DebianDistributions) { $Arguments["Distribution"] = $Distro if ($PSCmdlet.ShouldProcess("Create DEB Package for $Distro")) { New-UnixPackage @Arguments } } } 'deb-arm64' { $Arguments = @{ Type = 'deb' PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = "arm64" } foreach ($Distro in $Script:DebianDistributions) { $Arguments["Distribution"] = $Distro if ($PSCmdlet.ShouldProcess("Create DEB Package for $Distro")) { New-UnixPackage @Arguments } } } 'rpm' { $Arguments = @{ Type = 'rpm' PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = "x86_64" } foreach ($Distro in $Script:RedhatFullDistributions) { $Arguments["Distribution"] = $Distro if ($PSCmdlet.ShouldProcess("Create RPM Package for $Distro")) { Write-Verbose -Verbose "Creating RPM Package for $Distro" New-UnixPackage @Arguments } } } 'rpm-fxdependent' { $Arguments = @{ Type = 'rpm' PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = "x86_64" } foreach ($Distro in $Script:RedhatFddDistributions) { $Arguments["Distribution"] = $Distro if ($PSCmdlet.ShouldProcess("Create RPM Package for $Distro")) { Write-Verbose -Verbose "Creating RPM Package for $Distro" New-UnixPackage @Arguments } } } 'rpm-fxdependent-arm64' { $Arguments = @{ Type = 'rpm' PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = "aarch64" } foreach ($Distro in $Script:RedhatFddDistributions) { $Arguments["Distribution"] = $Distro if ($PSCmdlet.ShouldProcess("Create RPM Package for $Distro")) { Write-Verbose -Verbose "Creating RPM Package for $Distro" New-UnixPackage @Arguments } } } 'osxpkg' { $HostArchitecture = "x86_64" if ($MacOSRuntime -match "-arm64") { $HostArchitecture = "arm64" } Write-Verbose "HostArchitecture = $HostArchitecture" -Verbose $Arguments = @{ Type = 'osxpkg' PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = $HostArchitecture } if ($PSCmdlet.ShouldProcess("Create macOS Package")) { New-UnixPackage @Arguments } } default { $Arguments = @{ Type = $_ PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force NoSudo = $NoSudo LTS = $LTS HostArchitecture = "all" } if ($PSCmdlet.ShouldProcess("Create $_ Package")) { New-UnixPackage @Arguments } } } } function New-TarballPackage { [CmdletBinding(SupportsShouldProcess=$true)] param ( [Parameter(Mandatory)] [string] $PackageSourcePath, # Must start with 'powershell' but may have any suffix [Parameter(Mandatory)] [ValidatePattern("^powershell")] [string] $Name, # Suffix of the Name [string] $PackageNameSuffix, [Parameter(Mandatory)] [string] $Version, [Parameter()] [string] $Architecture = "x64", [switch] $Force, [switch] $ExcludeSymbolicLinks, [string] $CurrentLocation = (Get-Location), [R2RVerification] $R2RVerification ) if ($PackageNameSuffix) { $packageName = "$Name-$Version-{0}-$Architecture-$PackageNameSuffix.tar.gz" } else { $packageName = "$Name-$Version-{0}-$Architecture.tar.gz" } if ($Environment.IsWindows) { throw "Must be on Linux or macOS to build 'tar.gz' packages!" } elseif ($Environment.IsLinux) { $packageName = $packageName -f "linux" } elseif ($Environment.IsMacOS) { $packageName = $packageName -f "osx" } $packagePath = Join-Path -Path $CurrentLocation -ChildPath $packageName Write-Verbose "Create package $packageName" Write-Verbose "Package destination path: $packagePath" if (Test-Path -Path $packagePath) { if ($Force -or $PSCmdlet.ShouldProcess("Overwrite existing package file")) { Write-Verbose "Overwrite existing package file at $packagePath" -Verbose Remove-Item -Path $packagePath -Force -ErrorAction Stop -Confirm:$false } } $Staging = "$PSScriptRoot/staging" New-StagingFolder -StagingPath $Staging -PackageSourcePath $PackageSourcePath -R2RVerification $R2RVerification # Ensure PowerShell executable has correct permissions in tarball $pwshInStaging = Join-Path $Staging 'pwsh' if (Test-Path -LiteralPath $pwshInStaging) { Start-NativeExecution { chmod 755 $pwshInStaging } } # Included .NET executable for producing crash dumps $createdumpInStaging = Join-Path $Staging 'createdump' if (Test-Path -LiteralPath $createdumpInStaging) { Start-NativeExecution { chmod 755 $createdumpInStaging } } if (Get-Command -Name tar -CommandType Application -ErrorAction Ignore) { if ($Force -or $PSCmdlet.ShouldProcess("Create tarball package")) { $options = "-czf" if ($PSBoundParameters.ContainsKey('Verbose') -and $PSBoundParameters['Verbose'].IsPresent) { # Use the verbose mode '-v' if '-Verbose' is specified $options = "-czvf" } try { Push-Location -Path $Staging tar $options $packagePath * } finally { Pop-Location } if (Test-Path -Path $packagePath) { Write-Log "You can find the tarball package at $packagePath" return (Get-Item $packagePath) } else { throw "Failed to create $packageName" } } } else { throw "Failed to create the package because the application 'tar' cannot be found" } } function New-TempFolder { $tempPath = [System.IO.Path]::GetTempPath() $tempFolder = Join-Path -Path $tempPath -ChildPath ([System.IO.Path]::GetRandomFileName()) if (!(Test-Path -Path $tempFolder)) { $null = New-Item -Path $tempFolder -ItemType Directory } return $tempFolder } function New-PSSignedBuildZip { param( [Parameter(Mandatory)] [string]$BuildPath, [Parameter(Mandatory)] [string]$SignedFilesPath, [Parameter(Mandatory)] [string]$DestinationFolder, [parameter(HelpMessage='VSTS variable to set for path to zip')] [string]$VstsVariableName ) Update-PSSignedBuildFolder -BuildPath $BuildPath -SignedFilesPath $SignedFilesPath # Remove '$signedFilesPath' now that signed binaries are copied if (Test-Path $signedFilesPath) { Remove-Item -Recurse -Force -Path $signedFilesPath } New-PSBuildZip -BuildPath $BuildPath -DestinationFolder $DestinationFolder -VstsVariableName $VstsVariableName } function New-PSBuildZip { param( [Parameter(Mandatory)] [string]$BuildPath, [Parameter(Mandatory)] [string]$DestinationFolder, [parameter(HelpMessage='VSTS variable to set for path to zip')] [string]$VstsVariableName ) $name = Split-Path -Path $BuildPath -Leaf $zipLocationPath = Join-Path -Path $DestinationFolder -ChildPath "$name-signed.zip" Compress-Archive -Path $BuildPath\* -DestinationPath $zipLocationPath if ($VstsVariableName) { # set VSTS variable with path to package files Write-Log "Setting $VstsVariableName to $zipLocationPath" Write-Host "##vso[task.setvariable variable=$VstsVariableName]$zipLocationPath" } else { return $zipLocationPath } } function Update-PSSignedBuildFolder { param( [Parameter(Mandatory)] [string]$BuildPath, [Parameter(Mandatory)] [string]$SignedFilesPath, [string[]] $RemoveFilter = ('*.pdb', '*.xml', '*.zip', '*.r2rmap'), ## Remove .pdb and .xml files by default, as they are not needed for the package. [bool]$OfficialBuild = $true ) $BuildPathNormalized = (Get-Item $BuildPath).FullName $SignedFilesPathNormalized = (Get-Item $SignedFilesPath).FullName Write-Verbose -Verbose "BuildPath = $BuildPathNormalized" Write-Verbose -Verbose "SignedFilesPath = $signedFilesPath" # Replace unsigned binaries with signed $signedFilesFilter = Join-Path -Path $SignedFilesPathNormalized -ChildPath '*' Write-Verbose -Verbose "signedFilesFilter = $signedFilesFilter" $signedFilesList = Get-ChildItem -Path $signedFilesFilter -Recurse -File foreach ($signedFileObject in $signedFilesList) { # completely skip replacing pwsh on non-windows systems (there is no .exe extension here) # and it may not be signed correctly if ($signedFileObject.Name -eq "pwsh") { Write-Verbose -Verbose "Skipping $signedFileObject" continue } $signedFilePath = $signedFileObject.FullName Write-Verbose -Verbose "Processing $signedFilePath" # Agents seems to be on a case sensitive file system if ($IsLinux) { $relativePath = $signedFilePath.Replace($SignedFilesPathNormalized, '') } else { $relativePath = $signedFilePath.ToLowerInvariant().Replace($SignedFilesPathNormalized.ToLowerInvariant(), '') } Write-Verbose -Verbose "relativePath = $relativePath" $destination = (Get-Item (Join-Path -Path $BuildPathNormalized -ChildPath $relativePath)).FullName Write-Verbose -Verbose "destination = $destination" Write-Log "replacing $destination with $signedFilePath" if (-not (Test-Path $destination)) { $parent = Split-Path -Path $destination -Parent $exists = Test-Path -Path $parent if ($exists) { Write-Verbose -Verbose "Parent:" Get-ChildItem -Path $parent | Select-Object -ExpandProperty FullName | Write-Verbose -Verbose } Write-Error "File not found: $destination, parent - $parent exists: $exists" } # Get-AuthenticodeSignature will only work on Windows if ($IsWindows) { $signature = Get-AuthenticodeSignature -FilePath $signedFilePath if ($signature.Status -ne 'Valid' -and $OfficialBuild) { Write-Host "Certificate Issuer: $($signature.SignerCertificate.Issuer)" Write-Host "Certificate Subject: $($signature.SignerCertificate.Subject)" Write-Error "Invalid signature for $signedFilePath" } elseif ($OfficialBuild -eq $false) { if ($signature.Status -eq 'NotSigned') { Write-Warning "File is not signed: $signedFilePath" } elseif ($signature.SignerCertificate.Issuer -notmatch '^CN=(Microsoft|TestAzureEngBuildCodeSign|Windows Internal Build Tools).*') { Write-Warning "File signed with test certificate: $signedFilePath" Write-Host "Certificate Issuer: $($signature.SignerCertificate.Issuer)" Write-Host "Certificate Subject: $($signature.SignerCertificate.Subject)" } else { Write-Verbose -Verbose "File properly signed: $signedFilePath" } } } else { Write-Verbose -Verbose "Skipping certificate check of $signedFilePath on non-Windows" } Copy-Item -Path $signedFilePath -Destination $destination -Force } foreach($filter in $RemoveFilter) { $removePath = Join-Path -Path $BuildPathNormalized -ChildPath $filter Remove-Item -Path $removePath -Recurse -Force } } function Expand-PSSignedBuild { param( [Parameter(Mandatory)] [string]$BuildZip, [Switch]$SkipPwshExeCheck ) $psModulePath = Split-Path -Path $PSScriptRoot # Expand signed build $buildPath = Join-Path -Path $psModulePath -ChildPath 'ExpandedBuild' $null = New-Item -Path $buildPath -ItemType Directory -Force Expand-Archive -Path $BuildZip -DestinationPath $buildPath -Force # Remove the zip file that contains only those files from the parent folder of 'publish'. # That zip file is used for compliance scan. Remove-Item -Path (Join-Path -Path $buildPath -ChildPath '*.zip') -Recurse if ($SkipPwshExeCheck) { $executablePath = (Join-Path $buildPath -ChildPath 'pwsh.dll') } else { if ($IsMacOS -or $IsLinux) { $executablePath = (Join-Path $buildPath -ChildPath 'pwsh') } else { $executablePath = (Join-Path $buildPath -ChildPath 'pwsh.exe') } } Restore-PSModuleToBuild -PublishPath $buildPath $psOptionsPath = Join-Path $buildPath -ChildPath 'psoptions.json' Restore-PSOptions -PSOptionsPath $psOptionsPath $options = Get-PSOptions $options.PSModuleRestore = $true if (Test-Path -Path $executablePath) { $options.Output = $executablePath } else { throw 'Could not find pwsh' } Set-PSOptions -Options $options } function New-UnixPackage { [CmdletBinding(SupportsShouldProcess=$true)] param( [Parameter(Mandatory)] [ValidateSet("deb", "osxpkg", "rpm")] [string]$Type, [Parameter(Mandatory)] [string]$PackageSourcePath, # Must start with 'powershell' but may have any suffix [Parameter(Mandatory)] [ValidatePattern("^powershell")] [string]$Name, [Parameter(Mandatory)] [string]$Version, # Package iteration version (rarely changed) # This is a string because strings are appended to it [string]$Iteration = "1", # Host architecture values allowed for deb type packages: amd64, arm64 # Host architecture values allowed for rpm type packages include: x86_64, aarch64, native, all, noarch, any # Host architecture values allowed for osxpkg type packages include: x86_64, arm64 [string] [ValidateSet("x86_64", "amd64", "aarch64", "arm64", "native", "all", "noarch", "any")] $HostArchitecture, [Switch] $Force, [switch] $NoSudo, [switch] $LTS, |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |