Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/schemas/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"Kind": { "$ref": "#/$defs/ProjectKind" },
"SupportedPlatformOS": { "$ref": "#/$defs/ProjectSupportedPlatformOS" },
"IsRust": { "$ref": "#/$defs/ProjectIsRust" },
"RustPackageName": { "$ref": "#/$defs/ProjectRustPackageName" },
"TestOnly": { "$ref": "#/$defs/ProjectTestOnly" },
"SkipTest": { "$ref": "#/$defs/ProjectSkipTest" },
"ClippyUnclean": { "$ref": "#/$defs/ProjectClippyUnclean" },
Expand Down Expand Up @@ -70,6 +71,7 @@
"Kind": { "$ref": "#/$defs/ProjectKind" },
"SupportedPlatformOS": { "$ref": "#/$defs/ProjectSupportedPlatformOS" },
"IsRust": { "$ref": "#/$defs/ProjectIsRust" },
"RustPackageName": { "$ref": "#/$defs/ProjectRustPackageName" },
"TestOnly": { "$ref": "#/$defs/ProjectTestOnly" },
"SkipTest": { "$ref": "#/$defs/ProjectSkipTest" },
"ClippyUnclean": { "$ref": "#/$defs/ProjectClippyUnclean" },
Expand Down Expand Up @@ -190,6 +192,11 @@
"title": "Is Rust Crate",
"markdownDescription": "Indicates whether the project is a Rust crate."
},
"ProjectRustPackageName": {
"type": "string",
"title": "Rust package name",
"markdownDescription": "Defines the name of the rust project for the `-p` option on cargo commands."
},
"ProjectTestOnly": {
"type": "boolean",
"default": false,
Expand Down
8 changes: 3 additions & 5 deletions dsc-bicep-ext/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl BicepExtension for BicepExtensionService {
resource: Some(proto::Resource {
r#type: resource_type,
api_version: version,
identifiers: identifiers,
identifiers,
properties: result.actual_state.to_string(),
status: None,
}),
Expand Down Expand Up @@ -270,7 +270,7 @@ impl BicepExtension for BicepExtensionService {
resource: Some(proto::Resource {
r#type: resource_type,
api_version: version,
identifiers: identifiers,
identifiers,
properties: "{}".to_string(),
status: None,
}),
Expand Down Expand Up @@ -367,9 +367,7 @@ async fn run_server(
impl Connected for NamedPipeConnection {
type ConnectInfo = ();

fn connect_info(&self) -> Self::ConnectInfo {
()
}
fn connect_info(&self) -> Self::ConnectInfo {}
}

impl AsyncRead for NamedPipeConnection {
Expand Down
5 changes: 2 additions & 3 deletions dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn get(dsc: &mut DscManager, resource_type: &FullyQualifiedTypeName, version

match resource.get(input) {
Ok(result) => {
if let GetResult::Resource(response) = &result {
if format == Some(&GetOutputFormat::PassThrough) {
if let GetResult::Resource(response) = &result
&& format == Some(&GetOutputFormat::PassThrough) {
let json = match serde_json::to_string(&response.actual_state) {
Ok(json) => json,
Err(err) => {
Expand All @@ -46,7 +46,6 @@ pub fn get(dsc: &mut DscManager, resource_type: &FullyQualifiedTypeName, version
write_object(&json, Some(&OutputFormat::Json), false);
return;
}
}

// convert to json
let json = match serde_json::to_string(&result) {
Expand Down
10 changes: 4 additions & 6 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte

configurator.context.dsc_version = Some(env!("CARGO_PKG_VERSION").to_string());

if let ConfigSubCommand::Set { what_if , .. } = subcommand {
if *what_if {
configurator.context.execution_type = ExecutionKind::WhatIf;
}
if let ConfigSubCommand::Set { what_if , .. } = subcommand && *what_if {
configurator.context.execution_type = ExecutionKind::WhatIf;
}

let parameters: Option<serde_json::Value> = match if new_parameters.is_some() {
Expand Down Expand Up @@ -499,7 +497,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
let type_name = &FullyQualifiedTypeName::parse(type_name)?;
let require_version = resource_block["requireVersion"]
.as_str()
.map(|r| ResourceVersionReq::parse(r))
.map(ResourceVersionReq::parse)
.transpose()?;
resource_types.push(DiscoveryFilter::new(type_name, require_version, None));
}
Expand All @@ -512,7 +510,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
let type_name = &FullyQualifiedTypeName::parse(type_name)?;
let require_version = resource_block["requireVersion"]
.as_str()
.map(|r| ResourceVersionReq::parse(r))
.map(ResourceVersionReq::parse)
.transpose()?;

trace!("{} '{}'", t!("subcommand.validatingResource"), resource_block["name"].as_str().unwrap_or_default());
Expand Down
22 changes: 10 additions & 12 deletions dsc/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,16 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
}

// override with DSC_TRACE_LEVEL env var if permitted
if tracing_setting.allow_override {
if let Ok(level) = env::var(DSC_TRACE_LEVEL) {
tracing_setting.level = match level.to_ascii_uppercase().as_str() {
"ERROR" => TraceLevel::Error,
"WARN" => TraceLevel::Warn,
"INFO" => TraceLevel::Info,
"DEBUG" => TraceLevel::Debug,
"TRACE" => TraceLevel::Trace,
_ => {
warn!("{}: '{level}'", t!("util.invalidTraceLevel"));
TraceLevel::Warn
}
if tracing_setting.allow_override && let Ok(level) = env::var(DSC_TRACE_LEVEL) {
tracing_setting.level = match level.to_ascii_uppercase().as_str() {
"ERROR" => TraceLevel::Error,
"WARN" => TraceLevel::Warn,
"INFO" => TraceLevel::Info,
"DEBUG" => TraceLevel::Debug,
"TRACE" => TraceLevel::Trace,
_ => {
warn!("{}: '{level}'", t!("util.invalidTraceLevel"));
TraceLevel::Warn
}
}
}
Expand Down
140 changes: 130 additions & 10 deletions helpers.build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DscProjectDefinition {
[string] $RelativePath
[string] $Kind
[bool] $IsRust
[string] $RustPackageName
[bool] $ClippyUnclean
[bool] $ClippyPedanticUnclean
[bool] $SkipTestProject
Expand All @@ -38,6 +39,17 @@ class DscProjectDefinition {
[DscProjectCopyFiles] $CopyFiles
[DscProjectSkipTest] $SkipTest

[string[]] ToPackageFlags() {
if (-not $this.IsRust) {
return $null
}

return @(
'-p'
$this.RustPackageName ?? $this.Name
)
}

[string] ToJson([bool]$forBuild) {
$json = $this.ToData($forBuild) | ConvertTo-Json -Depth 5 -EnumsAsStrings
return ($json -replace "`r`n", "`n")
Expand Down Expand Up @@ -68,6 +80,9 @@ class DscProjectDefinition {
}
if ($this.IsRust) {
$data.IsRust = $true
if (-not [string]::IsNullOrEmpty($this.RustPackageName)) {
$data.RustPackageName = $this.RustPackageName
}
if ($this.ClippyPedanticUnclean) {
$data.ClippyPedanticUnclean = $true
}
Expand Down Expand Up @@ -1416,6 +1431,113 @@ function Export-GrammarBinding {
}
}
}

function Test-Clippy {
[CmdletBinding()]
param(
[DscProjectDefinition[]]$Project,
[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]$Release,
[switch]$NoModifyWorkspace
)

begin {
$flags = @($Release ? '-r' : $null)
if ($Architecture -ne 'current') {
$flags += '--target'
$flags += $Architecture
$memberGroup = if ($Architecture -match 'linux') {
'Linux'
} elseif ($Architecture -match 'darwin') {
'macOS'
} elseif ($Architecture -match 'windows') {
'Windows'
} else {
throw "Unsupported architecture '$Architecture'"
}
} else {
$memberGroup = if ($IsLinux) {
'Linux'
} elseif ($IsMacOS) {
'macOS'
} elseif ($IsWindows) {
'Windows'
}
}
$workspaceParams = @{
MemberGroup = $memberGroup
}
if ($VerbosePreference -eq 'Continue') {
$workspaceParams.Verbose = $true
}
if (-not $NoModifyWorkspace) {
Set-DefaultWorkspaceMemberGroup @workspaceParams
}
}

process {
$clippyFlags = @(
'--%'
'--'
'-Dwarnings' # Treat warnings as errors
'--no-deps' # Only lint DSC projects, not dependencies
)
# Collect projects to lint into two groups:
# - Normal projects get linting without pedantic checks
# - Pedantic projects get stricter linting
[DscProjectDefinition[]]$normalProjects = @()
[DscProjectDefinition[]]$pedanticProjects = @()
foreach ($p in $Project) {
if (
-not $p.IsRust -or
$p.ClippyUnclean -or
(Test-ShouldSkipProject -Project $p -Architecture $Architecture)
) {
continue
}

if ($p.ClippyPedanticUnclean) {
$pedanticProjects += $p
} else {
$normalProjects += $p
}
}
$normalProjectsExitCode = 0
$pedanticProjectsExitCode = 0
if ($normalProjects.count -gt 0) {
[string[]]$projectFlags = $normalProjects.ToPackageFlags()
Write-Verbose "Linting rust projects with clippy: $($normalProjects.Name | ConvertTo-Json)"
Write-Verbose "Invoking clippy: cargo clippy $flags $projectFlags $clippyFlags"
cargo clippy @flags @projectFlags @clippyFlags

if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) {
$normalProjectsExitCode = $LASTEXITCODE
}
}
if ($pedanticProjects.count -gt 0) {
[string[]]$projectFlags = $pedanticProjects.ToPackageFlags()
$clippyFlags += '-Dclippy::pedantic'
Write-Verbose "Linting rust projects with clippy (pedantic): $($pedanticProjects.Name | ConvertTo-Json)"
Write-Verbose "Invoking clippy: cargo clippy $flags $projectFlags $clippyFlags"
cargo clippy @flags @projectFlags @clippyFlags

if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) {
$pedanticProjectsExitCode = $LASTEXITCODE
}
}
if ($normalProjectsExitCode -or $pedanticProjectsExitCode) {
throw "Clippy failed for at least one project"
}
}

clean {
if (-not $NoModifyWorkspace) {
Reset-DefaultWorkspaceMemberGroup
}
}
}

function Build-RustProject {
[CmdletBinding()]
param(
Expand Down Expand Up @@ -1475,18 +1597,16 @@ function Build-RustProject {
cargo clean
}

if ($Clippy -and !$Project.ClippyUnclean) {
$clippyFlags = @()
if (!$Project.ClippyPedanticUnclean) {
cargo clippy @clippyFlags --% -- -Dclippy::pedantic --no-deps -Dwarnings
} else {
cargo clippy @clippyFlags --% -- -Dwarnings --no-deps
}

if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) {
throw "Last exit code is $LASTEXITCODE, clippy failed for at least one project"
if ($Clippy) {
$clippyParams = @{
Project = $Project
Architecture = $Architecture
Release = $Release
NoModifyWorkspace = $true
}
Test-Clippy @clippyParams
}

$members = Get-DefaultWorkspaceMemberGroup
Write-Verbose -Verbose "Building rust projects: [$members]"
Write-Verbose "Invoking cargo:`n`tcargo build $flags"
Expand Down
4 changes: 1 addition & 3 deletions lib/dsc-lib-jsonschema/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,7 @@ fn main() {
let version_data = read_to_string(data_path)
.expect("Failed to read .versions.json file");
let version_info: VersionInfo = serde_json::from_str(&version_data)
.expect(format!(
"Failed to parse version data from .versions.json:\n---FILE TEXT START---\n{version_data}\n---FILE TEXT END---\n"
).as_str());
.unwrap_or_else(|_| panic!("Failed to parse version data from .versions.json:\n---FILE TEXT START---\n{version_data}\n---FILE TEXT END---\n"));
let contents = format_file_content(&version_info);

fs::write(
Expand Down
Loading
Loading