-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathinstall.ps1
1143 lines (972 loc) · 36.1 KB
/
install.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
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
param([Switch]$debug, [Switch]$verbose, [Switch]$force, [Switch]$shbuild=$true, [Switch]$package_setup, [Switch]$declare_only=$false, [Switch]$yesdeps=$false,$fte="",$toolchain = "vsbuild")
# -shbuild:$false - Don't run bin\install.sh (Builds runtime lib)
# - Fail silently (allow npm install-pre-reqs script '&& exit' to work to close y/n prompt window)
# -debug - Enable debug builds (DEBUG=1)
# -verbose - Enable verbose build output (VERBOSE=1)
# -yesdeps - Automatically install dependencies
$OLD_CWD = (Get-Location).Path
$ASSET_PATH = "$env:LOCALAPPDATA\Programs\socketsupply"
$SRC_PATH = "$env:LOCALAPPDATA\Programs\socketsupply\src"
$LIB_PATH = "$env:LOCALAPPDATA\Programs\socketsupply\lib"
$BIN_PATH = "$env:LOCALAPPDATA\Programs\socketsupply\bin"
$INCLUDE_PATH = "$env:LOCALAPPDATA\Programs\socketsupply\include"
$WORKING_PATH = $OLD_CWD
$WORKING_BUILD_PATH = "$WORKING_PATH\build"
$LIBUV_BUILD_TYPE = "Release"
$LIBUV_TAG = $uv
# see https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/versioning
$WEBVIEW2_VERSION = "$webview"
$SSC_BUILD_OPTIONS = "-O2"
$global:git = "git.exe"
$global:cmake = "cmake.exe"
$global:useCurl = $true
$global:WIN_DEBUG_LIBS = ""
$global:path_advice = @()
$global:install_errors = @()
$forceArg = ""
$global:yesDepsArg = ""
$targetClangVersion = "15.0.0"
$targetCmakeVersion = "3.24.0"
$logfile="$env:LOCALAPPDATA\socket_install_ps1.log"
$fso = New-Object -ComObject Scripting.FileSystemObject
$clang_required = ($shbuild -or $fte -eq "windows" -or $fte -eq "all")
$global:android_fte = $false
# Powershell environment variables are maintained across sessions, clear if not explicitly set
$set_debug=$null
if ($debug) {
$LIBUV_BUILD_TYPE = "Debug"
$SSC_BUILD_OPTIONS = "-g", "-O0"
$set_debug="1"
}
[Environment]::SetEnvironmentVariable("DEBUG", $set_debug)
$set_verbose=$null
if ($verbose) {
$set_verbose="1"
}
[Environment]::SetEnvironmentVariable("VERBOSE", $set_verbose)
if ($force) {
$forceArg = "--force"
}
# Build not required if specifically running FTE
if ($fte -ne "") {
$shbuild=$false
}
if ($yesdeps) {
$global:yesDepsArg = "--yes-deps"
}
Function Exit-IfErrors {
# Restore colors, clang can mess with them. Always do this, even if not exiting.
[Console]::ResetColor()
if ($global:install_errors.Count -gt 0) {
foreach ($e in $global:install_errors) {
Write-Log "h" $e
}
Exit $global:install_errors.Count
}
}
function Call-VCVars() {
Write-Log "h" "# Calling vcvars64.bat"
$new_envs = $(Get-ProcEnvs("$OLD_CWD", $vc_vars))
if ($debug) {
foreach ($s in $new_envs) {
Write-Log "d" "$s"
}
Dump-VsEnvVars
}
Write-Log "v" "Errors: "
if ($new_envs[0] -ne "0") {
$global:install_errors += "not ok - vcvars64.bat failed ($($new_envs[0])); Please review $logfile and submit a bug if you think there's an issue."
Exit-IfErrors
}
}
# type:
# d - debug / console / file
# v - verbose / console / file
# h - host (console) / file
# f - file
function Write-Log ($type, $message) {
$wh = $false
$wf = $false
if (($debug) -and (($type -eq "d") -or ($type -eq "v"))) {
$wf = $wh = $true
} elseif (($verbose) -and ($type -eq "v")) {
$wf = $wh = $true
} elseif ($type -eq "f") {
# f doesn't write to host
} elseif ($type -eq "h") {
$wh = $true
}
if ($wh) {
Write-Host $message
}
Write-LogFile $message
}
function Dump-VsEnvVars() {
$path = $env:PATH.split(";")
$msvs="Microsoft Visual Studio"
Write-Log "d" "WindowsSDKLibVersion: $env:WindowsSDKLibVersion"
Write-Log "d" "Searching in path for $msvs"
foreach ($s in $env:PATH.split(";")) {
if ($s -like "*$msvs*") {
Write-Log "d" "$s"
}
}
}
function Write-LogFile($message)
{
Write-Output $message >> $logfile
}
Write-Log "d" "clang_required: $clang_required"
Function Prompt {
param($text)
Write-LogFile "$text`n> "
Write-Host "$text`n> " -NoNewLine
# note that we don't have a specific Prompt-Yn in powershell, everything is a yn
if ($yesdeps) {
Write-Host "default y"
Write-LogFile "default y"
$r = "y"
} else {
$r = $Host.UI.ReadLine()
Write-LogFile "User input: $r"
}
Write-Output $r
}
Function Get-CommandPath {
param($command_string)
$c = (Get-Command "$command_string" -ErrorAction SilentlyContinue -ErrorVariable F).Source
$r = $($null -eq $F.length)
if ($r -eq $true) {
Write-Output $c
return
}
Write-Output $r
}
Function Found-Command {
param($command_string)
(Get-Command $command_string -ErrorAction SilentlyContinue -ErrorVariable F) > $null
$r = $($null -eq $F.length)
Write-Output $r
}
Function Test-CommandVersion {
param($params)
$command_string = $params[0]
$target_version = $params[1]
$debug = $params.Count -gt 2
Write-Log "d" "Test-CommandVersion: $command_string $target_version"
while ($true) {
(Get-Command $command_string -ErrorAction SilentlyContinue -ErrorVariable F) > $null
$r = $($null -eq $F.length)
if ($r -eq $false) {
Write-Log "d" "Get-Command: Command not found"
Write-Output $r
return
}
$output = iex "& $command_string --version" | Out-String
$output = $output.split("`r`n")[0].split(" ")
for (($i = 0); ($i -lt $output.Count); ($i++)) {
if ($output[$i] -eq "version") {
$current_version = $output[$i+1]
}
}
$current_version = $current_version.split("-")[0]
Write-Log "v" "Current $($fso.GetFile($(Get-CommandPath $command_string)).Path): $current_version, target: $target_version"
$ta = @()
foreach ($v in $target_version.split(".")) {
$ta += [int]$v
}
$current_version_split = $current_version.split(".")
$ca = @()
# Ignore invalid (not equal) version strings
if ($current_version_split.Count -eq $ta.Count) {
foreach ($v in $current_version_split) {
$ca += [int]$v
}
} elseif ($debug) {
Write-Log "d" "($current_version_split).Count <> ($ta).Count}"
Write-Output $false
return
}
if ($ca.Count -ne $ta.Count) {
Write-Log "d" "$($ca.Count) <> $($ta.Count)"
Write-Output "$($ca.Count) <> $($ta.Count)"
Write-Output $false
}
for (($i = 0); ($i -lt $ca.Count); ($i++)) {
# Current element is lower, no point in comparing other elements
if ($ca[$i] -lt $ta[$i]) {
break;
}
# Current element is greater, no need to compare other elements
if ($ca[$i] -gt $ta[$i]) {
Write-Log "d" "$current_version >= $target_version"
Write-Output $true
return
}
# Current element is equal, test remaining elements
}
# Remove current item's path so it isn't used in future searches
$p = $fso.GetFile($(Get-CommandPath $command_string)).ParentFolder.Path
Write-Log "d" "Remove $p from PATH"
$env:PATH = $env:PATH.replace("$p", "")
}
Write-Log "d" "No viable versions of $command_string"
Write-Output $false
}
Function Locate-Sh() {
param($_gitPath)
$parent = $fso.GetFile($_gitPath).ParentFolder
if ($parent.Name -eq "cmd") {
$sh = "$($parent.ParentFolder.Path)\bin\sh.exe"
} else {
$sh = "$($parent.Path)\sh.exe"
}
Write-Output $sh
}
Function Locate-Git() {
# TODO(mribbons): This function should be used across the board but isn't ready yet
# Function has to support finding git on path after the first call. ProgramFiles should not be cached.
$gitPath = "$env:ProgramFiles\Git\bin"
$git = "git.exe"
if ((Found-Command($git))) {
$path=Get-CommandPath("$git")
if ($path -like "*Git\mingw64\*") {
# We're running under mingw, we need to locate the windows version of git to find git sh
$git = $path.replace("mingw64\", "")
if ((Found-Command($git))) {
Get-CommandPath("$git")
return $true
} else {
Write-Log "d" "No -mingw64 git at $git"
}
}
Get-CommandPath("$git")
return $true
} else {
$git = "$gitPath\$git"
if ((Found-Command($git))) {
Get-CommandPath("$git")
return $true
}
}
Write-Output ""
return $false
}
Function Bits-Download {
param($params)
$url=$params[0]
$dest=$params[1]
# use bitsadmin because iwr has no error reporting
$jobId = "$([guid]::NewGuid())"
$bts="bitsadmin"
(iex "$bts /create $jobId") > $null
(iex "$bts /setpriority $jobId high") > $null
if ($LASTEXITCODE -ne 0) {
return $LASTEXITCODE
}
(iex "$bts /addfile $jobId ""$url"" ""$dest""") > $null
if ($LASTEXITCODE -ne 0) {
return $LASTEXITCODE
}
(iex "$bts /rawreturn /resume $jobId") > $null
iex "sleep 1"
$percent=0
$exitCode=0
$total=0
Write-Log "h" "Downloading $url to $dest"
while ($true) {
if ($total -lt 1) {
$o=$(iex "$bts /rawreturn /getbytestotal $jobId")
# Write-Host "Bytes total: $o"
try {
# ignore very large initial number
$total=[int64]$o
} catch {}
}
$xferd=[int]$(iex "$bts /rawreturn /getbytestransferred $jobId")
$files=[int]$(iex "$bts /rawreturn /getfilestransferred $jobId")
$error_string=$(iex "$bts /rawreturn /geterror $jobId")
if (($error_string -like "*Unable to get error*") -eq $false) {
$exitCode=[unit32][Convert]::ToString($error_string, 10)
}
if ($total -gt 0) {
$percent = $(($xferd/$total)*100)
}
Write-Progress -Activity "Writing $dest" -PercentComplete $percent
if ($files -ne 0) {
break
}
if ($exitCode -ne 0) {
$exitCode = $exitCode
break
}
iex "sleep 1"
}
# exitCode never gets set, /geterror always contains "Unable to get error - 0x8020000f"
if (($exitCode -eq 0) -and ($xferd -ne $total)) {
$exitCode = $total - $xferd
}
(iex "$bts /rawreturn /complete $jobId") > $null
if (($exitCode -eq 0))
{
$fso = New-Object -ComObject Scripting.FileSystemObject
if ($fso.GetFile($dest).Size -eq 0) {
$exitCode = 255
}
}
if ($exitCode -eq 0) {
$exitCode = 200
}
Write-Log "h" "Downloaded $xferd/$total"
return $exitCode
}
# Sub UAC process is importing function definitions
if ($declare_only) {
Exit 0
}
$vsconfig = "nmake.vsconfig"
if ( -not (("llvm+vsbuild" -eq $toolchain) -or ("vsbuild" -eq $toolchain) -or ("llvm" -eq $toolchain)) ) {
Write-Log "h" "not ok - Unsupported -toolchain $toolchain. Supported options are vsbuild, llvm+vsbuild or llvm (external nmake required)"
Write-Log "h" "not ok - -toolchain llvm+vsbuild will check for and install llvm clang $targetClangVersion and vsbuild nmake."
Exit 1
}
if ("vsbuild" -eq $toolchain) {
if ($shbuild) {
$vsconfig = ".vsconfig"
} else {
# Use smaller footprint if we're not doing an install.sh
$vsconfig = ".vsconfig-app-build"
}
}
Write-Log "h" "# Using toolchain: $toolchain"
#
# Install the files we will want to use for builds
#
Function Install-Files {
(New-Item -ItemType Directory -Force -Path "$BIN_PATH") > $null
(New-Item -ItemType Directory -Force -Path "$LIB_PATH") > $null
(New-Item -ItemType Directory -Force -Path "$SRC_PATH") > $null
(New-Item -ItemType Directory -Force -Path "$INCLUDE_PATH") > $null
# install `.\build\uv\src`
Copy-Item -Path "$WORKING_BUILD_PATH\libuv\src" -Destination "$ASSET_PATH\uv\src" -Recurse -Force
# install `.\src\*`
Copy-Item -Path "$WORKING_PATH\src\*" -Destination "$SRC_PATH" -Recurse -Force -Container
# install `.\build\include\*`
Copy-Item -Path "$WORKING_BUILD_PATH\include\*" -Destination "$INCLUDE_PATH" -Recurse -Force -Container
# install `.\build\lib\*`
Copy-Item -Path "$WORKING_BUILD_PATH\lib\*" -Destination "$LIB_PATH" -Recurse -Force -Container
# install `.\build\bin\*`
Copy-Item -Path "$WORKING_BUILD_PATH\bin\*" -Destination "$BIN_PATH"
Write-Log "h" "ok - installed files to '$ASSET_PATH'."
}
$bin = "bin"
if ((Test-Path "bin" -PathType Container) -eq $false) {
. .\Get-VCVars.ps1
. .\Get-ProcEnvs.ps1
$bin = ""
} else {
. .\bin\Get-VCVars.ps1
. .\bin\Get-ProcEnvs.ps1
}
Function Get-UrlCall {
param($url, $dest)
# need .exe because curl is an alias for iwr, go figure...
if ($global:useCurl) {
return "iex ""& curl.exe -L --write-out '%{http_code}' """"$url"""" --output """"$dest""""""`n"
} else {
return "Bits-Download(""$url"", ""$dest"")"
}
}
Function Build-SSCToPathTaskBlock {
param([string]$binPath)
$regPath = (Get-ItemProperty -Path 'Registry::HKCU\Environment' -Name Path).Path
Write-Log "h" "# Checking for ssc.exe in PATH..."
if ($regPath -like "*$binPath*") {
Write-Log "h" "Found $binPath in user PATH"
return
}
$prompt = "Do you want to add ssc.exe to your user PATH? [y/N]"
$task = [string]{
Write-Log "h" "# Adding ssc.exe to PATH..."
$backup = "$env:LOCALAPPDATA\.userpath.txt"
Write-Log "v" "# Backing up path to $backup"
$regPath = (Get-ItemProperty -Path 'Registry::HKCU\Environment' -Name Path).Path
Write-Output "$regPath" >> $backup
SETX PATH """$binPath"";$regPath"
Write-Log "h" "# Done"
}
$task = $task.replace("`$binPath", $binPath)
Write-Output $prompt
Write-Output $task
}
Function Execute-PromptedTaskBlock() {
param($prompt, $task)
$wrapper = [string]{
$task
}
$script =
$wrapper = "
. ""$OLD_CWD\bin\install.ps1"" -declare_only
$($wrapper.replace("`$task", $task))
"
if (($prompt -ne $null) -and ((Prompt $prompt) -eq 'y')) {
Invoke-Expression $("$wrapper")
}
}
Function Prompt-AddSSCToPath {
# This method has been implemented in a builder / execute pattern which will be used to refactor other install tasks
# but admin priviledges aren't required to add to user's PATH
$prompt, $task = $(Build-SSCToPathTaskBlock $BIN_PATH)
Execute-PromptedTaskBlock $prompt $task
}
Function Add-InstallTask() {
param([ref]$install_tasks, [array]$install_args)
# Build-*InstallBlock functions return array of [prompt, task]
# Empty array indicates dep already installed
if (($install_args.Count -eq 0) -Or ($install_args[0] -eq $null)) {
return $true
}
$prompt = $install_args[0]
$task = $install_args[1]
if (($prompt -ne $null) -and ((Prompt $prompt) -eq 'y')) {
$install_tasks.value += $task
return $true
}
if ($install_args.Count -gt 2) {
# See vc redist task, force installer process to fail if this task isn't confirmed
$global:install_errors += $install_args[2];
}
return $false
}
Function Build-VCRuntimeInstallBlock() {
param($vc_runtime_test_path)
if ((Test-Path "$vc_runtime_test_path" -PathType Leaf) -eq $true) {
Write-Log "h" "# $vc_runtime_test_path found."
return
}
$installer = "vc_redist.x64.exe"
$url = "https://aka.ms/vs/17/release/$installer"
$prompt = "$installer is required to run ssc.exe, proceed with install from Microsoft? y/[n]?"
$t = [string]{
Write-Log "h" "# Downloading $url"
$r=-geturl-
Write-Log "v" "HTTP result: $r"
if ($r -ne 200) {
Return 1
}
Write-Log "h" "# Installing $env:TEMP\$installer"
iex "& $env:TEMP\$installer /quiet"
Write-Log "v" "Install result: $LASTEXITCODE"
return $LASTEXITCODE
}
$t = $t.replace("`$installer", $installer).replace("`$env:TEMP", $env:TEMP).replace("`$url", $url).replace("-geturl-", (Get-UrlCall "$url" "$env:TEMP\$installer")).replace("""", "\""")
Write-Output $prompt
Write-Output $t
Write-Output "ssc.exe will be unable to run without $installer."
}
Function Build-GitInstallBlock() {
param($alternate_prompt)
$gitPath = "$env:ProgramFiles\Git\bin"
# Look for git in path
if (-not (Found-Command($global:git))) {
# Look for git in default location, in case it was installed in a previous session
$global:git = "$gitPath\$global:git"
} else {
Write-Log "v" "# Git found at, changing path to: $global:git"
}
if (Found-Command($global:git)) {
Write-Log "h" "# Found $global:git"
return
} else {
# Reset git path for future searches
$global:git = "git.exe"
}
$prompt = "Git is a requirement, proceed with install from github.com/git-for-windows?"
if ($alternate_prompt -ne $null) {
$prompt = "$alternate_prompt"
}
$prompt += " y/[n]?"
$installer = "Git-2.39.1-64-bit.exe"
$installer_tmp = "Git-2.39.1-64-bit.tmp"
$url = "https://github.com/git-for-windows/git/releases/download/v2.39.1.windows.1/$installer"
$t = [string]{
Write-Log "h" "# Downloading $url"
$r=-geturl-
Write-Log "v" "HTTP result: $r"
if ($r -ne 200) {
Return 1
}
Write-Log "h" "# Installing $env:TEMP\$installer"
iex "& $env:TEMP\$installer /SILENT"
# Waiting for initial process to end doesn't work because a separate installer process is launched after extracting to tmp
sleep 1
$install_pid=(Get-Process $installer_tmp).id
$p = New-Object System.Diagnostics.Process
$processes = @()
foreach ($install_pid in (Get-Process $installer_tmp).id) {
Write-Log "d" "# watch sub process: $install_pid"
$processes+=[System.Diagnostics.Process]::GetProcessById([int]$install_pid)
}
Write-Log "v" "# Waiting for $installer_tmp..."
foreach ($proc in $processes) {
$proc.WaitForExit()
# This doesn't work, may improve in the future. Exit code is always empty.
# We check existence of installed tools later
if ($proc.ExitCode -ne 0) {
Write-Log "v" "Install result: $($proc.ExitCode)"
}
}
return 0
}
$t = $t.replace("`$installer_tmp", $installer_tmp).replace("`$installer", $installer).replace("`$env:TEMP", $env:TEMP).replace("`$url", $url).replace("-geturl-", (Get-UrlCall "$url" "$env:TEMP\$installer")).replace("""", "\""")
Write-Output $prompt
Write-Output $t
}
Function Build-CMakeInstallBlock() {
# install `cmake.exe`
if ($shbuild -eq $false) {
return
}
$cmakePath = ""
if (-not (Test-CommandVersion("cmake", $targetCmakeVersion))) {
$cmakePath = "$env:ProgramFiles\CMake\bin"
if ((Test-Path $cmakePath -PathType Container) -eq $true) {
$env:PATH="$cmakePath\;$env:PATH"
$global:cmake = "$cmakePath\$global:cmake"
}
}
if (Test-CommandVersion("cmake", $targetCmakeVersion)) {
return
}
$prompt = "CMake is a requirement, proceed with install from cmake.org? y/[n]?"
$installer = "cmake-3.26.0-rc2-windows-x86_64.msi"
$url = "https://github.com/Kitware/CMake/releases/download/v3.26.0-rc2/$installer"
$t = [string]{
Write-Log "h" "# Downloading $url"
$r=-geturl-
Write-Log "v" "HTTP result: $r"
if ($r -ne 200) {
Return 1
}
Write-Log "h" "# Installing $env:TEMP\$installer"
iex "& $env:TEMP\$installer /quiet"
sleep 2
$p = New-Object System.Diagnostics.Process
$processes = @()
foreach ($install_pid in (Get-Process "msiexec").id) {
$process=[System.Diagnostics.Process]::GetProcessById([int]$install_pid)
$commandLine = Get-CimInstance Win32_Process -Filter "ProcessId = '$install_pid'" | Select-Object CommandLine
if ($commandLine -like "*$installer*") {
Write-Log "d" "cmake installer args: $($install_pid): $($commandLine)"
Write-Log "d" "# watch sub process: $install_pid"
$processes+=$process
}
}
Write-Log "h" "# Waiting for $installer_tmp..."
foreach ($proc in $processes) {
$proc.WaitForExit()
# This doesn't work, may improve in the future. Exit code is always empty.
# We check existence of installed tools later
if ($proc.ExitCode -ne 0) {
Write-Log "v" "Install result: $($proc.ExitCode)"
}
}
return 0
}
$t = $t.replace("`$installer", $installer).replace("`$env:TEMP", $env:TEMP).replace("`$url", $url).replace("-geturl-", (Get-UrlCall "$url" "$env:TEMP\$installer")).replace("""", "\""")
Write-Output $prompt
Write-Output $t
}
Function Build-LLVMInstallBlock() {
$clang = "clang++"
if (("llvm+vsbuild" -eq $toolchain) -or ("llvm" -eq $toolchain)) {
$clangPath = "$env:ProgramFiles\LLVM\bin"
if (-not (Test-CommandVersion("clang++", $targetClangVersion))) {
$clang = "$clangPath\$clang"
$env:PATH="$clangPath;$env:PATH"
}
if (Test-CommandVersion("clang++", $targetClangVersion)) {
Write-Log "h" "# Found clang++.exe"
return
}
} else {
return
}
$prompt = "LLVM will be downloaded for clang++, proceed? y/[n]?"
$installer = "LLVM-15.0.7-win64.exe"
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/$installer"
$t = [string]{
Write-Log "h" "# Downloading $url"
$r=-geturl-
Write-Log "v" "HTTP result: $r"
if ($r -ne 200) {
Return 1
}
Write-Log "h" "# Installing $env:TEMP\$installer"
iex "& $env:TEMP\$installer /S"
sleep 1
$proc=Get-Process $installer
Write-Log "h" "# Waiting for $installer..."
}
$t = $t.replace("`$installer", $installer).replace("`$env:TEMP", $env:TEMP).replace("`$url", $url).replace("-geturl-", (Get-UrlCall "$url" "$env:TEMP\$installer")).replace("""", "\""")
$install_tasks += $t
Write-Output $prompt
Write-Output $t
}
Function Build-VSBuildInstallBlock() {
if ($install_vc_build -eq $false) {
return
}
$report_vc_vars_reqd = $true
$prompt = "clang $targetClangVersion, Windows SDK$and_nmake are required, proceed with install from Microsoft? y/[n]?"
$installer = "vs_buildtools.exe"
$url = "https://aka.ms/vs/17/release/$installer"
$t = [string]{
Write-Log "h" "# Downloading $url"
$r=-geturl-
Write-Log "v" "HTTP result: $r"
if ($r -ne 200) {
Return 1
}
Write-Log "h" "# Installing $env:TEMP\$installer"
$InstallPWD = (Get-Location).Path
cd "$OLD_CWD\$bin"
Write-Log "f" "cd $OLD_CWD\$bin"
Write-Log "f" "& $env:TEMP\$installer --passive --config $OLD_CWD\$bin\$vsconfig"
iex "& $env:TEMP\$installer --passive --config $OLD_CWD\$bin\$vsconfig"
Write-Log "v" "Install result: $LASTEXITCODE"
cd "$InstallPWD"
return $LASTEXITCODE
}
$t = $t.replace("`$OLD_CWD", $OLD_CWD).replace("`$bin", $bin).replace("`$vsconfig", $vsconfig)
$t = $t.replace("`$installer", $installer).replace("`$env:TEMP", $env:TEMP).replace("`$url", $url).replace("-geturl-", (Get-UrlCall "$url" "$env:TEMP\$installer")).replace("""", "\""")
Write-Output $prompt
Write-Output $t
}
Function Install-Requirements {
Write-Log "v" "# Logging to $logfile"
if (-not (Found-Command("curl"))) {
$global:useCurl = $false
}
$and_nmake = ""
if ($shbuild) {
$and_nmake = " and nmake"
}
if (("llvm+vsbuild" -eq $toolchain) -or ("vsbuild" -eq $toolchain)) {
$vc_exists, $vc_vars = $(Get-VCVars)
$report_vc_vars_reqd = $false
$install_vc_build = $true
if ($clang_required -and $(Test-CommandVersion("clang++", $targetClangVersion)) -and $(Found-Command("nmake.exe"))) {
Write-Log "h" "# Found clang$and_nmake"
$install_vc_build = $false
} elseif ($(Test-CommandVersion("clang++", $targetClangVersion))) {
Write-Log "h" "# Found clang"
$install_vc_build = $false
} else {
if ($vc_exists) {
Call-VcVars
if ($clang_required -and $(Test-CommandVersion("clang++", $targetClangVersion)) -and $(Found-Command("nmake.exe"))) {
$report_vc_vars_reqd = $true
$install_vc_build = $false
} elseif ($(Test-CommandVersion("clang++", $targetClangVersion))) {
$report_vc_vars_reqd = $true
$install_vc_build = $false
} else {
Write-Log "h" "# $vc_vars didn't enable both clang++$and_nmake, downloading vs_build.exe"
Dump-VsEnvVars
}
}
}
# Check windows SDK
if (($env:WindowsSdkDir -eq $null) -or ((Test-Path $env:WindowsSdkDir -PathType Container) -eq $false)) {
Write-Log "v" "WindowsSdkDir not set."
$install_vc_build = $true
}
}
# Check if there are any install tasks before querying user
$check_tasks = @()
$vc_runtime_test_path = "$env:SYSTEMROOT\System32\vcruntime140_1.dll"
$vcruntime_task = $(Build-VCRuntimeInstallBlock "$vc_runtime_test_path")
$git_task = $null
# This task will be used if user opts out of windows build deps but opts in to android deps. By including it within the windows prompts we are preventing an additional prompt.
$git_task_android = $(Build-GitInstallBlock "Git bash is required for running the Android dependency setup script.")
$vsbuild_task = $null
# += , syntax prevents array unrolling, we will get an array of arrays
$check_tasks += , $vcruntime_task
if ($shbuild -or ($fte -eq "all") -or ($fte -eq "windows")) {
$git_task = $(Build-GitInstallBlock)
$vsbuild_task = $(Build-VSBuildInstallBlock $install_vc_build)
$check_tasks += , $git_task
$check_tasks += , $(Build-CMakeInstallBlock)
if ($toolchain -like "*llvm*") {
$check_tasks += , $(Build-LLVMInstallBlock)
}
if ($env:CI -ne $true) {
$check_tasks += , $vsbuild_task
}
}
$vsbuild_missing = $true
if ($vsbuild_task -eq $null) {
$vsbuild_missing = $false
}
$all_deps_accepted = $true
foreach ($task in $check_tasks) {
if (($task -ne $null) -and ($task[0].length -gt 0)) {
$all_deps_accepted = $false
}
}
$global:android_fte = ($fte -eq "android")
if ((($shbuild) -and ($env:CI -eq $null)) -or (($fte -eq "all") -or ($fte -eq "android"))) {
$_gitPath, $exists = Locate-Git
$promptAndroid = $true
if ($exists) {
Write-Log "d" "Git path: $_gitPath"
$sh = Locate-Sh $_gitPath
$android_setup_required_sh = """$sh"" bin\android-functions.sh --android-setup-required"
Write-Log "v" "# Calling $android_setup_required_sh"
iex "& $android_setup_required_sh"
if ($LASTEXITCODE -eq 0) {
$promptAndroid = $false
}
Write-Log "d" "--android-setup-required result: $LASTEXITCODE"
}
if ($promptAndroid) {
$prompt = "Do you want to install Android build dependencies?
Download size: 4.6GB, Installed size: 11.7GB y/[N]"
if ((Prompt $prompt) -ne 'y') {
$global:yesDepsArg = "--no-android-fte"
$global:android_fte = $false
} else {
$global:android_fte = $true
}
}
}
$confirm_windows_deps = $false
if ((($all_deps_accepted -eq $false) -and ($vsbuild_missing) -and ($shbuild) -and ($env:CI -eq $null)) -or (($force -or $vsbuild_missing) -and (($fte -eq "all") -or ($fte -eq "windows")))) {
$prompt = "Do you want to install Windows build dependencies? This will enable you to build Windows apps.
Download size: 5.5GB, Installed size: 10.2GB y/[N]"
if ((Prompt $prompt) -ne 'y') {
$check_tasks = @()
if (($vcruntime_task -ne $null) -and ($vcruntime_task[0].length -gt 0)) {
$check_tasks += , $vcruntime_task
}
if (($global:android_fte -eq $true) -and ($git_task_android -ne $null) -and ($git_task_android[0].length -gt 0)) {
$check_tasks += , $git_task_android
}
} else {
$confirm_windows_deps = $true
}
}
# Ensure git (bash) is installed if only running android-fte and git_task not going to be executed
if (($global:android_fte -eq $true) -and ($git_task -eq $null)) {
$check_tasks += , $git_task_android
}
$install_tasks = @()
$all_deps_accepted = $true
foreach ($task in $check_tasks) {
if ((Add-InstallTask ([ref]$install_tasks) $($task)) -eq $false) {
$all_deps_accepted = $false
}
}
if ($all_deps_accepted) {
# The minimum deps based on current top level choices (Android, Windows) have been accepted
Write-Log "d" "Minimum deps accepted."
}
if ($all_deps_accepted) {
# Install process will write exit code back to this file
$deps_status_file="$($env:Temp)\socket-deps-$([guid]::NewGuid()).dat"
Write-Log "d" "deps_status_file: $deps_status_file"
if ($install_tasks.Count -gt 0) {
Write-Log "h" "# Installing build dependencies..."
$script = ". ""$OLD_CWD\bin\install.ps1"" -declare_only"
# concatinate all script blocks so a single UAC request is raised
foreach ($task in $install_tasks) {
$script = "$($script)
Write-Log ""v"" ""Running install tasks"";
`$r=Invoke-Command {$($task)}
if (`$r -ne 0) {
# Write-Log ""v"" ""fInstall task failed: `$r""
Write-Output `$r > ""$deps_status_file""
return `$r
}
"
}
$script = "$($script)
Write-Output ""0"" > ""$deps_status_file.final""
"
if ($debug) {
$install_script_name="$($env:Temp)\socket-deps-$([guid]::NewGuid()).ps1"
Write-Log "d" "Writing install script to $install_script_name"
Write-Output "$script".replace("\""", """") > $install_script_name
}
try {
Start-Process powershell -verb runas -wait -ArgumentList "$script"
} catch [InvalidOperationException] {
$global:install_errors += "not ok - UAC declined, nothing installed."
}
if (Test-Path $deps_status_file) {
$global:install_errors += "not ok - Dependency installation incomplete: "
foreach ($line in Get-Content($deps_status_file).split("`r`n")) {
$global:install_errors += "Exit code: $line"
}
if ($debug) {
$install_script_name="$($env:Temp)\socket-deps-$([guid]::NewGuid()).ps1"
Write-Log "d" "Writing intall script to $install_script_name"
Write-Output "$script".replace("\""", """") > $install_script_name
} else {
Remove-Item $deps_status_file
}
} elseif ((Test-Path "$deps_status_file.final") -eq $false) {
if ($global:install_errors.Count -eq 0) {
$global:install_errors += "Final exit signal not received from UAC context, forced termination may have occurred."
}
} else {
Remove-Item "$deps_status_file.final"
}
}
} elseif ($shbuild) {
$global:install_errors += "Some dependencies were declined, unable to continue."
}
Exit-IfErrors
if ($confirm_windows_deps -or $shbuild) {
if ($install_vc_build) {
$vc_exists, $vc_vars = $(Get-VCVars)
if ($vc_exists) {
Call-VcVars
} else {
if ($env:CI -eq $null) {
$global:install_errors += "not ok - vcvars64.bat still not present, something went wrong."
}
}
}
if (-not (Test-CommandVersion("clang++", $targetClangVersion))) {
$global:install_errors += "not ok - unable to install clang++."
}
if ($env:CI -eq $null) {
if (($env:WindowsSdkDir -eq $null) -or ((Test-Path $env:WindowsSdkDir -PathType Container) -eq $false)) {
# Had this situation occur after uninstalling SDK from add/remove programs instead of VS Installer.
$global:install_errors += "`$WindowsSdkDir ($env:WindowsSdkDir) still not present, please install manually."
} else {
# Find lib required for debug builds (Prevents 'Debug Assertion Failed. Expression: (_osfile(fh) & fopen)' error)
$WIN_DEBUG_LIBS="$($env:WindowsSdkDir)Lib\$($env:WindowsSDKLibVersion)ucrt\x64\ucrtd.osmode_permissive.lib"