Skip to content

Commit

Permalink
refactor: move infverif task's condition script logic to cargo_make.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
svasista-ms committed Sep 12, 2024
1 parent 315a90e commit c693f36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion crates/wdk-build/rust-driver-sample-makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
'''
16 changes: 9 additions & 7 deletions crates/wdk-build/src/cargo_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>(&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::<u32>(
&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
Expand Down

0 comments on commit c693f36

Please sign in to comment.