forked from raspberrypi/pico-setup-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
679 lines (530 loc) · 22.5 KB
/
build.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
[CmdletBinding()]
param (
[Parameter(Mandatory = $true,
Position = 0,
HelpMessage = "Path to a JSON installer configuration file.")]
[Alias("PSPath")]
[ValidateNotNullOrEmpty()]
[string]
$ConfigFile,
[Parameter(HelpMessage = "Path to MSYS2 installation. MSYS2 will be downloaded and installed to this path if it doesn't exist.")]
[ValidatePattern('[\\\/]msys64$')]
[string]
$MSYS2Path = '.\build\msys64',
[switch]
$SkipDownload,
[switch]
$SkipSigning,
[ValidateSet('zlib', 'bzip2', 'lzma')]
[string]
$Compression = 'lzma',
[ValidateSet('system', 'user')]
[string]
$BuildType = 'system'
)
#Requires -Version 7.2
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
. "$PSScriptRoot\common.ps1"
Write-Host "Building from $ConfigFile"
$basename = "pico-setup-windows"
$version = (Get-Content "$PSScriptRoot\version.txt").Trim()
$build = (Get-Date -Format FileDateTimeUniversal)
$suffix = [io.path]::GetFileNameWithoutExtension($ConfigFile) + ($BuildType -eq 'user' ? '-user' : '' )
$binfile = "bin\$basename-$suffix.exe"
$tools = (Get-Content '.\config\tools.json' | ConvertFrom-Json).tools
$repositories = (Get-Content '.\config\repositories.json' | ConvertFrom-Json).repositories
$config = Get-Content $ConfigFile | ConvertFrom-Json
$bitness = $config.bitness
$mingw_arch = $config.mingwArch
$downloads = $config.downloads
$componentSelection = ($config | Get-Member componentSelection) ? $config.componentSelection : $false
mkdirp "build"
mkdirp "bin"
($downloads + $tools) | ForEach-Object {
$_ | Add-Member -NotePropertyName 'shortName' -NotePropertyValue ($_.name -replace '[^a-zA-Z0-9]', '')
$outfile = "downloads/$($_.file)"
if ($SkipDownload) {
Write-Host "Checking $($_.name): " -NoNewline
if (-not (Test-Path $outfile)) {
Write-Error "$outfile not found"
}
}
else {
Write-Host "Downloading $($_.name): " -NoNewline
exec { curl.exe --fail --silent --show-error --url "$($_.href)" --location --output "$outfile" --create-dirs --remote-time --time-cond "downloads/$($_.file)" }
}
# Display versions of packaged installers, for information only. We try to
# extract it from:
# 1. The file name
# 2. The download URL
# 3. The version metadata in the file
#
# This fails for MSYS2, because there is no version number (only a timestamp)
# and the version that gets reported is 7-zip SFX version.
$fileVersion = ''
$versionRegEx = '([0-9]+\.)+[0-9]+'
if ($_.file -match $versionRegEx -or $_.href -match $versionRegEx) {
$fileVersion = $Matches[0]
} else {
$fileVersion = (Get-ChildItem $outfile).VersionInfo.ProductVersion
}
if ($fileVersion) {
Write-Host $fileVersion
} else {
Write-Host $_.file
}
if ($_ | Get-Member dirName) {
$strip = 0;
if ($_ | Get-Member extractStrip) { $strip = $_.extractStrip }
mkdirp "build\$($_.dirName)" -clean
exec { tar -xf $outfile -C "build\$($_.dirName)" --strip-components $strip }
}
}
if (-not (Get-Command cmake -ErrorAction SilentlyContinue)) {
$env:PATH = $env:PATH + ';' + (Resolve-Path .\build\cmake\bin).Path
}
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
$env:PATH = $env:PATH + ';' + (Resolve-Path .\build\git\cmd).Path
}
$repositories | ForEach-Object {
$repodir = Join-Path 'build' ([IO.Path]::GetFileNameWithoutExtension($_.href))
if ($SkipDownload) {
Write-Host "Checking ${repodir}: " -NoNewline
if (-not (Test-Path $repodir)) {
Write-Error "$repodir not found"
}
exec { git -C "$repodir" describe --all }
}
else {
if (Test-Path $repodir) {
Remove-Item $repodir -Recurse -Force
}
exec { git clone -b "$($_.tree)" --depth=1 -c advice.detachedHead=false "$($_.href)" "$repodir" }
if ($_ | Get-Member submodules) {
exec { git -C "$repodir" submodule update --init --depth=1 }
}
}
}
# BTstack needs the PyCryptodome module
if (Test-Path .\build\python\python.exe) {
exec { .\build\python\python.exe .\downloads\pip.pyz install pycryptodome }
Add-Content -Path .\build\python\python*._pth -Value 'import site'
}
$sdkVersion = (cmake -P .\packages\pico-setup-windows\pico-sdk-version.cmake -N | Select-String -Pattern 'PICO_SDK_VERSION_STRING=(.*)$').Matches.Groups[1].Value
if (-not ($sdkVersion -match $versionRegEx)) {
Write-Error 'Could not determine Pico SDK version.'
}
$sdkVersionClean = $Matches[0]
$sdkVersionCommit = (git -C .\build\pico-sdk rev-parse --short HEAD)
$product = "Raspberry Pi Pico SDK v$sdkVersion"
$productDir = "Raspberry Pi\Pico SDK v$sdkVersion"
$company = "Raspberry Pi Ltd"
Write-Host "SDK version: $sdkVersion ($sdkVersionCommit)"
Write-Host "Installer version: $version"
if (-not (Test-Path $MSYS2Path)) {
Write-Host 'Extracting MSYS2'
exec { & .\downloads\msys2.exe -y "-o$(Resolve-Path (Split-Path $MSYS2Path -Parent))" }
}
function sign {
param ([string[]] $filesToSign)
if ($SkipSigning) {
Write-Warning "Skipping code signing."
} else {
$cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert | Where-Object { $_.Subject -like "CN=Raspberry Pi*" }
if (-not $cert) {
Write-Error "No suitable code signing certificates found."
}
$filesToSign | Set-AuthenticodeSignature -Certificate $cert -TimestampServer "http://timestamp.digicert.com" -HashAlgorithm SHA256 | Tee-Object -Variable signatures
$signatures | ForEach-Object {
if ($_.Status -ne 0) {
Write-Error "Error signing $($_.Path)"
}
}
}
}
function msys {
param ([string] $cmd)
exec { & "$MSYS2Path\usr\bin\bash" -leo pipefail -c "$cmd" }
}
# Preserve the current working directory
$env:CHERE_INVOKING = 'yes'
# Start MINGW32/64 environment
$env:MSYSTEM = "MINGW$bitness"
if (-not $SkipDownload) {
# First run setup
msys 'uname -a'
# Core update
msys 'pacman --noconfirm -Syuu'
# Normal update
msys 'pacman --noconfirm -Suu'
msys "pacman -S --noconfirm --needed autoconf automake git libtool make pactoys pkg-config wget"
# pacboy adds MINGW_PACKAGE_PREFIX to package names suffixed with :p
msys "pacboy -S --noconfirm --needed cmake:p ninja:p toolchain:p libusb:p hidapi:p"
}
if (-not (Test-Path ".\build\openocd-install\mingw$bitness")) {
msys "cd build && ../packages/openocd/build-openocd.sh $bitness $mingw_arch"
}
if (-not (Test-Path ".\build\picotool-install\mingw$bitness")) {
msys "cd build && ../packages/picotool/build-picotool.sh $bitness $mingw_arch $version"
}
$template = Get-Content ".\packages\pico-sdk-tools\pico-sdk-tools-config-version.cmake" -Raw
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\mingw$bitness\pico-sdk-tools-config-version.cmake"
exec { .\build\pandoc\pandoc.exe --from gfm --to gfm --output .\build\ReadMe.txt .\docs\tutorial.md }
mkdirp .\build\pico-examples\.vscode
Copy-Item .\packages\pico-examples\ide\vscode\*.json .\build\pico-examples\.vscode\ -Force
exec { tar -a -cf "build\pico-examples.zip" -C "build" "pico-examples" "pico-extras" "pico-playground" }
$endl = '$\r$\n'
function writeFile {
param ([string] $filename)
begin {
"FileOpen `$9 '$filename' w`r`n"
}
process {
$_ -split "[\r\n]+" | ForEach-Object {
"FileWrite `$9 ``${_}${endl}```r`n"
}
}
end {
"FileClose `$9`r`n"
}
}
@"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "MUI2.nsh"
!include "WinCore.nsh"
!include "WordFunc.nsh"
!include "x64.nsh"
!include "packages\pico-setup-windows\aumi.nsh"
!define TITLE "$product"
!define PICO_INSTALL_DIR "$productDir"
; The repos need to be cloned into a dir with a fairly short name, because CMake generates build
; defs with long hashes in the paths. Both CMake and Ninja currently have problems working with
; long paths on Windows.
; We use "%USERPROFILE%" here so that it resolves at runtime to the actual user's profile, rather
; than the admin user which is used to elevate the installer.
!define PICO_REPOS_DIR "`%USERPROFILE%\Documents\Pico-v$sdkVersion"
!define PICO_SHORTCUTS_DIR "`$SMPROGRAMS\$product"
!define PICO_WINTERM_DIR "`$LOCALAPPDATA\Microsoft\Windows Terminal\Fragments\$product"
!define PICO_REG_ROOT SHELL_CONTEXT
!define PICO_REG_KEY "Software\$productDir"
!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\$product"
!define PICO_AppUserModel_ID "RaspberryPi.PicoSDK.$sdkVersion"
Name "`${TITLE}"
Caption "`${TITLE}"
XPStyle on
ManifestDPIAware true
Unicode true
SetCompressor $Compression
RequestExecutionLevel $($BuildType -eq 'system' ? 'admin' : 'user')
VIAddVersionKey "FileDescription" "`${TITLE}"
VIAddVersionKey "InternalName" "$basename"
VIAddVersionKey "ProductName" "`${TITLE}"
VIAddVersionKey "FileVersion" "$version-$build"
VIAddVersionKey "ProductVersion" "$sdkVersion-$sdkVersionCommit"
VIAddVersionKey "LegalCopyright" "$company"
VIAddVersionKey "CompanyName" "$company"
VIFileVersion $version.0
VIProductVersion $sdkVersionClean.0
; Since we're packaging up a bunch of installers, the "Space required" shown is inaccurate
SpaceTexts "none"
; We set the default INSTDIR ourselves in .onInit
InstallDir ""
Var ReposDir
!ifdef BUILD_UNINSTALLER
OutFile "build\build-uninstaller-$suffix.exe"
!define MUI_UNICON "resources\raspberrypi.ico"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Function un.onInit
SetShellVarContext $($BuildType -eq 'system' ? 'all' : 'current')
SetRegView $bitness
ReadRegStr `$ReposDir HKCU "`${PICO_REG_KEY}" "ReposPath"
FunctionEnd
Section "Uninstall"
RMDir /r /REBOOTOK "`${PICO_SHORTCUTS_DIR}"
RMDir /r /REBOOTOK "`${PICO_WINTERM_DIR}"
RMDir /r /REBOOTOK "`$INSTDIR\cmake"
RMDir /r /REBOOTOK "`$INSTDIR\gcc-arm-none-eabi"
RMDir /r /REBOOTOK "`$INSTDIR\git"
RMDir /r /REBOOTOK "`$INSTDIR\ninja"
RMDir /r /REBOOTOK "`$INSTDIR\openocd"
RMDir /r /REBOOTOK "`$INSTDIR\python"
RMDir /r /REBOOTOK "`$INSTDIR\pico-sdk"
RMDir /r /REBOOTOK "`$INSTDIR\pico-sdk-tools"
RMDir /r /REBOOTOK "`$INSTDIR\picotool"
RMDir /r /REBOOTOK "`$INSTDIR\resources"
Delete /REBOOTOK "`$INSTDIR\install.log"
Delete /REBOOTOK "`$INSTDIR\pico-code.ps1"
Delete /REBOOTOK "`$INSTDIR\pico-env.cmd"
Delete /REBOOTOK "`$INSTDIR\pico-env.ps1"
Delete /REBOOTOK "`$INSTDIR\pico-setup.cmd"
Delete /REBOOTOK "`$INSTDIR\pico-setup.lnk"
Delete /REBOOTOK "`$INSTDIR\ReadMe.txt"
Delete /REBOOTOK "`$INSTDIR\version.ini"
Delete /REBOOTOK "`$INSTDIR\pico-examples.zip"
Delete /REBOOTOK "`$INSTDIR\uninstall.exe"
RMDir /REBOOTOK "`$INSTDIR"
; Remove the C:\Program Files\Raspberry Pi directory if it is empty
`${GetParent} "`$INSTDIR" `$R0
RMDir `$R0
`${If} `$ReposDir != ""
RMDir /r /REBOOTOK "`$ReposDir\pico-examples"
RMDir /r /REBOOTOK "`$ReposDir\pico-extras"
RMDir /r /REBOOTOK "`$ReposDir\pico-playground"
RMDir "`$ReposDir"
`${EndIf}
DeleteRegValue `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools" "v$sdkVersion"
DeleteRegKey /ifempty `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools"
DeleteRegKey `${PICO_REG_ROOT} "`${UNINSTALL_KEY}"
DeleteRegKey `${PICO_REG_ROOT} "`${PICO_REG_KEY}"
DeleteRegKey HKCU "`${PICO_REG_KEY}"
SectionEnd
Section
WriteUninstaller `$INSTDIR\uninstall-$suffix.exe
SectionEnd
!else
OutFile "$binfile"
!define MUI_ICON "resources\raspberrypi.ico"
!define MUI_ABORTWARNING
!define MUI_WELCOMEPAGE_TITLE "`${TITLE}"
!insertmacro MUI_PAGE_WELCOME
$($componentSelection ? '!insertmacro MUI_PAGE_COMPONENTS' : '')
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DumpLog
!insertmacro MUI_PAGE_INSTFILES
!define FINISHPAGE_RUN_FUNCTION RunBuild
!define MUI_FINISHPAGE_SHOWREADME "`$INSTDIR\ReadMe.txt"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Show ReadMe"
!include "packages\pico-setup-windows\FinishPage.nsh"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
!include "packages\pico-setup-windows\DumpLog.nsh"
Function .onInit
SetShellVarContext $($BuildType -eq 'system' ? 'all' : 'current')
SetRegView $bitness
; No /D= on the command line
`${If} `$INSTDIR == ""
ReadRegStr `$INSTDIR `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "InstallPath"
`${EndIf}
; Nothing in the registry either; use the defaults
`${If} `$INSTDIR == ""
$(if ($BuildType -eq 'system') {
"StrCpy `$INSTDIR `"`$PROGRAMFILES$bitness`""
} else {
'GetKnownFolderPath $INSTDIR ${FOLDERID_UserProgramFiles}
${If} $INSTDIR == ""
StrCpy $INSTDIR "$LOCALAPPDATA\Programs"
${EndIf}'
})
StrCpy `$INSTDIR "`$INSTDIR\`${PICO_INSTALL_DIR}"
`${EndIf}
StrCpy `$ReposDir "`${PICO_REPOS_DIR}"
ReadRegStr `$R0 HKCU "`${PICO_REG_KEY}" "ReposPath"
`${If} `$R0 != ""
StrCpy `$ReposDir "`$R0"
`${EndIf}
ClearErrors
`${GetParameters} `$R1
`${GetOptions} "`$R1" "/REPOSDIR=" `$R0
`${IfNot} `${Errors}
StrCpy `$ReposDir "`$R0"
`${EndIf}
FunctionEnd
Section
SetOutPath `$INSTDIR
$(if ($bitness -eq '64') {
'${IfNot} ${IsNativeAMD64}
Abort "This installer only supports x86-64 versions of Windows."
${EndIf}'
})
; Uninstall previous version
ReadRegStr `$R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\$basename-$sdkVersion" "UninstallString"
`${If} `$R0 == ""
ReadRegStr `$R0 `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "UninstallString"
`${EndIf}
`${If} `$R0 != ""
`${GetParent} "`$R0" `$R1
DetailPrint "Uninstalling previous version..."
ExecWait '"`$R0" /S _?=`$R1' `$1
DetailPrint "Uninstaller returned `$1"
`${EndIf}
InitPluginsDir
CreateDirectory "`${PICO_SHORTCUTS_DIR}"
SetOutPath `$INSTDIR\resources
File /r resources\*.*
SetOutPath `$INSTDIR
SectionEnd
$($downloads | ForEach-Object {
@"
Section "$($_.name)" Sec$($_.shortName)
ClearErrors
$(if ($_ | Get-Member additionalFiles) {
$_.additionalFiles | ForEach-Object {
"File /oname=`$PLUGINSDIR\$(Split-Path -Leaf $_) $_`r`n"
}
})
$(if (($_ | Get-Member exec) -or ($_ | Get-Member execToLog)) {
@"
SetOutPath "`$TEMP"
File "downloads\$($_.file)"
StrCpy `$0 "`$TEMP\$($_.file)"
$(if ($_ | Get-Member exec) {
"ExecWait ``$($_.exec)`` `$1"
})
$(if ($_ | Get-Member execToLog) {
"nsExec::ExecToLog ``$($_.execToLog)```r`n"
"Pop `$1"
})
DetailPrint "$($_.name) returned `$1"
Delete /REBOOTOK "`$0"
`${If} `${Errors}
Abort "Installation of $($_.name) failed"
$(if ($_ | Get-Member rebootExitCodes) {
$_.rebootExitCodes | ForEach-Object {
"`${ElseIf} `$1 = $_`r`n SetRebootFlag true"
}
})
`${ElseIf} `$1 <> 0
Abort "Installation of $($_.name) failed"
`${EndIf}
"@
})
$(if ($_ | Get-Member dirName) {
"SetOutPath '`$INSTDIR\$($_.dirName)'`r`n"
"File /r build\$($_.dirName)\*.*"
})
SectionEnd
LangString DESC_Sec$($_.shortName) `${LANG_ENGLISH} "$($_.name)"
"@
})
Section "-OpenOCD" SecOpenOCD
SetOutPath "`$INSTDIR\openocd"
File "build\openocd-install\mingw$bitness\bin\*.*"
SetOutPath "`$INSTDIR\openocd\scripts"
File /r "build\openocd-install\mingw$bitness\share\openocd\scripts\*.*"
SectionEnd
!include "packages\pico-setup-windows\VSCodeUtils.nsh"
Section VSCode
`${FindVSCode}
`${If} `$VSCodeExePath != ""
DetailPrint "Found VS Code: `$VSCodeExePath"
`${Else}
DetailPrint "Could not find VS Code. Installing..."
`${InstallVSCode}
`${EndIf}
$((Get-Content 'packages\pico-examples\ide\vscode\extensions.json' | ConvertFrom-Json).recommendations | ForEach-Object {
"`${VSCodeCmd} '--install-extension $_'`r`n"
"Pop `$0`r`n"
})
SectionEnd
Section "-Pico environment" SecPico
SetOutPath "`$INSTDIR\pico-sdk"
File /r "build\pico-sdk\*.*"
SetOutPath "`$INSTDIR\pico-sdk-tools"
File /r "build\pico-sdk-tools\mingw$bitness\*.*"
WriteRegStr `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools" "v$sdkVersion" "`$INSTDIR\pico-sdk-tools"
SetOutPath "`$INSTDIR\picotool"
File "build\picotool-install\mingw$bitness\picotool\*.*"
SetOutPath "`$INSTDIR"
File "build\pico-examples.zip"
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_SDK_VERSION" "$sdkVersion"
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_INSTALL_PATH" "`$INSTDIR"
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_REG_KEY" "`${PICO_REG_KEY}"
File "packages\pico-setup-windows\pico-code.ps1"
File "packages\pico-setup-windows\pico-env.ps1"
File "packages\pico-setup-windows\pico-env.cmd"
File "packages\pico-setup-windows\pico-setup.cmd"
File "build\ReadMe.txt"
File /oname=uninstall.exe "build\uninstall-$suffix.exe"
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "DisplayName" "$($BuildType -eq 'system' ? $product : "$product (User)")"
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "UninstallString" "`$INSTDIR\uninstall.exe"
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "InstallPath" "`$INSTDIR"
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "DisplayIcon" "`$INSTDIR\resources\raspberrypi.ico"
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "DisplayVersion" "$version"
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "Publisher" "$company"
`${IfNot} `${FileExists} "`$VSCodeExePath"
# Just use the default (user) install location for the icon, in case the user installs VS Code later
StrCpy `$VSCodeExePath "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe"
DetailPrint "Could not find Visual Studio Code."
MessageBox MB_OK|MB_ICONEXCLAMATION "Installation of Visual Studio Code failed. Please install it manually by downloading the installer from:${endl}${endl}https://code.visualstudio.com/" /SD IDOK
`${EndIf}
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Developer Command Prompt.lnk" "`${PICO_AppUserModel_ID}!cmd" ``"cmd.exe" '/k "`$INSTDIR\pico-env.cmd"'``
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Developer PowerShell.lnk" "`${PICO_AppUserModel_ID}!powershell" ``"powershell.exe" '-NoExit -ExecutionPolicy Bypass -File "`$INSTDIR\pico-env.ps1"'``
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Visual Studio Code.lnk" "`${PICO_AppUserModel_ID}!code" ``"powershell.exe" '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "`$INSTDIR\pico-code.ps1"' "`$VSCodeExePath" "" SW_SHOWMINIMIZED``
SetOutPath "`${PICO_WINTERM_DIR}"
`${WordReplace} "`$INSTDIR" "\" "\\" "+" `$7
$( @"
{
"profiles": [
{
"name": "Pico - Developer Command Prompt (SDK v$sdkVersion)",
"commandline": "cmd.exe /k \"`$7\\pico-env.cmd\"",
"icon": "`$7\\resources\\raspberrypi.ico",
"startingDirectory": "`$7"
},
{
"name": "Pico - Developer PowerShell (SDK v$sdkVersion)",
"commandline": "powershell.exe -NoExit -ExecutionPolicy Bypass -File \"`$7\\pico-env.ps1\"",
"icon": "`$7\\resources\\raspberrypi.ico",
"startingDirectory": "`$7"
}
]
}
"@ | writeFile "pico-terminals.json")
CreateDirectory "`${PICO_SHORTCUTS_DIR}\Pico - Documentation"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico Datasheet.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico W Datasheet.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico 2 Datasheet.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/pico-2-datasheet.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico C C++ SDK.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico Python SDK.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf"
; Reset working dir for pico-setup launched from the finish page
SetOutPath "`$INSTDIR"
SectionEnd
Function RunBuild
; We need to run pico-setup.cmd un-elevated, to avoid problems with builds later on.
; So we create a shortcut with the command line to use, and have explorer.exe launch it.
; http://mdb-blog.blogspot.com/2013/01/nsis-lunch-program-as-user-from-uac.html
CreateShortcut "`$INSTDIR\pico-setup.lnk" "cmd.exe" '/k call "`$INSTDIR\pico-setup.cmd" "`$ReposDir" 1'
Exec '"`$WINDIR\explorer.exe" "`$INSTDIR\pico-setup.lnk"'
FunctionEnd
!if $($componentSelection ? 1 : 0)
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
$($downloads | ForEach-Object {
" !insertmacro MUI_DESCRIPTION_TEXT `${Sec$($_.shortName)} `$(DESC_Sec$($_.shortName))`n"
})
!insertmacro MUI_FUNCTION_DESCRIPTION_END
!endif
!endif # BUILD_UNINSTALLER
"@ | Set-Content ".\$basename-$suffix.nsi"
exec { .\build\NSIS\makensis /DBUILD_UNINSTALLER ".\$basename-$suffix.nsi" }
# The 'installer' that just writes the uninstaller asks for admin access, which is not actually needed.
$env:__COMPAT_LAYER = "RunAsInvoker"
exec { Start-Process -FilePath ".\build\build-uninstaller-$suffix.exe" -ArgumentList "/S /D=$PSScriptRoot\build" -Wait }
$env:__COMPAT_LAYER = ""
# Sign files before packaging up the installer
sign "build\uninstall-$suffix.exe",
"build\openocd-install\mingw$bitness\bin\openocd.exe",
"build\pico-sdk-tools\mingw$bitness\pioasm\pioasm.exe",
"build\picotool-install\mingw$bitness\picotool\picotool.exe"
exec { .\build\NSIS\makensis ".\$basename-$suffix.nsi" }
Write-Host "Installer saved to $binfile"
# Sign the installer
sign $binfile
# Package OpenOCD separately as well
$version = (cmd /c ".\build\openocd-install\mingw$bitness\bin\openocd.exe" --version '2>&1')[0]
if (-not ($version -match 'Open On-Chip Debugger (?<version>[a-zA-Z0-9\.\-+]+) \((?<timestamp>[0-9\-:]+)\)')) {
Write-Error 'Could not determine openocd version'
}
$filename = 'openocd-{0}-{1}-{2}.zip' -f
($Matches.version -replace '-dirty$', ''),
($Matches.timestamp -replace '[:-]', ''),
$suffix
Write-Host "Saving OpenOCD package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\openocd-install\mingw$bitness\bin" * -C "..\share\openocd" "scripts" }