Skip to content

Commit 8ce3724

Browse files
author
Andrew
committed
Merge branch 'rename_type_prop' of https://github.com/anmenaga/DSC-New into rename_type_prop
2 parents 8c95c84 + 55b152f commit 8ce3724

File tree

14 files changed

+97
-81
lines changed

14 files changed

+97
-81
lines changed

.cargo/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ registry-auth = true
55
[registries]
66
powershell = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" }
77

8+
[registry]
9+
global-credential-providers = ["cargo:token"]
10+
811
# Enable Control Flow Guard (needed for OneBranch's post-build analysis).
912
[target.x86_64-pc-windows-msvc]
1013
rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE /CETCOMPAT"]
1114

1215
[target.aarch64-windows-msvc]
1316
rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE"]
17+
18+
# The following is only needed for release builds
19+
[source.crates-io]
20+
replace-with = "powershell"

.pipelines/DSC-Official.yml

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ extends:
141141
ob_restore_phase: true
142142
- pwsh: |
143143
Set-Location "$(Build.SourcesDirectory)/DSC"
144-
Write-Host "Use 'powershell' CFS"
145-
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
146-
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
147-
Add-Content -Path "./.cargo/config.toml" -Value '[registry]'
148-
Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]'
149-
150-
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck
144+
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck -UseCFS
151145
displayName: 'Build $(buildName)'
152146
env:
153147
ob_restore_phase: true
@@ -279,13 +273,7 @@ extends:
279273
env:
280274
ob_restore_phase: true
281275
- pwsh: |
282-
Write-Host "Use 'powershell' CFS"
283-
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
284-
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
285-
Add-Content -Path "./.cargo/config.toml" -Value '[registry]'
286-
Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]'
287-
288-
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu
276+
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu -UseCFS
289277
./build.ps1 -PackageType tgz -Architecture x86_64-unknown-linux-gnu -Release
290278
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
291279
displayName: 'Build x86_64-unknown-linux-gnu'
@@ -325,13 +313,7 @@ extends:
325313
env:
326314
ob_restore_phase: true
327315
- pwsh: |
328-
Write-Host "Use 'powershell' CFS"
329-
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
330-
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
331-
Add-Content -Path "./.cargo/config.toml" -Value '[registry]'
332-
Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]'
333-
334-
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu
316+
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu -UseCFS
335317
./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-gnu -Release
336318
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
337319
displayName: 'Build aarch64-unknown-linux-gnu'
@@ -379,18 +361,7 @@ extends:
379361
env:
380362
ob_restore_phase: true
381363
- pwsh: |
382-
Write-Host "Use 'powershell' CFS"
383-
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
384-
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
385-
Add-Content -Path "./.cargo/config.toml" -Value '[registry]'
386-
Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]'
387-
388-
$c = get-content "./.cargo/config.toml" | Out-String
389-
Write-Host $c
390-
391-
$env:CARGO_HTTP_DEBUG=true
392-
$env:CARGO_LOG='network=trace'
393-
./build.ps1 -Release -Architecture $(buildName)
364+
./build.ps1 -Release -Architecture $(buildName) -UseCFS
394365
./build.ps1 -PackageType tgz -Architecture $(buildName) -Release
395366
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
396367
Write-Host "##vso[artifact.upload containerfolder=release;artifactname=release]$(ob_outputDirectory)/DSC-$(PackageVersion)-$(buildName).tar.gz"

archive/registry/.cargo/config.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

build.ps1

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ param(
77
$architecture = 'current',
88
[switch]$Clippy,
99
[switch]$SkipBuild,
10-
[ValidateSet('msix','msixbundle','tgz','zip')]
10+
[ValidateSet('msix','msix-private','msixbundle','tgz','zip')]
1111
$packageType,
1212
[switch]$Test,
1313
[switch]$GetPackageVersion,
1414
[switch]$SkipLinkCheck,
15-
[switch]$UseX64MakeAppx
15+
[switch]$UseX64MakeAppx,
16+
[switch]$UseCFS
1617
)
1718

1819
if ($GetPackageVersion) {
@@ -171,6 +172,17 @@ if (!$SkipBuild) {
171172
}
172173
New-Item -ItemType Directory $target -ErrorAction Ignore > $null
173174

175+
if (!$UseCFS) {
176+
# this will override the config.toml
177+
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
178+
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
179+
$env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/'
180+
} else {
181+
Write-Host "Using CFS for cargo source replacement"
182+
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
183+
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
184+
}
185+
174186
# make sure dependencies are built first so clippy runs correctly
175187
$windows_projects = @("pal", "registry", "reboot_pending", "wmi-adapter")
176188

@@ -240,6 +252,7 @@ if (!$SkipBuild) {
240252

241253
if ($LASTEXITCODE -ne 0) {
242254
$failed = $true
255+
break
243256
}
244257

245258
$binary = Split-Path $project -Leaf
@@ -424,7 +437,7 @@ if ($packageType -eq 'msixbundle') {
424437
$msixPath = Join-Path $PSScriptRoot 'bin' 'msix'
425438
& $makeappx bundle /d $msixPath /p "$PSScriptRoot\bin\$packageName.msixbundle"
426439
return
427-
} elseif ($packageType -eq 'msix') {
440+
} elseif ($packageType -eq 'msix' -or $packageType -eq 'msix-private') {
428441
if (!$IsWindows) {
429442
throw "MSIX is only supported on Windows"
430443
}
@@ -433,21 +446,34 @@ if ($packageType -eq 'msixbundle') {
433446
throw 'MSIX requires a specific architecture'
434447
}
435448

449+
$isPrivate = $packageType -eq 'msix-private'
450+
436451
$makeappx = Find-MakeAppx
437452
$makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop
438453
$displayName = "DesiredStateConfiguration"
439454
$isPreview = $productVersion -like '*-*'
440455
$productName = "DesiredStateConfiguration"
441456
if ($isPreview) {
442457
Write-Verbose -Verbose "Preview version detected"
443-
$productName += "-Preview"
458+
if ($isPrivate) {
459+
$productName += "-Private"
460+
}
461+
else {
462+
$productName += "-Preview"
463+
}
444464
# save preview number
445465
$previewNumber = $productVersion -replace '.*?-[a-z]+\.([0-9]+)', '$1'
446466
# remove label from version
447467
$productVersion = $productVersion.Split('-')[0]
448468
# replace revision number with preview number
449469
$productVersion = $productVersion -replace '(\d+)$', "$previewNumber.0"
450-
$displayName += "-Preview"
470+
471+
if ($isPrivate) {
472+
$displayName += "-Private"
473+
}
474+
else {
475+
$displayName += "-Preview"
476+
}
451477
}
452478
Write-Verbose -Verbose "Product version is $productVersion"
453479
$arch = if ($architecture -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' }
@@ -519,7 +545,7 @@ if ($packageType -eq 'msixbundle') {
519545
throw "Failed to create msix package"
520546
}
521547

522-
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName.msix"
548+
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName"
523549
} elseif ($packageType -eq 'zip') {
524550
$zipTarget = Join-Path $PSScriptRoot 'bin' $architecture 'zip'
525551
if (Test-Path $zipTarget) {

dsc/.cargo/config.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

dsc/src/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fn main() {
2626
#[cfg(debug_assertions)]
2727
check_debug();
2828

29+
#[cfg(windows)]
30+
check_store();
31+
2932
if ctrlc::set_handler(ctrlc_handler).is_err() {
3033
error!("Error: Failed to set Ctrl-C handler");
3134
}
@@ -156,3 +159,38 @@ fn check_debug() {
156159
}
157160
}
158161
}
162+
163+
// Check if the dsc binary parent process is WinStore.App or Exploerer.exe
164+
#[cfg(windows)]
165+
fn check_store() {
166+
let message = r"
167+
DSC.exe is a command-line tool and cannot be run directly from the Windows Store or Explorer.
168+
Visit https://aka.ms/dscv3-docs for more information on how to use DSC.exe.
169+
170+
Press any key to close this window
171+
";
172+
let sys = System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()));
173+
// get current process
174+
let Ok(current_pid) = get_current_pid() else {
175+
return;
176+
};
177+
178+
// get parent process
179+
let Some(current_process) = sys.process(current_pid) else {
180+
return;
181+
};
182+
let Some(parent_process_pid) = current_process.parent() else {
183+
return;
184+
};
185+
let Some(parent_process) = sys.process(parent_process_pid) else {
186+
return;
187+
};
188+
189+
// MS Store runs app using `sihost.exe`
190+
if parent_process.name().to_lowercase() == "sihost.exe" || parent_process.name().to_lowercase() == "explorer.exe"{
191+
eprintln!("{message}");
192+
// wait for keypress
193+
let _ = io::stdin().read(&mut [0u8]).unwrap();
194+
exit(util::EXIT_INVALID_ARGS);
195+
}
196+
}

dsc_lib/.cargo/config.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

osinfo/.cargo/config.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

powershell-adapter/Tests/win_powershellgroup.tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ Describe 'WindowsPowerShell adapter resource tests' {
4343
$res.actualState.result.properties.DestinationPath | Should -Be "$testFile"
4444
}
4545

46+
It 'Set works on Binary "File" resource' -Skip:(!$IsWindows){
47+
48+
$testFile = "$testdrive\test.txt"
49+
$r = '{"DestinationPath":"' + $testFile.replace('\','\\') + '", type: File, contents: HelloWorld, Ensure: present}' | dsc resource set -r 'PSDesiredStateConfiguration/File'
50+
$LASTEXITCODE | Should -Be 0
51+
Get-Content -Raw -Path $testFile | Should -Be "HelloWorld"
52+
}
53+
4654
It 'Get works on traditional "Script" resource' -Skip:(!$IsWindows){
4755

4856
$testFile = "$testdrive\test.txt"

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,15 @@ function Invoke-DscOperation {
355355
$invokeResult = Invoke-DscResource -Method $Operation -ModuleName $cachedDscResourceInfo.ModuleName -Name $cachedDscResourceInfo.Name -Property $property
356356

357357
if ($invokeResult.GetType().Name -eq 'Hashtable') {
358-
$invokeResult.keys | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $invokeResult.$_ }
358+
$invokeResult.keys | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
359359
}
360360
else {
361361
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
362-
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $invokeResult.$_ }
362+
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
363363
}
364364

365365
# set the properties of the OUTPUT object from the result of Get-TargetResource
366-
$addToActualState.properties = $getDscResult
366+
$addToActualState.properties = $ResultProperties
367367
}
368368
catch {
369369
'ERROR: ' + $_.Exception.Message | Write-DscTrace
@@ -422,21 +422,19 @@ function Invoke-DscOperation {
422422

423423
# morph the INPUT object into a hashtable named "property" for the cmdlet Invoke-DscResource
424424
$DesiredState.properties.psobject.properties | ForEach-Object -Begin { $property = @{} } -Process { $property[$_.Name] = $_.Value }
425-
426425
# using the cmdlet from PSDesiredStateConfiguration module in Windows
427426
try {
428-
$getResult = $PSDesiredStateConfiguration.invoke({ param($Name, $Property) Invoke-DscResource -Name $Name -Method Get -ModuleName @{ModuleName = 'PSDesiredStateConfiguration'; ModuleVersion = '1.1' } -Property $Property -ErrorAction Stop }, $cachedDscResourceInfo.Name, $property )
429-
430-
if ($getResult.GetType().Name -eq 'Hashtable') {
431-
$getResult.keys | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
427+
$invokeResult = Invoke-DscResource -Method $Operation -ModuleName $cachedDscResourceInfo.ModuleName -Name $cachedDscResourceInfo.Name -Property $property
428+
if ($invokeResult.GetType().Name -eq 'Hashtable') {
429+
$invokeResult.keys | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
432430
}
433431
else {
434432
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
435-
$getResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
433+
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
436434
}
437435

438436
# set the properties of the OUTPUT object from the result of Get-TargetResource
439-
$addToActualState.properties = $getDscResult
437+
$addToActualState.properties = $ResultProperties
440438
}
441439
catch {
442440
'ERROR: ' + $_.Exception.Message | Write-DscTrace

0 commit comments

Comments
 (0)