forked from PowerShell/DSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
694 lines (603 loc) · 24.1 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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
param(
[switch]$Release,
[ValidateSet('current','aarch64-pc-windows-msvc','x86_64-pc-windows-msvc','aarch64-apple-darwin','x86_64-apple-darwin','aarch64-unknown-linux-gnu','aarch64-unknown-linux-musl','x86_64-unknown-linux-gnu','x86_64-unknown-linux-musl')]
$architecture = 'current',
[switch]$Clippy,
[switch]$SkipBuild,
[ValidateSet('msix','msix-private','msixbundle','tgz','zip')]
$packageType,
[switch]$Test,
[switch]$GetPackageVersion,
[switch]$SkipLinkCheck,
[switch]$UseX64MakeAppx,
[switch]$UseCratesIO,
[switch]$UpdateLockFile,
[switch]$Audit,
[switch]$UseCFSAuth
)
if ($GetPackageVersion) {
$match = Select-String -Path $PSScriptRoot/dsc/Cargo.toml -Pattern '^version\s*=\s*"(?<ver>.*?)"$'
if ($null -eq $match) {
throw 'Unable to find version in Cargo.toml'
}
return $match.Matches.Groups[1].Value
}
$filesForWindowsPackage = @(
'dsc.exe',
'dscecho.exe',
'echo.dsc.resource.json',
'assertion.dsc.resource.json',
'group.dsc.resource.json',
'NOTICE.txt',
'powershell.dsc.resource.json',
'psDscAdapter/',
'reboot_pending.dsc.resource.json',
'reboot_pending.resource.ps1',
'registry.dsc.resource.json',
'registry.exe',
'RunCommandOnSet.dsc.resource.json',
'RunCommandOnSet.exe',
'windowspowershell.dsc.resource.json',
'wmi.dsc.resource.json',
'wmi.resource.ps1',
'windows_baseline.dsc.yaml',
'windows_inventory.dsc.yaml'
'dsc_default.settings.json',
'dsc.settings.json'
)
$filesForLinuxPackage = @(
'dsc',
'dscecho',
'echo.dsc.resource.json',
'assertion.dsc.resource.json',
'apt.dsc.resource.json',
'apt.dsc.resource.sh',
'group.dsc.resource.json',
'NOTICE.txt',
'powershell.dsc.resource.json',
'psDscAdapter/',
'RunCommandOnSet.dsc.resource.json',
'runcommandonset',
'dsc_default.settings.json',
'dsc.settings.json'
)
$filesForMacPackage = @(
'dsc',
'dscecho',
'echo.dsc.resource.json',
'assertion.dsc.resource.json',
'brew.dsc.resource.json',
'brew.dsc.resource.sh',
'group.dsc.resource.json',
'NOTICE.txt',
'powershell.dsc.resource.json',
'psDscAdapter/',
'RunCommandOnSet.dsc.resource.json',
'runcommandonset',
'dsc_default.settings.json',
'dsc.settings.json'
)
# the list of files other than the binaries which need to be executable
$filesToBeExecutable = @(
'apt.dsc.resource.sh',
'brew.dsc.resource.sh'
)
function Find-LinkExe {
try {
# this helper may not be needed anymore, but keeping in case the install doesn't work for everyone
Write-Verbose -Verbose "Finding link.exe"
Push-Location $BuildToolsPath
Set-Location "$(Get-ChildItem -Directory | Sort-Object name -Descending | Select-Object -First 1)\bin\Host$($env:PROCESSOR_ARCHITECTURE)\x64" -ErrorAction Stop
$linkexe = (Get-Location).Path
Write-Verbose -Verbose "Using $linkexe"
$linkexe
}
finally {
Pop-Location
}
}
if ($null -ne (Get-Command rustup -ErrorAction Ignore)) {
$rustup = 'rustup'
} else {
$rustup = 'echo'
}
if ($null -ne $packageType) {
$SkipBuild = $true
} else {
## Test if Rust is installed
if (!(Get-Command 'cargo' -ErrorAction Ignore)) {
Write-Verbose -Verbose "Rust not found, installing..."
if (!$IsWindows) {
curl https://sh.rustup.rs -sSf | sh -s -- -y
$env:PATH += ":$env:HOME/.cargo/bin"
}
else {
Invoke-WebRequest 'https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe' -OutFile 'temp:/rustup-init.exe'
Write-Verbose -Verbose "Use the default settings to ensure build works"
& 'temp:/rustup-init.exe' -y
$env:PATH += ";$env:USERPROFILE\.cargo\bin"
Remove-Item temp:/rustup-init.exe -ErrorAction Ignore
}
}
$BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
& $rustup default stable
}
if (!$SkipBuild -and !$SkipLinkCheck -and $IsWindows -and !(Get-Command 'link.exe' -ErrorAction Ignore)) {
if (!(Test-Path $BuildToolsPath)) {
Write-Verbose -Verbose "link.exe not found, installing C++ build tools"
Invoke-WebRequest 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile 'temp:/vs_buildtools.exe'
$arg = @('--passive','--add','Microsoft.VisualStudio.Workload.VCTools','--includerecommended')
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
$arg += '--add','Microsoft.VisualStudio.Component.VC.Tools.ARM64'
}
Start-Process -FilePath 'temp:/vs_buildtools.exe' -ArgumentList $arg -Wait
Remove-Item temp:/vs_installer.exe -ErrorAction Ignore
Write-Verbose -Verbose "Updating env vars"
$machineEnv = [environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine).Split(';')
$userEnv = [environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User).Split(';')
$pathEnv = ($env:PATH).Split(';')
foreach ($env in $machineEnv) {
if ($pathEnv -notcontains $env) {
$pathEnv += $env
}
}
foreach ($env in $userEnv) {
if ($pathEnv -notcontains $env) {
$pathEnv += $env
}
}
$env:PATH = $pathEnv -join ';'
}
#$linkexe = Find-LinkExe
#$env:PATH += ";$linkexe"
}
$configuration = $Release ? 'release' : 'debug'
$flags = @($Release ? '-r' : $null)
if ($architecture -eq 'current') {
$path = ".\target\$configuration"
$target = Join-Path $PSScriptRoot 'bin' $configuration
}
else {
& $rustup target add $architecture
$flags += '--target'
$flags += $architecture
$path = ".\target\$architecture\$configuration"
$target = Join-Path $PSScriptRoot 'bin' $architecture $configuration
}
if (!$SkipBuild) {
if (Test-Path $target) {
Remove-Item $target -Recurse -ErrorAction Ignore
}
New-Item -ItemType Directory $target -ErrorAction Ignore > $null
if ($UseCratesIO) {
# this will override the config.toml
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
$env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/'
} else {
Write-Host "Using CFS for cargo source replacement"
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
if ($UseCFSAuth -or $null -ne $env:TF_BUILD) {
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
throw "Azure CLI not found"
}
if ($null -ne (Get-Command az -ErrorAction Ignore)) {
Write-Host "Getting token"
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
} else {
$header = "Bearer $accessToken"
$env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
}
}
else {
Write-Warning "Azure CLI not found, proceeding with anonymous access."
}
}
}
# make sure dependencies are built first so clippy runs correctly
$windows_projects = @("pal", "registry", "reboot_pending", "wmi-adapter", "configurations/windows")
$macOS_projects = @("resources/brew")
$linux_projects = @("resources/apt")
# projects are in dependency order
$projects = @(
"tree-sitter-dscexpression",
"security_context_lib",
"dsc_lib",
"dsc",
"dscecho",
"osinfo",
"powershell-adapter",
"process",
"runcommandonset",
"tools/dsctest",
"tools/test_group_resource",
"y2j",
"."
)
$pedantic_unclean_projects = @()
$clippy_unclean_projects = @("tree-sitter-dscexpression")
$skip_test_projects_on_windows = @("tree-sitter-dscexpression")
if ($IsWindows) {
$projects += $windows_projects
}
if ($IsMacOS) {
$projects += $macOS_projects
}
if ($IsLinux) {
$projects += $linux_projects
}
$failed = $false
foreach ($project in $projects) {
## Build format_json
Write-Host -ForegroundColor Cyan "Building $project ... for $architecture"
try {
Push-Location "$PSScriptRoot/$project" -ErrorAction Stop
if ($project -eq 'tree-sitter-dscexpression') {
if ($UpdateLockFile) {
cargo generate-lockfile
}
else {
if ($Audit) {
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
cargo install cargo-audit --features=fix
}
cargo audit fix
}
./build.ps1
}
}
if (Test-Path "./Cargo.toml")
{
if ($Clippy) {
if ($clippy_unclean_projects -contains $project) {
Write-Verbose -Verbose "Skipping clippy for $project"
}
elseif ($pedantic_unclean_projects -contains $project) {
Write-Verbose -Verbose "Running clippy for $project"
cargo clippy @flags -- -Dwarnings
}
else {
Write-Verbose -Verbose "Running clippy with pedantic for $project"
cargo clippy @flags --% -- -Dwarnings -Dclippy::pedantic
}
}
else {
if ($UpdateLockFile) {
cargo generate-lockfile
}
else {
if ($Audit) {
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
cargo install cargo-audit --features=fix
}
cargo audit fix
}
cargo build @flags
}
}
}
if ($LASTEXITCODE -ne 0) {
$failed = $true
break
}
$binary = Split-Path $project -Leaf
if ($IsWindows) {
Copy-Item "$path/$binary.exe" $target -ErrorAction Ignore
}
else {
Copy-Item "$path/$binary" $target -ErrorAction Ignore
}
if (Test-Path "./copy_files.txt") {
Get-Content "./copy_files.txt" | ForEach-Object {
# if the line contains a '\' character, throw an error
if ($_ -match '\\') {
throw "copy_files.txt should use '/' as the path separator"
}
# copy the file to the target directory, creating the directory path if needed
$fileCopyPath = $_.split('/')
if ($fileCopyPath.Length -gt 1) {
$fileCopyPath = $fileCopyPath[0..($fileCopyPath.Length - 2)]
$fileCopyPath = $fileCopyPath -join '/'
New-Item -ItemType Directory -Path "$target/$fileCopyPath" -Force -ErrorAction Ignore | Out-Null
}
Copy-Item $_ "$target/$_" -Force -ErrorAction Ignore
}
}
Copy-Item "*.dsc.resource.json" $target -Force -ErrorAction Ignore
# be sure that the files that should be executable are executable
if ($IsLinux -or $IsMacOS) {
foreach ($exeFile in $filesToBeExecutable) {
$exePath = "$target/$exeFile"
if (test-path $exePath) {
chmod +x $exePath
}
}
}
} finally {
Pop-Location
}
}
if ($failed) {
Write-Host -ForegroundColor Red "Build failed"
exit 1
}
}
if (!$Clippy -and !$SkipBuild) {
$relative = Resolve-Path $target -Relative
Write-Host -ForegroundColor Green "`nEXE's are copied to $target ($relative)"
# remove the other target in case switching between them
$dirSeparator = [System.IO.Path]::DirectorySeparatorChar
if ($Release) {
$oldTarget = $target.Replace($dirSeparator + 'release', $dirSeparator + 'debug')
}
else {
$oldTarget = $target.Replace($dirSeparator + 'debug', $dirSeparator + 'release')
}
$env:PATH = $env:PATH.Replace($oldTarget, '')
$paths = $env:PATH.Split([System.IO.Path]::PathSeparator)
$found = $false
foreach ($path in $paths) {
if ($path -eq $target) {
$found = $true
break
}
}
# remove empty entries from path
$env:PATH = [string]::Join([System.IO.Path]::PathSeparator, $env:PATH.Split([System.IO.Path]::PathSeparator, [StringSplitOptions]::RemoveEmptyEntries))
if (!$found) {
Write-Host -ForegroundCOlor Yellow "Adding $target to `$env:PATH"
$env:PATH = $target + [System.IO.Path]::PathSeparator + $env:PATH
}
}
if ($Test) {
$failed = $false
$usingADO = ($null -ne $env:TF_BUILD)
$repository = 'PSGallery'
if ($usingADO) {
$repository = 'CFS'
if ($null -eq (Get-PSResourceRepository -Name CFS -ErrorAction Ignore)) {
"Registering CFS repository"
Register-PSResourceRepository -uri 'https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2' -Name CFS -Trusted
}
}
if ($IsWindows) {
# PSDesiredStateConfiguration module is needed for Microsoft.Windows/WindowsPowerShell adapter
$FullyQualifiedName = @{ModuleName="PSDesiredStateConfiguration";ModuleVersion="2.0.7"}
if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName))
{
Install-PSResource -Name PSDesiredStateConfiguration -Version 2.0.7 -Repository $repository -TrustRepository
}
}
if (-not(Get-Module -ListAvailable -Name Pester))
{ "Installing module Pester"
Install-PSResource Pester -WarningAction Ignore -Repository $repository -TrustRepository
}
foreach ($project in $projects) {
if ($IsWindows -and $skip_test_projects_on_windows -contains $project) {
Write-Verbose -Verbose "Skipping test for $project on Windows"
continue
}
Write-Host -ForegroundColor Cyan "Testing $project ..."
try {
Push-Location "$PSScriptRoot/$project"
if (Test-Path "./Cargo.toml")
{
cargo test
if ($LASTEXITCODE -ne 0) {
$failed = $true
}
}
} finally {
Pop-Location
}
}
if ($failed) {
throw "Test failed"
}
"PSModulePath is:"
$env:PSModulePath
"Pester module located in:"
(Get-Module -Name Pester -ListAvailable).Path
# On Windows disable duplicated WinPS resources that break PSDesiredStateConfiguration module
if ($IsWindows) {
$a = $env:PSModulePath -split ";" | ? { $_ -notmatch 'WindowsPowerShell' }
$env:PSModulePath = $a -join ';'
"Updated PSModulePath is:"
$env:PSModulePath
if (-not(Get-Module -ListAvailable -Name Pester))
{ "Installing module Pester"
$InstallTargetDir = ($env:PSModulePath -split ";")[0]
Find-PSResource -Name 'Pester' -Repository $repository | Save-PSResource -Path $InstallTargetDir -TrustRepository
}
"Updated Pester module location:"
(Get-Module -Name Pester -ListAvailable).Path
}
Invoke-Pester -ErrorAction Stop
}
function Find-MakeAppx() {
$makeappx = Get-Command makeappx -CommandType Application -ErrorAction Ignore
if ($null -eq $makeappx) {
# try to find
if (!$UseX64MakeAppx -and $architecture -eq 'aarch64-pc-windows-msvc') {
$arch = 'arm64'
}
else {
$arch = 'x64'
}
$makeappx = Get-ChildItem -Recurse -Path (Join-Path ${env:ProgramFiles(x86)} 'Windows Kits\10\bin\*\' $arch) -Filter makeappx.exe | Sort-Object FullName -Descending | Select-Object -First 1
if ($null -eq $makeappx) {
throw "makeappx not found, please install Windows SDK"
}
}
$makeappx
}
$productVersion = ((Get-Content $PSScriptRoot/dsc/Cargo.toml) -match '^version\s*=\s*') -replace 'version\s*=\s*"(.*?)"', '$1'
if ($packageType -eq 'msixbundle') {
if (!$IsWindows) {
throw "MsixBundle is only supported on Windows"
}
$packageName = "DSC-$productVersion-Win"
$makeappx = Find-MakeAppx
$msixPath = Join-Path $PSScriptRoot 'bin' 'msix'
& $makeappx bundle /d $msixPath /p "$PSScriptRoot\bin\$packageName.msixbundle"
return
} elseif ($packageType -eq 'msix' -or $packageType -eq 'msix-private') {
if (!$IsWindows) {
throw "MSIX is only supported on Windows"
}
if ($architecture -eq 'current') {
throw 'MSIX requires a specific architecture'
}
$isPrivate = $packageType -eq 'msix-private'
$makeappx = Find-MakeAppx
$makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop
$displayName = "DesiredStateConfiguration"
$isPreview = $productVersion -like '*-*'
$productName = "DesiredStateConfiguration"
if ($isPreview) {
Write-Verbose -Verbose "Preview version detected"
if ($isPrivate) {
$productName += "-Private"
}
else {
$productName += "-Preview"
}
# save preview number
$previewNumber = $productVersion -replace '.*?-[a-z]+\.([0-9]+)', '$1'
# remove label from version
$productVersion = $productVersion.Split('-')[0]
# replace revision number with preview number
$productVersion = $productVersion -replace '(\d+)$', "$previewNumber.0"
if ($isPrivate) {
$displayName += "-Private"
}
else {
$displayName += "-Preview"
}
}
Write-Verbose -Verbose "Product version is $productVersion"
$arch = if ($architecture -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' }
# Appx manifest needs to be in root of source path, but the embedded version needs to be updated
# cp-459155 is 'CN=Microsoft Windows Store Publisher (Store EKU), O=Microsoft Corporation, L=Redmond, S=Washington, C=US'
# authenticodeFormer is 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'
$releasePublisher = 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'
$appxManifest = Get-Content "$PSScriptRoot\packaging\msix\AppxManifest.xml" -Raw
$appxManifest = $appxManifest.Replace('$VERSION$', $ProductVersion).Replace('$ARCH$', $Arch).Replace('$PRODUCTNAME$', $productName).Replace('$DISPLAYNAME$', $displayName).Replace('$PUBLISHER$', $releasePublisher)
$msixTarget = Join-Path $PSScriptRoot 'bin' $architecture 'msix'
if (Test-Path $msixTarget) {
Remove-Item $msixTarget -Recurse -ErrorAction Stop -Force
}
New-Item -ItemType Directory $msixTarget > $null
Set-Content -Path "$msixTarget\AppxManifest.xml" -Value $appxManifest -Force
foreach ($file in $filesForWindowsPackage) {
if ((Get-Item "$target\$file") -is [System.IO.DirectoryInfo]) {
Copy-Item "$target\$file" "$msixTarget\$file" -Recurse -ErrorAction Stop
} else {
Copy-Item "$target\$file" $msixTarget -ErrorAction Stop
}
}
# Necessary image assets need to be in source assets folder
$assets = @(
'Square150x150Logo'
'Square64x64Logo'
'Square44x44Logo'
'Square44x44Logo.targetsize-48'
'Square44x44Logo.targetsize-48_altform-unplated'
'StoreLogo'
)
New-Item -ItemType Directory "$msixTarget\assets" > $null
foreach ($asset in $assets) {
Copy-Item "$PSScriptRoot\packaging\assets\$asset.png" "$msixTarget\assets" -ErrorAction Stop
}
Write-Verbose "Creating priconfig.xml" -Verbose
& $makepri createconfig /o /cf (Join-Path $msixTarget "priconfig.xml") /dq en-US
if ($LASTEXITCODE -ne 0) {
throw "Failed to create priconfig.xml"
}
Write-Verbose "Creating resources.pri" -Verbose
Push-Location $msixTarget
& $makepri new /v /o /pr $msixTarget /cf (Join-Path $msixTarget "priconfig.xml")
Pop-Location
if ($LASTEXITCODE -ne 0) {
throw "Failed to create resources.pri"
}
Write-Verbose "Creating msix package" -Verbose
$targetFolder = Join-Path $PSScriptRoot 'bin' 'msix'
if (Test-Path $targetFolder) {
Remove-Item $targetFolder -Recurse -ErrorAction Stop -Force
} else {
New-Item -ItemType Directory $targetFolder > $null
}
$packageName = Join-Path $targetFolder "$productName-$productVersion-$arch.msix"
& $makeappx pack /o /v /h SHA256 /d $msixTarget /p $packageName
if ($LASTEXITCODE -ne 0) {
throw "Failed to create msix package"
}
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName"
} elseif ($packageType -eq 'zip') {
$zipTarget = Join-Path $PSScriptRoot 'bin' $architecture 'zip'
if (Test-Path $zipTarget) {
Remove-Item $zipTarget -Recurse -ErrorAction Stop -Force
}
New-Item -ItemType Directory $zipTarget > $null
foreach ($file in $filesForWindowsPackage) {
if ((Get-Item "$target\$file") -is [System.IO.DirectoryInfo]) {
Copy-Item "$target\$file" "$zipTarget\$file" -Recurse -ErrorAction Stop
} else {
Copy-Item "$target\$file" $zipTarget -ErrorAction Stop
}
}
$packageName = "DSC-$productVersion-$architecture.zip"
$zipFile = Join-Path $PSScriptRoot 'bin' $packageName
Compress-Archive -Path "$zipTarget/*" -DestinationPath $zipFile -Force
Write-Host -ForegroundColor Green "`nZip file is created at $zipFile"
} elseif ($packageType -eq 'tgz') {
$tgzTarget = Join-Path $PSScriptRoot 'bin' $architecture 'tgz'
if (Test-Path $tgzTarget) {
Remove-Item $tgzTarget -Recurse -ErrorAction Stop -Force
}
New-Item -ItemType Directory $tgzTarget > $null
if ($IsLinux) {
$filesForPackage = $filesForLinuxPackage
} elseif ($IsMacOS) {
$filesForPackage = $filesForMacPackage
} else {
Write-Error "Unsupported platform for tgz package"
}
foreach ($file in $filesForPackage) {
if ((Get-Item "$target\$file") -is [System.IO.DirectoryInfo]) {
Copy-Item "$target\$file" "$tgzTarget\$file" -Recurse -ErrorAction Stop
} else {
Copy-Item "$target\$file" $tgzTarget -ErrorAction Stop
}
}
# for Linux, we only build musl as its statically linked, so we remove the musl suffix
$productArchitecture = if ($architecture -eq 'aarch64-unknown-linux-musl') {
'aarch64-linux'
} elseif ($architecture -eq 'x86_64-unknown-linux-musl') {
'x86_64-linux'
} else {
$architecture
}
$packageName = "DSC-$productVersion-$productArchitecture.tar"
$tarFile = Join-Path $PSScriptRoot 'bin' $packageName
tar cvf $tarFile -C $tgzTarget .
if ($LASTEXITCODE -ne 0) {
throw "Failed to create tar file"
}
Write-Host -ForegroundColor Green "`nTar file is created at $tarFile"
$gzFile = "$tarFile.gz"
gzip -c $tarFile > $gzFile
if ($LASTEXITCODE -ne 0) {
throw "Failed to create gz file"
}
Write-Host -ForegroundColor Green "`nGz file is created at $gzFile"
}
$env:RUST_BACKTRACE=1