From 4486203864911157c5f7557b6b7d1497aadcb026 Mon Sep 17 00:00:00 2001 From: Mikey Lombardi Date: Tue, 16 Dec 2025 08:59:44 -0600 Subject: [PATCH] (MAINT) Fix Rust build script for `dsc-lib-jsonschema` This change makes a few changes for debugging and fixing the `build.rs` script in the `dsc-lib-jsonschema` crate for improved debugging and usage: - Adds a shebang to `.versions.ps1` (which is called by `build.rs`) for easier interactive invocation. - Sets the permissions for `.versions.ps1` to `755`. - Throws an error in `.versions.ps1` when unable to fetch git tags. - Enhances the error message for an unparseable data file to include the file text instead of simply saying it couldn't be parsed. - Only rebuilds the version data for `debug` builds, not release. --- lib/dsc-lib-jsonschema/.versions.ps1 | 9 ++++++++- lib/dsc-lib-jsonschema/build.rs | 27 +++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) mode change 100644 => 100755 lib/dsc-lib-jsonschema/.versions.ps1 diff --git a/lib/dsc-lib-jsonschema/.versions.ps1 b/lib/dsc-lib-jsonschema/.versions.ps1 old mode 100644 new mode 100755 index 0c8c94047..cb7822c30 --- a/lib/dsc-lib-jsonschema/.versions.ps1 +++ b/lib/dsc-lib-jsonschema/.versions.ps1 @@ -1,3 +1,5 @@ +#!/usr/bin/env pwsh + # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. @@ -32,7 +34,12 @@ begin { param() process { - $null = git fetch --all --tags + $allOut = git fetch --all --tags *>&1 + + if ($LASTEXITCODE -ne 0) { + throw "Unable to fetch git tags:`n`t$($allOut -join "`n`t")" + } + git tag -l | Where-Object -FilterScript {$_ -match '^v\d+(\.\d+){2}$' } | ForEach-Object -Process { [semver]($_.Substring(1)) } diff --git a/lib/dsc-lib-jsonschema/build.rs b/lib/dsc-lib-jsonschema/build.rs index 26fdcf573..59ac916f6 100644 --- a/lib/dsc-lib-jsonschema/build.rs +++ b/lib/dsc-lib-jsonschema/build.rs @@ -501,20 +501,27 @@ fn main() { .expect("env var 'OUT_DIR' not defined"); let dest_path = Path::new(&out_dir).join("recognized_schema_version.rs"); - // Update the versions data if needed. - let output = update_versions_data(&script_path); - assert!( - output.status.success(), - "Failed to update versions data via PowerShell script.\nExit code: {:?}\nStdout: {}\nStderr: {}", - output.status.code(), - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) - ); + let profile = env::var_os("PROFILE") + .expect("env var 'PROFILE' not defined"); + + // Update the versions data if needed, only on debug builds. + if profile == "debug" { + let output = update_versions_data(&script_path); + assert!( + output.status.success(), + "Failed to update versions data via PowerShell script.\nExit code: {:?}\nStdout: {}\nStderr: {}", + output.status.code(), + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + } 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("Failed to parse version data from .versions.json"); + .expect(format!( + "Failed to parse version data from .versions.json:\n---FILE TEXT START---\n{version_data}\n---FILE TEXT END---\n" + ).as_str()); let contents = format_file_content(&version_info); fs::write(