-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecute-Razzle.ps1
458 lines (395 loc) · 13 KB
/
Execute-Razzle.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
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
#################################
#
# Razzle scripts
#
[CmdletBinding()]
param (
$flavor="fre",
$arch="x64",
$device=$null,
$binariesPrefix = "c:\bin",
$vsVersion = "Enterprise",
$vsYear = "2022",
$ddDir = $env:LOCALAPPDATA,
[switch]$noSymbolicLinks = $true,
[switch]$bl_ok,
[switch]$DevBuild,
[switch]$opt,
[switch]$noDeep,
[switch]$nobtok,
[switch]$gitVersionCheck,
[switch]$autoMount,
[int]$commitLookUp=20,
[switch]$fast = $true,
[switch]$noprompt = $true,
$enlistment = $env:SDXROOT)
##
## Support to get out and get in of razzle
##
$global:ddIni = ($ddDir+"\dd.ini")
function Check-GSudo
{
if ($null -eq (get-command gsudo -ErrorAction Ignore))
{
winget install gsudo
$env:path += ";C:\Program Files (x86)\gsudo\"
}
gsudo cache on -p 0
}
if (!($noSymbolicLinks.IsPresent))
{
Check-GSudo
}
if ($null -eq $enlistment)
{
Write-Verbose "Reading last enlistment from $global:ddIni"
if (test-path $global:ddIni)
{
$ddIniData = (Get-Content $global:ddIni)
$enlistment = $ddIniData | Select -First 1
Write-Verbose "Found enlistment:'$enlistment'"
$data = $ddIniData | Select -Skip 1 -First 1
if ($null -ne $data) {
Write-Verbose "Override arch to $data from ddIni"
$arch = $data
}
$data = $ddIniData | Select -Skip 2 -First 1
if ($null -ne $data) {
Write-Verbose "Override flavor to $data from ddIni"
$flavor = $data
}
}
else
{
throw "Enlistment parameter not specified"
}
}
if (test-path $enlistment)
{
Set-Location $enlistment
pushd $enlistment
}
if ($null -ne $env:_BuildArch) {$arch=$env:_BuildArch;}
if ($null -ne $env:_BuildType) {$flavor=$env:_BuildType;}
function global:Execute-OutsideRazzle
{
param([ScriptBlock] $script)
Undo-Razzle;
try
{
& $script;
}
finally
{
Redo-Razzle;
}
}
Set-Alias UnRazzle Execute-OutsideRazzle -Scope Global;
[hashtable]$razzleKind = [ordered]@{
DevDiv = "\src\tools\razzle.ps1";
Windows = "\developer\razzle.ps1";
Lifted = "\init.cmd";
Phone = "\wm\tools\bat\WPOpen.ps1" }
function Get-RazzleProbeDir($kind, $srcDir)
{
return ($srcDir+$razzleKind[$kind])
}
function Get-RazzleKind($srcDir)
{
$kind = $razzleKind.Keys | where { (test-path (Get-RazzleProbeDir $_ $srcDir)) } | Select-Object -First 1
return $kind
}
function global:Get-RazzleProbes()
{
[string[]]$razzleProbe = $null
if ((test-path $ddIni) -and ($null -eq $enlistment))
{
$enlistment = (get-content $ddIni)
$razzleProbe += $enlistment
return $razzleProbe
}
else
{
if (($enlistment -ne $null) -and (test-path $enlistment))
{
$razzleProbe += $enlistment
return $razzleProbe
}
}
throw "Enlistment not provided"
}
function __Get-BranchName($razzleDirName)
{
$branch = (git branch | where { $_.StartsWith("*") } | select -first 1 )
if ($branch -ne $null)
{
$branch = $branch.Split("/") | select -last 1
if ($branch -ne $null)
{
return $branch;
}
}
return $razzleDirName;
}
function global:New-RazzleLink($linkName, $binaries)
{
if ($noSymbolicLinks.IsPresent)
{
return;
}
Write-Verbose "Linking $linkName -> $binaries ..."
if (!(test-path $binaries))
{
Write-Verbose "Making new dir $binaries"
mkdir $binaries | Out-Null
}
$currentTarget = $null
if (test-path $linkName)
{
$currentTarget = (Get-Item $linkName).Target
}
if (($currentTarget -eq $null) -or ($currentTarget -ne $binaries))
{
Write-Verbose "Making new link $linkName -> $binaries"
gsudo New-Item $linkName -ItemType SymbolicLink -Target $binaries -Force
}
}
function global:Get-BranchCustomId()
{
[string]$branch = git branch | Where-Object { $_.StartsWith("*") };
if ($null -ne $branch)
{
return ($branch.Split("/") | select -last 1)
}
}
function global:Retarget-Razzle
{
Write-Verbose "Retarget-Razzle"
if ($noSymbolicLinks.IsPresent) {
return;
}
Write-Verbose ("Retargeting common paths")
New-RazzleLink "c:\Symbols" "$binariesPrefix\Symbols"
New-RazzleLink "c:\Symcache" "$binariesPrefix\Symbols"
New-RazzleLink "c:\Sym" "$binariesPrefix\Symbols"
#New-RazzleLink $env:temp "$binariesPrefix\Temp"
New-RazzleLink $env:HOMEDRIVE$env:HOMEPATH\.nuget "$binariesPrefix\NuGet"
New-RazzleLink "c:\Temp" "$binariesPrefix\Temp"
New-RazzleLink "c:\Logs" "$binariesPrefix\Logs"
New-RazzleLink "c:\CrashDumps" "$binariesPrefix\CrashDumps"
New-RazzleLink "c:\ProgramData\dbg\Sym" "$binariesPrefix\Symbols"
New-RazzleLink "c:\ProgramData\dbg\Src" "$binariesPrefix\src"
Write-Verbose ("Retargeting done")
}
function global:Retarget-OSRazzle($binariesRoot, $srcRoot = $env:OSBuildRoot)
{
Write-Verbose "Retarget-OSRazzle"
if ($noSymbolicLinks.IsPresent) {
return;
}
Write-Verbose ("Retargeting $srcRoot -> $binariesRoot")
Push-Location ($srcRoot+"\src")
$binRoot = $srcRoot.Replace("f:","w:")
$binRoot = $binRoot.Replace("F:","w:")
$binRoot = $binRoot.Replace("c:\src","w:")
$binRoot = $binRoot.Replace("C:\src","w:")
Write-Verbose "Branch binRoot is $binRoot"
Pop-Location
New-RazzleLink "$binariesPrefix\os" $binRoot
New-RazzleLink ($srcRoot+"\bin") ($binRoot+"\bin")
New-RazzleLink ($srcRoot+"\bldcache") ($binRoot+"\bldcache")
New-RazzleLink ($srcRoot+"\bldout") ($binRoot+"\bldout")
New-RazzleLink ($srcRoot+"\cdg") ($binRoot+"\cdg")
New-RazzleLink ($srcRoot+"\intl") ($binRoot+"\intl")
New-RazzleLink ($srcRoot+"\engcache") ($binRoot+"\engcache")
New-RazzleLink ($srcRoot+"\pgo") ($binRoot+"\pgo")
New-RazzleLink ($srcRoot+"\public") ($binRoot+"\public")
New-RazzleLink ($srcRoot+"\pubpkg") ($binRoot+"\pubpkg")
New-RazzleLink ($srcRoot+"\obj") ($binRoot+"\obj")
New-RazzleLink ($srcRoot+"\osdep") ($binRoot+"\osdep")
New-RazzleLink ($srcRoot+"\out") ($binRoot+"\out")
New-RazzleLink ($srcRoot+"\Temp") ($binRoot+"\Temp")
New-RazzleLink ($srcRoot+"\tools") ($binRoot+"\tools")
New-RazzleLink ($srcRoot+"\utilities") ($binRoot+"\utilities")
New-RazzleLink ($binRoot+"\src") ($srcRoot+"\src")
New-RazzleLink ($srcRoot+"\TestPayload") ($binRoot+"\TestPayload")
Write-Verbose ("Retargeting done")
}
function global:Retarget-LiftedRazzle
{
if ($noSymbolicLinks.IsPresent) {
return;
}
$_srcName = Split-Path $enlistment -Leaf
$binRoot = ($binariesPrefix+"\"+$_srcName)
$srcRoot = ("c:\src\"+$_srcName)
Write-Verbose "Branch binRoot is $binRoot, srcRoot is $srcRoot"
New-RazzleLink ($srcDir+"\packages") ("$binariesPrefix\NuGet\packages")
New-RazzleLink ($srcDir+"\buildOutput") ($binRoot)
New-RazzleLink ($srcDir+"\TestPayload") ($binRoot+"\TestPayLoad")
New-RazzleLink ($srcDir+"\bin") ($binRoot+"\bin")
New-RazzleLink ($srcDir+"\obj") ($binRoot+"\obj")
New-RazzleLink ($srcDir+"\temp") ($binRoot+"\temp")
New-RazzleLink ($srcDir+"\log") ($binRoot+"\out")
}
function Execute-Razzle-Internal($flavor="chk",$arch="x86",$enlistment)
{
if ( ($gitVersionCheck.IsPresent) )
{
Write-Verbose "Checking git version..."
gvfs upgrade
}
$popDir = Get-Location
#Undo-Razzle
$razzleProbe = (Get-RazzleProbes)
$binaries = $binariesPrefix
foreach ($driveEnlistRoot in $razzleProbe)
{
if (test-path $driveEnlistRoot)
{
$razzleDirName = split-path $driveEnlistRoot -leaf
$depotRoot = $driveEnlistRoot
Write-Verbose "Probing $depotRoot..."
if ($depotRoot -like "*\os*\src" -and $autoMount.IsPresent)
{
Write-Verbose "gvfs mount $depotRoot..."
Check-GSudo
gsudo Start-Service GVFS.Service
gvfs mount $depotRoot
}
$srcDir = $depotRoot;
Write-Verbose "Searching for razzle kind in $srcDir"
$global:kind = Get-RazzleKind $srcDir
if ($null -ne $kind)
{
Write-Verbose "Found razzle kind: $kind"
Push-Location $srcDir
$razzle = (Get-RazzleProbeDir $kind $srcDir)
if ( test-path $razzle )
{
Write-Verbose "Found razzle script: $razzle"
if (!($popDir.Path.StartsWith($depotRoot)))
{
$podDir = $null
}
Write-Verbose "Store $srcDir,$arch,$flavor in $ddIni"
Set-Content $ddIni $srcDir
Add-Content $ddIni $arch
Add-Content $ddIni $flavor
$env:RazzleOptions = ""
if (!($opt.IsPresent))
{
$env:RazzleOptions += " no_opt "
}
if ( ($DevBuild.IsPresent) )
{
$env:RazzleOptions += " dev_build "
}
$binaries = ($binariesPrefix+(__Get-BranchName $razzleDirName))
$tempDir = ($binaries + "\temp")
if ($noDeep.IsPresent)
{
$env:RazzleOptions += " binaries_dir " + $binaries + "\bin "
$env:RazzleOptions += " object_dir " + $binaries + "\obj "
$env:RazzleOptions += " public_dir " + $binaries + "\public "
$env:RazzleOptions += " output_dir " + $binaries + "\out "
$env:RazzleOptions += " temp " + $tempDir
}
Retarget-Razzle
Write-Verbose "Adding razzle commands line arguments"
if ($nobtok.IsPresent)
{
$env:RazzleOptions += " no_bl_ok "
}
$phoneOptions = ""
if ( $kind -eq "Phone" )
{
$uConfig = ($ddDir + '\DefaultWindowsSettings.uconfig')
if (test-path $uConfig)
{
$phoneOptions += " uconfig=" + $uConfig + " "
}
$phoneOptions += (" UConfig_Razzle_Parameters=`""+$env:RazzleOptions+"`" ")
}
$env:_XROOT = $srcDir.Trim("\")
$env:_XOSROOT = (get-item "$srcDir\..\").FullName
Write-Verbose "Razzle Fast mode: $fast"
$commitId = (git rev-parse HEAD)
if ($fast) {
$lastCommits = git log -n $commitLookUp --pretty=format:"%H"
$lastEnvId = $lastCommits | where { Test-Path "$env:_XOSROOT\$_.$arch.$flavor.env.json" } | Select -First 1
if (($null -ne $lastEnvId) -and ($lastEnvId -ne $commitId)) {
$commitId = $lastEnvId
}
}
$env:EnlistmentEnv = "$env:_XOSROOT\$commitId.$arch.$flavor.env.json"
if ( ($null -ne $env:EnlistmentEnv) -and (Test-Path $env:EnlistmentEnv) -and ($fast) ) {
Write-Verbose "Fast razzle using $env:EnlistmentEnv"
Get-Content $env:EnlistmentEnv | ConvertFrom-Json |% { $k=$_.Name; $v=$_.Value; Set-Item -Path env:$k -Value $v }
$setRazzle = "$srcDir/utilities/psrazzle/setrazzle.ps1"
if (Test-Path $setRazzle) {
.$setRazzle
}
} else {
Remove-Item "$env:_XOSROOT\*.$arch.$flavor.env.json"
if ( $kind -eq "Phone" ) {
Write-Verbose "Phone: $razzle $device $arch$flavor $phoneOptions"
.$razzle $device ($arch+$flavor) $phoneOptions @args
}
elseif ( $kind -eq "Lifted" ) {
Write-Verbose "Lifted: $razzle $initParams"
Retarget-LiftedRazzle
Push-Location $env:SDXROOT
Enter-VSShell -vsVersion $vsVersion -vsYear $vsYear
Write-Verbose ".$razzle $arch$flavor"
$initParams = (($arch+$flavor),"/2019")
$initParams = (($arch+$flavor))
Invoke-CmdScript -script $razzle -parameters $initParams
.$PSScriptRoot\MSBuild-Alias.ps1 -msBuildAlias
}
else {
Write-Verbose "Windows: $razzle"
Retarget-OSRazzle $binaries (Get-item $depotRoot).Parent.FullName
$arch = $arch.Replace("x64","amd64")
$setRazzlePs1Dir = "$env:_XROOT\developer\$env:USERNAME"
Write-Verbose "Reseting setrazzle.ps1: $setRazzlePs1Dir"
mkdir $setRazzlePs1Dir -ErrorAction Ignore | Out-Null
$setRazzlePs1 = "$setRazzlePs1Dir\setrazzle.ps1"
Set-Content "" -Path $setRazzlePs1
if ($noPrompt) {
$args += "noprompt"
}
Write-Verbose ".$razzle $flavor $arch $env:RazzleOptions $args"
.$razzle $flavor $arch $env:RazzleOptions @args
}
$envData = Get-ChildItem env: | Select -Property Name,Value
$envData | ConvertTo-Json -Depth 2 | Set-Content $env:EnlistmentEnv
Write-Verbose "Stored razzle environment in '$env:EnlistmentEnv'"
}
Pop-Location
if ($null -ne $popDir)
{
Set-Location $popDir
}
return
}
Write-Verbose $razzle
}
}
}
throw "Razzle not found"
}
if (!(test-path "$binariesPrefix\Symbols"))
{
mkdir "$binariesPrefix\Symbols" | Out-Null
}
if (!(test-path "$binariesPrefix\SymCache"))
{
mkdir "$binariesPrefix\SymCache" | Out-Null
}
if (!(test-path "$binariesPrefix\Temp"))
{
mkdir "$binariesPrefix\Temp" | Out-Null
}
Execute-Razzle-Internal -flavor $flavor -arch $arch -enlistment $enlistment