From c693f3661df616de761d651bbe3070776fe22a7b Mon Sep 17 00:00:00 2001 From: Shravan Vasista Date: Wed, 11 Sep 2024 23:52:13 -0700 Subject: [PATCH] refactor: move infverif task's condition script logic to cargo_make.rs --- .../wdk-build/rust-driver-sample-makefile.toml | 5 ++++- crates/wdk-build/src/cargo_make.rs | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/wdk-build/rust-driver-sample-makefile.toml b/crates/wdk-build/rust-driver-sample-makefile.toml index 1406cba1..2a390594 100644 --- a/crates/wdk-build/rust-driver-sample-makefile.toml +++ b/crates/wdk-build/rust-driver-sample-makefile.toml @@ -38,8 +38,11 @@ condition_script = ''' //! ```cargo //! [dependencies] //! wdk-build = { path = ".", version = "0.2.0" } +//! anyhow = "1" //! ``` #![allow(unused_doc_comments)] -wdk_build::cargo_make::infverif_condition_script()? +fn main() -> anyhow::Result<()> { + wdk_build::cargo_make::driver_sample_infverif_condition_script() +} ''' diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 61aa438d..7b9a310f 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -1069,19 +1069,21 @@ where /// /// This function returns an error whenever it determines that the /// `infverif` `cargo-make` task should be skipped (i.e. when the WDK Version is -/// bugged and does not contain /samples flag +/// bugged and does not contain /samples flag) /// /// # Panics -/// Panics if the `WDK_BUILD_DETECTED_VERSION` environment variable is not set. -pub fn infverif_condition_script() -> anyhow::Result<()> { +/// Panics if `CARGO_MAKE_CURRENT_TASK_NAME` is not set in the environment +pub fn driver_sample_infverif_condition_script() -> anyhow::Result<()> { condition_script(|| { let wdk_version = env::var(WDK_VERSION_ENV_VAR).expect( "WDK_BUILD_DETECTED_VERSION should always be set by wdk-build-init cargo make task", ); - let wdk_build_number = str::parse::(&get_wdk_version_number(&wdk_version).unwrap()) - .unwrap_or_else(|_| { - panic!("Couldn't parse WDK version number! Version number: {wdk_version}") - }); + let wdk_build_number = str::parse::( + &get_wdk_version_number(&wdk_version).expect("Failed to get WDK version number"), + ) + .expect(&format!( + "Couldn't parse WDK version number! Version number: {wdk_version}" + )); if MISSING_SAMPLE_FLAG_WDK_BUILD_NUMBER_RANGE.contains(&wdk_build_number) { // cargo_make will interpret returning an error from the rust-script // condition_script as skipping the task