Skip to content

Commit 72dbf6b

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
Merge branch 'v3.2-p4' into v3.2-p4-merge
2 parents 2ec12b9 + 12a5faf commit 72dbf6b

File tree

10 files changed

+361
-290
lines changed

10 files changed

+361
-290
lines changed

.cargo/config.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-arg
1919
[source.crates-io]
2020
replace-with = "POWERSHELL"
2121

22-
[target.aarch64-unknown-linux-gnu]
23-
linker = "aarch64-linux-gnu-gcc"
22+
#[target.aarch64-unknown-linux-gnu]
23+
#linker = "aarch64-linux-gnu-gcc"
2424

25-
[target.aarch64-unknown-linux-musl]
26-
linker = "aarch64-linux-musl-gcc"
25+
#[target.aarch64-unknown-linux-musl]
26+
#linker = "aarch64-linux-musl-gcc"

.pipelines/DSC-Official.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ pr:
77
- onebranch
88
- release/v*
99

10+
parameters:
11+
- name: OfficialBuild
12+
type: boolean
13+
default: false
14+
1015
variables:
1116
- name: BuildConfiguration
1217
value: 'release'
@@ -16,7 +21,11 @@ variables:
1621
value: 'onebranch.azurecr.io/windows/ltsc2022/vse2022:latest'
1722
- name: Codeql.TSAEnabled
1823
value: true
24+
- name: templateFile
25+
value: ${{ iif ( parameters.OfficialBuild, 'v2/OneBranch.Official.CrossPlat.yml@onebranchTemplates', 'v2/OneBranch.NonOfficial.CrossPlat.yml@onebranchTemplates' ) }}
1926
- group: DSC-Rust.SDK
27+
- name: officialBuild
28+
value: ${{ parameters.OfficialBuild }}
2029

2130
resources:
2231
repositories:
@@ -26,7 +35,7 @@ resources:
2635
ref: refs/heads/main
2736

2837
extends:
29-
template: v2/OneBranch.Official.CrossPlat.yml@onebranchTemplates
38+
template: ${{ variables.templateFile }}
3039
parameters:
3140
featureFlags:
3241
WindowsHostVersion:
@@ -110,15 +119,16 @@ extends:
110119
buildName: x86_64-pc-windows-msvc
111120
signSrcPath: '$(signSrcPath)'
112121
PackageRoot: '$(PackageRoot)'
113-
token: '$(AzToken)'
114-
rustSDK: $(Rust.SDK)
122+
aztoken: '$(AzToken)'
123+
rustSDK: '$(Rust.SDK)'
115124

116125
- job: BuildWin_arm64
117126
dependsOn: SetPackageVersion
118127
variables:
119128
ob_sdl_tsa_configFile: '$(Build.SourcesDirectory)\DSC\.config\tsaoptions.json'
120129
ob_outputDirectory: '$(Build.ArtifactStagingDirectory)'
121130
signSrcPath: '$(Build.SourcesDirectory)\out'
131+
AzToken: $[ dependencies.SetPackageVersion.outputs['AzToken'] ]
122132
ob_sdl_sbom_enabled: true
123133
ob_signing_setup_enabled: true
124134
ob_sdl_codeql_compiled_enabled: true
@@ -130,8 +140,8 @@ extends:
130140
buildName: aarch64-pc-windows-msvc
131141
signSrcPath: '$(signSrcPath)'
132142
PackageRoot: '$(PackageRoot)'
133-
token: '$(AzToken)'
134-
rustSDK: $(Rust.SDK)
143+
aztoken: '$(AzToken)'
144+
rustSDK: '$(Rust.SDK)'
135145

136146
- job: CreateMsixBundle
137147
dependsOn:
@@ -169,6 +179,7 @@ extends:
169179
condition: succeeded()
170180
171181
- job: SignMsixBundle
182+
condition: and(succeeded(), eq(variables.officialBuild, true))
172183
dependsOn: CreateMsixBundle
173184
variables:
174185
ob_outputDirectory: '$(Build.ArtifactStagingDirectory)'
@@ -223,7 +234,7 @@ extends:
223234
- pwsh: |
224235
apt update
225236
apt -y install musl-tools
226-
$header = "Bearer $accessToken"
237+
$header = "Bearer $(AzToken)"
227238
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
228239
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
229240
./build.ps1 -Release -Architecture x86_64-unknown-linux-musl
@@ -271,15 +282,15 @@ extends:
271282
apt -y install clang
272283
apt -y install llvm
273284
apt -y install musl-tools
274-
apt -y install musi-gcc
285+
apt -y install musl-gcc
275286
#apt -y install gcc-multilib
276287
apt -y install libssl-dev
277288
apt -y install pkg-config
278289
msrustup default stable-aarch64-unknown-linux-musl
279290
if ((openssl version -d) -match 'OPENSSLDIR: "(?<dir>.*?)"') {
280291
$env:OPENSSL_LIB_DIR = $matches['dir']
281292
}
282-
$header = "Bearer $accessToken"
293+
$header = "Bearer $(AzToken)"
283294
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
284295
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
285296
./build.ps1 -Release -Architecture aarch64-unknown-linux-musl
@@ -324,9 +335,10 @@ extends:
324335
inlineScript: |
325336
az account show
326337
- pwsh: |
327-
$header = "Bearer $accessToken"
338+
$header = "Bearer $(AzToken)"
328339
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
329340
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
341+
Write-Verbose -Verbose "Building for $(buildName)"
330342
./build.ps1 -Release -Architecture $(buildName)
331343
./build.ps1 -PackageType tgz -Architecture $(buildName) -Release
332344
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"

.pipelines/DSC-Windows.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ parameters:
88
- name: BuildConfiguration
99
type: string
1010
default: Release
11-
- name: token
11+
- name: aztoken
12+
type: string
13+
- name: RustSDK
1214
type: string
1315
- name: RustSDK
1416
type: string
@@ -39,7 +41,7 @@ steps:
3941
env:
4042
ob_restore_phase: true
4143
- pwsh: |
42-
$header = "Bearer ${ parameters.token }"
44+
$header = "Bearer ${{ parameters.aztoken }}"
4345
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
4446
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
4547
Set-Location "$(Build.SourcesDirectory)/DSC"
@@ -49,6 +51,7 @@ steps:
4951
}
5052
$env:PATH += ";$LLVMBIN"
5153
write-verbose -verbose (gcm clang.exe | out-string)
54+
Write-Verbose -Verbose "Building for ${{ parameters.buildName }}"
5255
./build.ps1 -Release -Architecture ${{ parameters.buildName }} -SkipLinkCheck
5356
displayName: 'Build ${{ parameters.buildName }}'
5457
env:

build.ps1

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,8 @@ function Find-LinkExe {
155155
}
156156

157157
$channel = 'stable'
158-
$rustup = 'echo'
159-
if ($usingADO) {
160-
return
161-
} elseif ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore)) {
158+
if ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore)) {
159+
Write-Verbose -Verbose "Using msrustup"
162160
$rustup = 'msrustup'
163161
$channel = 'ms-stable'
164162
if ($architecture -eq 'current') {
@@ -172,7 +170,7 @@ if ($null -ne $packageType) {
172170
$SkipBuild = $true
173171
} else {
174172
## Test if Rust is installed
175-
if (!(Get-Command 'cargo' -ErrorAction Ignore)) {
173+
if (!$usingADO -and !(Get-Command 'cargo' -ErrorAction Ignore)) {
176174
Write-Verbose -Verbose "Rust not found, installing..."
177175
if (!$IsWindows) {
178176
curl https://sh.rustup.rs -sSf | sh -s -- -y
@@ -185,13 +183,18 @@ if ($null -ne $packageType) {
185183
$env:PATH += ";$env:USERPROFILE\.cargo\bin"
186184
Remove-Item temp:/rustup-init.exe -ErrorAction Ignore
187185
}
186+
if ($LASTEXITCODE -ne 0) {
187+
throw "Failed to install Rust"
188+
}
188189
}
189-
else {
190+
elseif (!$usingADO) {
190191
Write-Verbose -Verbose "Rust found, updating..."
191192
& $rustup update
192193
}
193194

194-
$BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
195+
if ($IsWindows) {
196+
$BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
197+
}
195198

196199
if (!$usingADO) {
197200
& $rustup default stable
@@ -216,6 +219,18 @@ if ($null -ne $packageType) {
216219
Write-Warning "winget not found, please install Node.js manually"
217220
}
218221
}
222+
if ($LASTEXITCODE -ne 0) {
223+
throw "Failed to install Node.js"
224+
}
225+
}
226+
227+
## Test if tree-sitter is installed
228+
if ($null -eq (Get-Command tree-sitter -ErrorAction Ignore)) {
229+
Write-Verbose -Verbose "tree-sitter not found, installing..."
230+
cargo install tree-sitter-cli --config .cargo/config.toml
231+
if ($LASTEXITCODE -ne 0) {
232+
throw "Failed to install tree-sitter-cli"
233+
}
219234
}
220235
}
221236

@@ -350,9 +365,10 @@ if (!$SkipBuild) {
350365
$failed = $false
351366
foreach ($project in $projects) {
352367
## Build format_json
353-
Write-Host -ForegroundColor Cyan "Building $project ... for $architecture"
368+
Write-Host -ForegroundColor Cyan "Building '$project' for $architecture"
354369
try {
355370
Push-Location "$PSScriptRoot/$project" -ErrorAction Stop
371+
Write-Verbose -Verbose "Current directory is $(Get-Location)"
356372

357373
# check if the project is either tree-sitter-dscexpression or tree-sitter-ssh-server-config
358374
if (($project -eq 'tree-sitter-dscexpression') -or ($project -eq 'tree-sitter-ssh-server-config')) {
@@ -362,12 +378,13 @@ if (!$SkipBuild) {
362378
else {
363379
if ($Audit) {
364380
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
365-
cargo install cargo-audit --features=fix
381+
cargo install cargo-audit --features=fix --config .cargo/config.toml
366382
}
367383

368384
cargo audit fix
369385
}
370386

387+
Write-Verbose -Verbose "Running build.ps1 for $project"
371388
./build.ps1
372389
}
373390
}
@@ -394,7 +411,7 @@ if (!$SkipBuild) {
394411
else {
395412
if ($Audit) {
396413
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
397-
cargo install cargo-audit --features=fix
414+
cargo install cargo-audit --features=fix --config .cargo/config.toml
398415
}
399416

400417
cargo audit fix
@@ -404,12 +421,14 @@ if (!$SkipBuild) {
404421
cargo clean
405422
}
406423

424+
Write-Verbose -Verbose "Building $project"
407425
cargo build @flags
408426
}
409427
}
410428
}
411429

412-
if ($LASTEXITCODE -ne 0) {
430+
if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) {
431+
Write-Error "Last exit code is $LASTEXITCODE, build failed for '$project'"
413432
$failed = $true
414433
break
415434
}
@@ -458,7 +477,10 @@ if (!$SkipBuild) {
458477
}
459478
}
460479
}
461-
480+
} catch {
481+
Write-Error "Failed to build $project : $($_ | Out-String)"
482+
$failed = $true
483+
break
462484
} finally {
463485
Pop-Location
464486
}

dsc_lib/src/extensions/discover.rs

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
use crate::dscresources::resource_manifest::ArgKind;
4+
use crate::{
5+
discovery::command_discovery::{
6+
load_manifest, ImportedManifest
7+
},
8+
dscerror::DscError,
9+
dscresources::{
10+
command_resource::{
11+
invoke_command, process_args
12+
},
13+
dscresource::DscResource,
14+
resource_manifest::ArgKind,
15+
},
16+
extensions::{
17+
dscextension::{
18+
Capability,
19+
DscExtension,
20+
},
21+
extension_manifest::ExtensionManifest,
22+
},
23+
};
24+
use rust_i18n::t;
525
use schemars::JsonSchema;
626
use serde::{Deserialize, Serialize};
27+
use std::path::Path;
28+
use tracing::{info, trace};
729

830
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
931
pub struct DiscoverMethod {
@@ -19,3 +41,67 @@ pub struct DiscoverResult {
1941
#[serde(rename = "manifestPath")]
2042
pub manifest_path: String,
2143
}
44+
45+
impl DscExtension {
46+
/// Perform discovery of resources using the extension.
47+
///
48+
/// # Returns
49+
///
50+
/// A result containing a vector of discovered resources or an error.
51+
///
52+
/// # Errors
53+
///
54+
/// This function will return an error if the discovery fails.
55+
pub fn discover(&self) -> Result<Vec<DscResource>, DscError> {
56+
let mut resources: Vec<DscResource> = Vec::new();
57+
58+
if self.capabilities.contains(&Capability::Discover) {
59+
let extension = match serde_json::from_value::<ExtensionManifest>(self.manifest.clone()) {
60+
Ok(manifest) => manifest,
61+
Err(err) => {
62+
return Err(DscError::Manifest(self.type_name.clone(), err));
63+
}
64+
};
65+
let Some(discover) = extension.discover else {
66+
return Err(DscError::UnsupportedCapability(self.type_name.clone(), Capability::Discover.to_string()));
67+
};
68+
let args = process_args(discover.args.as_ref(), "");
69+
let (_exit_code, stdout, _stderr) = invoke_command(
70+
&discover.executable,
71+
args,
72+
None,
73+
Some(self.directory.as_str()),
74+
None,
75+
extension.exit_codes.as_ref(),
76+
)?;
77+
if stdout.is_empty() {
78+
info!("{}", t!("extensions.dscextension.discoverNoResults", extension = self.type_name));
79+
} else {
80+
for line in stdout.lines() {
81+
trace!("{}", t!("extensions.dscextension.extensionReturned", extension = self.type_name, line = line));
82+
let discover_result: DiscoverResult = match serde_json::from_str(line) {
83+
Ok(result) => result,
84+
Err(err) => {
85+
return Err(DscError::Json(err));
86+
}
87+
};
88+
if !Path::new(&discover_result.manifest_path).is_absolute() {
89+
return Err(DscError::Extension(t!("extensions.dscextension.discoverNotAbsolutePath", extension = self.type_name.clone(), path = discover_result.manifest_path.clone()).to_string()));
90+
}
91+
let manifest_path = Path::new(&discover_result.manifest_path);
92+
// Currently we don't support extensions discovering other extensions
93+
if let ImportedManifest::Resource(resource) = load_manifest(manifest_path)? {
94+
resources.push(resource);
95+
}
96+
}
97+
}
98+
99+
Ok(resources)
100+
} else {
101+
Err(DscError::UnsupportedCapability(
102+
self.type_name.clone(),
103+
Capability::Discover.to_string()
104+
))
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)