forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 4
/
PowerShellPackage.ps1
201 lines (169 loc) · 6.74 KB
/
PowerShellPackage.ps1
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
[cmdletbinding(DefaultParameterSetName='default')]
# PowerShell Script to clone, build and package PowerShell from specified fork and branch
param (
[string] $fork = 'powershell',
[string] $branch = 'master',
[string] $location = "$pwd\powershell",
[string] $destination = "$env:WORKSPACE",
[ValidateSet("win7-x64", "win7-x86", "win-arm", "win-arm64", "fxdependent", "fxdependent-win-desktop")]
[string]$Runtime = 'win7-x64',
[switch] $Wait,
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")]
[ValidateNotNullOrEmpty()]
[string]$ReleaseTag,
[Parameter(Mandatory,ParameterSetName='IncludeSymbols')]
[switch] $Symbols,
[Parameter(Mandatory,ParameterSetName='packageSigned')]
[ValidatePattern("-signed.zip$")]
[string]$BuildZip,
[Parameter(Mandatory,ParameterSetName='ComponentRegistration')]
[switch] $ComponentRegistration
)
$releaseTagParam = @{}
if ($ReleaseTag)
{
$releaseTagParam = @{ 'ReleaseTag' = $ReleaseTag }
}
if (-not $env:homedrive)
{
Write-Verbose "fixing empty home paths..." -Verbose
$profileParts = $env:userprofile -split ':'
$env:homedrive = $profileParts[0]+':'
$env:homepath = $profileParts[1]
}
if (! (Test-Path $destination))
{
Write-Verbose "Creating destination $destination" -Verbose
$null = New-Item -Path $destination -ItemType Directory
}
Write-Verbose "homedrive : ${env:homedrive}"
Write-Verbose "homepath : ${env:homepath}"
# Don't use CIM_PhysicalMemory, docker containers may cache old values
$memoryMB = (Get-CimInstance win32_computersystem).TotalPhysicalMemory /1MB
$requiredMemoryMB = 2048
if ($memoryMB -lt $requiredMemoryMB)
{
throw "Building powershell requires at least $requiredMemoryMB MiB of memory and only $memoryMB MiB is present."
}
Write-Verbose "Running with $memoryMB MB memory." -Verbose
try{
Set-Location $location
Import-Module "$location\build.psm1" -Force
Import-Module "$location\tools\packaging" -Force
$env:platform = $null
Write-Verbose "Sync'ing Tags..." -verbose
Sync-PSTags -AddRemoteIfMissing
Write-Verbose "Bootstrapping powershell build..." -verbose
Start-PSBootstrap -Force -Package
if ($PSCmdlet.ParameterSetName -eq 'packageSigned')
{
Write-Verbose "Expanding signed build..." -verbose
if($Runtime -like 'fxdependent*')
{
Expand-PSSignedBuild -BuildZip $BuildZip -SkipPwshExeCheck
}
else
{
Expand-PSSignedBuild -BuildZip $BuildZip
}
Remove-Item -Path $BuildZip
}
else
{
Write-Verbose "Starting powershell build for RID: $Runtime and ReleaseTag: $ReleaseTag ..." -verbose
$buildParams = @{'CrossGen'= $Runtime -notmatch "arm" -and $Runtime -notlike "fxdependent*"}
if($Symbols.IsPresent)
{
$buildParams['NoPSModuleRestore'] = $true
}
else
{
$buildParams['PSModuleRestore'] = $true
}
Start-PSBuild -Clean -Runtime $Runtime -Configuration Release @releaseTagParam @buildParams
}
if ($Runtime -eq 'fxdependent')
{
$pspackageParams = @{'Type'='fxdependent'}
}
elseif ($Runtime -eq 'fxdependent-win-desktop')
{
$pspackageParams = @{'Type'='fxdependent-win-desktop'}
}
else
{
$pspackageParams = @{'Type'='msi'; 'WindowsRuntime'=$Runtime}
}
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notmatch 'arm' -and $Runtime -notlike 'fxdependent*')
{
Write-Verbose "Starting powershell packaging(msi)..." -verbose
Start-PSPackage @pspackageParams @releaseTagParam
}
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notin 'win7-x86','fxdependent', 'fxdependent-win-desktop')
{
$pspackageParams['Type']='msix'
Write-Verbose "Starting powershell packaging(msix)..." -verbose
Start-PSPackage @pspackageParams @releaseTagParam
}
if (!$ComponentRegistration.IsPresent -and $Runtime -notlike 'fxdependent*')
{
$pspackageParams['Type']='zip'
$pspackageParams['IncludeSymbols']=$Symbols.IsPresent
Write-Verbose "Starting powershell packaging(zip)..." -verbose
Start-PSPackage @pspackageParams @releaseTagParam
Write-Verbose "Exporting packages ..." -verbose
Get-ChildItem $location\*.msi,$location\*.zip,$location\*.wixpdb,$location\*.msix | ForEach-Object {
$file = $_.FullName
Write-Verbose "Copying $file to $destination" -verbose
Copy-Item -Path $file -Destination "$destination\" -Force
}
}
elseif (!$ComponentRegistration.IsPresent -and $Runtime -like 'fxdependent*')
{
## Add symbols for just like zip package.
$pspackageParams['IncludeSymbols']=$Symbols.IsPresent
Start-PSPackage @pspackageParams @releaseTagParam
## Copy the fxdependent Zip package to destination.
Get-ChildItem $location\PowerShell-*.zip | ForEach-Object {
$file = $_.FullName
Write-Verbose "Copying $file to $destination" -verbose
Copy-Item -Path $file -Destination "$destination\" -Force
}
}
else
{
Write-Verbose "Exporting project.assets files ..." -verbose
$projectAssetsCounter = 1
$projectAssetsFolder = Join-Path -Path $destination -ChildPath 'projectAssets'
$projectAssetsZip = Join-Path -Path $destination -ChildPath 'windowsProjectAssetssymbols.zip'
Get-ChildItem $location\project.assets.json -Recurse | ForEach-Object {
$subfolder = $_.FullName.Replace($location,'')
$subfolder.Replace('project.assets.json','')
$itemDestination = Join-Path -Path $projectAssetsFolder -ChildPath $subfolder
New-Item -Path $itemDestination -ItemType Directory -Force
$file = $_.FullName
Write-Verbose "Copying $file to $itemDestination" -verbose
Copy-Item -Path $file -Destination "$itemDestination\" -Force
$projectAssetsCounter++
}
Compress-Archive -Path $projectAssetsFolder -DestinationPath $projectAssetsZip
Remove-Item -Path $projectAssetsFolder -Recurse -Force -ErrorAction SilentlyContinue
}
}
finally
{
Write-Verbose "Beginning build clean-up..." -verbose
if ($Wait.IsPresent)
{
$path = Join-Path $PSScriptRoot -ChildPath 'delete-to-continue.txt'
$null = New-Item -Path $path -ItemType File
Write-Verbose "Computer name: $env:COMPUTERNAME" -Verbose
Write-Verbose "Delete $path to exit." -Verbose
while(Test-Path -LiteralPath $path)
{
Start-Sleep -Seconds 60
}
}
}