7
7
$architecture = ' current' ,
8
8
[switch ]$Clippy ,
9
9
[switch ]$SkipBuild ,
10
- [switch ] $Msix ,
11
- [ switch ] $MsixBundle ,
10
+ [ValidateSet ( ' msix ' , ' msixbundle ' , ' tgz ' , ' zip ' )]
11
+ $packageType ,
12
12
[switch ]$Test ,
13
13
[switch ]$GetPackageVersion ,
14
- [switch ]$SkipLinkCheck
14
+ [switch ]$SkipLinkCheck ,
15
+ [switch ]$UseX64MakeAppx
15
16
)
16
17
17
18
if ($GetPackageVersion ) {
@@ -23,28 +24,45 @@ if ($GetPackageVersion) {
23
24
return $match.Matches.Groups [1 ].Value
24
25
}
25
26
26
- # # Test if Rust is installed
27
- if (! (Get-Command ' cargo' - ErrorAction Ignore)) {
28
- Write-Verbose - Verbose " Rust not found, installing..."
29
- if (! $IsWindows ) {
30
- curl https:// sh.rustup.rs - sSf | sh - s -- - y
31
- $env: PATH += " :$env: HOME /.cargo/bin"
32
- }
33
- else {
34
- Invoke-WebRequest ' https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe' - OutFile ' temp:/rustup-init.exe'
35
- Write-Verbose - Verbose " Use the default settings to ensure build works"
36
- & ' temp:/rustup-init.exe' - y
37
- $env: PATH += " ;$env: USERPROFILE \.cargo\bin"
38
- Remove-Item temp:/ rustup-init.exe - ErrorAction Ignore
39
- }
40
- }
27
+ $filesForWindowsPackage = @ (
28
+ ' dsc.exe' ,
29
+ ' assertion.dsc.resource.json' ,
30
+ ' group.dsc.resource.json' ,
31
+ ' powershell.dsc.resource.json' ,
32
+ ' PSDesiredStateConfiguration/' ,
33
+ ' psDscAdapter/' ,
34
+ ' reboot_pending.dsc.resource.json' ,
35
+ ' reboot_pending.resource.ps1' ,
36
+ ' registry.dsc.resource.json' ,
37
+ ' registry.exe' ,
38
+ ' RunCommandOnSet.dsc.resource.json' ,
39
+ ' RunCommandOnSet.exe' ,
40
+ ' windowspowershell.dsc.resource.json' ,
41
+ ' wmi.dsc.resource.json' ,
42
+ ' wmi.resource.ps1'
43
+ )
41
44
42
- if ($IsLinux -and (Test-Path / etc/ mariner- release)) {
43
- tdnf install - y openssl- devel
44
- }
45
+ $filesForLinuxPackage = @ (
46
+ ' dsc' ,
47
+ ' assertion.dsc.resource.json' ,
48
+ ' group.dsc.resource.json' ,
49
+ ' powershell.dsc.resource.json' ,
50
+ ' psDscAdapter/' ,
51
+ ' RunCommandOnSet.dsc.resource.json' ,
52
+ ' runcommandonset'
53
+ )
45
54
46
- rustup default stable
47
- $BuildToolsPath = " ${env: ProgramFiles(x86)} \Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
55
+ $filesForMacPackage = @ (
56
+ ' dsc' ,
57
+ ' assertion.dsc.resource.json' ,
58
+ ' brew.dsc.resource.json' ,
59
+ ' brew.dsc.resource.sh' ,
60
+ ' group.dsc.resource.json' ,
61
+ ' powershell.dsc.resource.json' ,
62
+ ' psDscAdapter/' ,
63
+ ' RunCommandOnSet.dsc.resource.json' ,
64
+ ' runcommandonset'
65
+ )
48
66
49
67
function Find-LinkExe {
50
68
try {
@@ -61,8 +79,32 @@ function Find-LinkExe {
61
79
}
62
80
}
63
81
64
- if ($Msix -or $MsixBundle ) {
82
+ if ($null -ne $packageType ) {
65
83
$SkipBuild = $true
84
+ } else {
85
+ # # Test if Rust is installed
86
+ if (! (Get-Command ' cargo' - ErrorAction Ignore)) {
87
+ Write-Verbose - Verbose " Rust not found, installing..."
88
+ if (! $IsWindows ) {
89
+ curl https:// sh.rustup.rs - sSf | sh - s -- - y
90
+ $env: PATH += " :$env: HOME /.cargo/bin"
91
+ }
92
+ else {
93
+ Invoke-WebRequest ' https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe' - OutFile ' temp:/rustup-init.exe'
94
+ Write-Verbose - Verbose " Use the default settings to ensure build works"
95
+ & ' temp:/rustup-init.exe' - y
96
+ $env: PATH += " ;$env: USERPROFILE \.cargo\bin"
97
+ Remove-Item temp:/ rustup-init.exe - ErrorAction Ignore
98
+ }
99
+ }
100
+
101
+ if ($IsLinux -and (Test-Path / etc/ mariner- release)) {
102
+ tdnf install - y openssl- devel
103
+ }
104
+
105
+ $BuildToolsPath = " ${env: ProgramFiles(x86)} \Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
106
+
107
+ rustup default stable
66
108
}
67
109
68
110
if (! $SkipBuild -and ! $SkipLinkCheck -and $IsWindows -and ! (Get-Command ' link.exe' - ErrorAction Ignore)) {
@@ -111,35 +153,38 @@ else {
111
153
}
112
154
113
155
if (! $SkipBuild ) {
114
- if (Test-Path $target ) {
115
- Remove-Item $target - Recurse - ErrorAction Stop
116
- }
117
- New-Item - ItemType Directory $target > $null
118
-
119
- # make sure dependencies are built first so clippy runs correctly
120
- $windows_projects = @ (" pal" , " registry" , " reboot_pending" , " wmi-adapter" )
121
-
122
- # projects are in dependency order
123
- $projects = @ (
124
- " tree-sitter-dscexpression" ,
125
- " security_context_lib" ,
126
- " dsc_lib" ,
127
- " dsc" ,
128
- " osinfo" ,
129
- " powershell-adapter" ,
130
- " process" ,
131
- " tools/dsctest " ,
132
- " tools/test_group_resource " ,
133
- " y2j " ,
134
- " resources/brew " ,
135
- " runcommandonset "
136
- )
137
- $pedantic_unclean_projects = @ ()
138
- $clippy_unclean_projects = @ (" tree-sitter-dscexpression" )
139
- $skip_test_projects_on_windows = @ (" tree-sitter-dscexpression" )
156
+ if (Test-Path $target ) {
157
+ Remove-Item $target - Recurse - ErrorAction Ignore
158
+ }
159
+ New-Item - ItemType Directory $target - ErrorAction Ignore > $null
160
+
161
+ # make sure dependencies are built first so clippy runs correctly
162
+ $windows_projects = @ (" pal" , " registry" , " reboot_pending" , " wmi-adapter" )
163
+
164
+ # projects are in dependency order
165
+ $projects = @ (
166
+ " tree-sitter-dscexpression" ,
167
+ " security_context_lib" ,
168
+ " dsc_lib" ,
169
+ " dsc" ,
170
+ " osinfo" ,
171
+ " powershell-adapter" ,
172
+ " process" ,
173
+ " resources/brew " ,
174
+ " runcommandonset " ,
175
+ " tools/dsctest " ,
176
+ " tools/test_group_resource " ,
177
+ " y2j "
178
+ )
179
+ $pedantic_unclean_projects = @ ()
180
+ $clippy_unclean_projects = @ (" tree-sitter-dscexpression" )
181
+ $skip_test_projects_on_windows = @ (" tree-sitter-dscexpression" )
140
182
141
183
if ($IsWindows ) {
142
184
$projects += $windows_projects
185
+ Save-Module - Path $target - Name ' PSDesiredStateConfiguration' - RequiredVersion ' 2.0.7' - Repository PSGallery - Force
186
+ # Need to unhide all the files so that packaging works
187
+ Get-ChildItem - Path $target - Recurse - Hidden | ForEach-Object { $_.Attributes = ' Normal' }
143
188
}
144
189
145
190
$failed = $false
@@ -216,8 +261,8 @@ $skip_test_projects_on_windows = @("tree-sitter-dscexpression")
216
261
}
217
262
}
218
263
219
- $relative = Resolve-Path $target - Relative
220
- if ( ! $Clippy ) {
264
+ if ( ! $Clippy -and ! $SkipBuild ) {
265
+ $relative = Resolve-Path $target - Relative
221
266
Write-Host - ForegroundColor Green " `n EXE's are copied to $target ($relative )"
222
267
223
268
# remove the other target in case switching between them
@@ -318,7 +363,7 @@ function Find-MakeAppx() {
318
363
$makeappx = Get-Command makeappx - CommandType Application - ErrorAction Ignore
319
364
if ($null -eq $makeappx ) {
320
365
# try to find
321
- if ($architecture -eq ' aarch64-pc-windows-msvc' ) {
366
+ if (! $UseX64MakeAppx -and $architecture -eq ' aarch64-pc-windows-msvc' ) {
322
367
$arch = ' arm64'
323
368
}
324
369
else {
@@ -334,24 +379,19 @@ function Find-MakeAppx() {
334
379
$makeappx
335
380
}
336
381
337
- if ($MsixBundle ) {
338
- if ($Msix ) {
339
- throw " Creating MsixBundle requires all msix packages to already be created"
340
- }
382
+ $productVersion = ((Get-Content $PSScriptRoot / dsc/ Cargo.toml) -match ' ^version\s*=\s*' ) -replace ' version\s*=\s*"(.*?)"' , ' $1'
341
383
384
+ if ($packageType -eq ' msixbundle' ) {
342
385
if (! $IsWindows ) {
343
386
throw " MsixBundle is only supported on Windows"
344
387
}
345
388
346
- $productVersion = ((Get-Content $PSScriptRoot / dsc/ Cargo.toml) -match ' ^version\s*=\s*' ) -replace ' version\s*=\s*"(.*?)"' , ' $1'
347
- $isPreview = $productVersion -like ' *-*'
348
389
$packageName = " DSC-$productVersion -Win"
349
390
$makeappx = Find-MakeAppx
350
- & $makeappx bundle / d $PSScriptRoot / p " $PSScriptRoot \$packageName .msixbundle"
391
+ $msixPath = Join-Path $PSScriptRoot ' bin' ' msix'
392
+ & $makeappx bundle / d $msixPath / p " $PSScriptRoot \bin\$packageName .msixbundle"
351
393
return
352
- }
353
-
354
- if ($Msix ) {
394
+ } elseif ($packageType -eq ' msix' ) {
355
395
if (! $IsWindows ) {
356
396
throw " MSIX is only supported on Windows"
357
397
}
@@ -363,7 +403,6 @@ if ($Msix) {
363
403
$makeappx = Find-MakeAppx
364
404
$makepri = Get-Item (Join-Path $makeappx.Directory " makepri.exe" ) - ErrorAction Stop
365
405
$displayName = " DesiredStateConfiguration"
366
- $productVersion = ((Get-Content $PSScriptRoot / dsc/ Cargo.toml) -match ' ^version\s*=\s*' ) -replace ' version\s*=\s*"(.*?)"' , ' $1'
367
406
$isPreview = $productVersion -like ' *-*'
368
407
$productName = " DesiredStateConfiguration"
369
408
if ($isPreview ) {
@@ -389,25 +428,18 @@ if ($Msix) {
389
428
$appxManifest = $appxManifest.Replace (' $VERSION$' , $ProductVersion ).Replace(' $ARCH$' , $Arch ).Replace(' $PRODUCTNAME$' , $productName ).Replace(' $DISPLAYNAME$' , $displayName ).Replace(' $PUBLISHER$' , $releasePublisher )
390
429
$msixTarget = Join-Path $PSScriptRoot ' bin' $architecture ' msix'
391
430
if (Test-Path $msixTarget ) {
392
- Remove-Item $msixTarget - Recurse - ErrorAction Stop
431
+ Remove-Item $msixTarget - Recurse - ErrorAction Stop - Force
393
432
}
394
433
395
434
New-Item - ItemType Directory $msixTarget > $null
396
435
Set-Content - Path " $msixTarget \AppxManifest.xml" - Value $appxManifest - Force
397
436
398
- $filesForMsix = @ (
399
- ' dsc.exe' ,
400
- ' assertion.dsc.resource.json' ,
401
- ' group.dsc.resource.json' ,
402
- ' parallel.dsc.resource.json' ,
403
- ' powershellgroup.dsc.resource.json' ,
404
- ' powershellgroup.resource.ps1' ,
405
- ' wmigroup.dsc.resource.json.optout' ,
406
- ' wmigroup.resource.ps1'
407
- )
408
-
409
- foreach ($file in $filesForMsix ) {
410
- Copy-Item " $target \$file " $msixTarget - ErrorAction Stop
437
+ foreach ($file in $filesForWindowsPackage ) {
438
+ if ((Get-Item " $target \$file " ) -is [System.IO.DirectoryInfo ]) {
439
+ Copy-Item " $target \$file " " $msixTarget \$file " - Recurse - ErrorAction Stop
440
+ } else {
441
+ Copy-Item " $target \$file " $msixTarget - ErrorAction Stop
442
+ }
411
443
}
412
444
413
445
# Necessary image assets need to be in source assets folder
@@ -440,12 +472,69 @@ if ($Msix) {
440
472
}
441
473
442
474
Write-Verbose " Creating msix package" - Verbose
443
- $packageName = " $productName -$productVersion -$arch "
444
- & $makeappx pack / o / v / h SHA256 / d $msixTarget / p (Join-Path - Path (Get-Location ) - ChildPath " $packageName .msix" )
475
+
476
+ $targetFolder = Join-Path $PSScriptRoot ' bin' ' msix'
477
+ if (Test-Path $targetFolder ) {
478
+ Remove-Item $targetFolder - Recurse - ErrorAction Stop - Force
479
+ } else {
480
+ New-Item - ItemType Directory $targetFolder > $null
481
+ }
482
+
483
+ $packageName = Join-Path $targetFolder " $productName -$productVersion -$arch .msix"
484
+ & $makeappx pack / o / v / h SHA256 / d $msixTarget / p $packageName
445
485
if ($LASTEXITCODE -ne 0 ) {
446
486
throw " Failed to create msix package"
447
487
}
448
- Write-Verbose " Created $packageName .msix" - Verbose
488
+
489
+ Write-Host - ForegroundColor Green " `n MSIX package is created at $packageName .msix"
490
+ } elseif ($packageType -eq ' zip' ) {
491
+ $zipTarget = Join-Path $PSScriptRoot ' bin' $architecture ' zip'
492
+ if (Test-Path $zipTarget ) {
493
+ Remove-Item $zipTarget - Recurse - ErrorAction Stop - Force
494
+ }
495
+
496
+ New-Item - ItemType Directory $zipTarget > $null
497
+
498
+ foreach ($file in $filesForWindowsPackage ) {
499
+ if ((Get-Item " $target \$file " ) -is [System.IO.DirectoryInfo ]) {
500
+ Copy-Item " $target \$file " " $zipTarget \$file " - Recurse - ErrorAction Stop
501
+ } else {
502
+ Copy-Item " $target \$file " $zipTarget - ErrorAction Stop
503
+ }
504
+ }
505
+
506
+ $packageName = " DSC-$productVersion -$architecture .zip"
507
+ $zipFile = Join-Path $PSScriptRoot ' bin' $packageName
508
+ Compress-Archive - Path " $zipTarget /*" - DestinationPath $zipFile - Force
509
+ Write-Host - ForegroundColor Green " `n Zip file is created at $zipFile "
510
+ } elseif ($packageType -eq ' tgz' ) {
511
+ $tgzTarget = Join-Path $PSScriptRoot ' bin' $architecture ' tgz'
512
+ if (Test-Path $tgzTarget ) {
513
+ Remove-Item $tgzTarget - Recurse - ErrorAction Stop - Force
514
+ }
515
+
516
+ New-Item - ItemType Directory $tgzTarget > $null
517
+
518
+ if ($IsLinux ) {
519
+ $filesForPackage = $filesForLinuxPackage
520
+ } elseif ($IsMacOS ) {
521
+ $filesForPackage = $filesForMacPackage
522
+ } else {
523
+ Write-Error " Unsupported platform for tgz package"
524
+ }
525
+
526
+ foreach ($file in $filesForPackage ) {
527
+ if ((Get-Item " $target \$file " ) -is [System.IO.DirectoryInfo ]) {
528
+ Copy-Item " $target \$file " " $tgzTarget \$file " - Recurse - ErrorAction Stop
529
+ } else {
530
+ Copy-Item " $target \$file " $tgzTarget - ErrorAction Stop
531
+ }
532
+ }
533
+
534
+ $packageName = " DSC-$productVersion -$architecture .tar.gz"
535
+ $tgzFile = Join-Path $PSScriptRoot ' bin' $packageName
536
+ tar cvf $tgzFile - C $tgzTarget .
537
+ Write-Host - ForegroundColor Green " `n Tgz file is created at $tgzFile "
449
538
}
450
539
451
540
$env: RUST_BACKTRACE = 1
0 commit comments