Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip infverif task for sample drivers built with certain GE WDK versions #143

Merged
merged 47 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5cd6fc7
Initial stab at getting the WDK version into environment
NateD-MSFT Apr 23, 2024
6038348
Implement logic to select InfVerif flag. HAS BUG
NateD-MSFT Apr 26, 2024
67f3717
Introduce WDK_IS_SAMPLE flag to make simpler environment logic
NateD-MSFT Apr 26, 2024
1dc5701
Quick TODO to improve parsing
NateD-MSFT Apr 26, 2024
b261b0a
Refactor set_sample_infverif
NateD-MSFT Apr 26, 2024
db8da44
Cleanup and add test case.
NateD-MSFT Apr 26, 2024
f760c30
/samples, not /sample
NateD-MSFT Apr 26, 2024
b6e2951
Update to not run infverif for samples
NateD-MSFT Apr 26, 2024
15e99c7
Merge branch 'main' into vnext-wdk-support
NateD-MSFT Apr 26, 2024
ab732ab
Fix cargo format bug
NateD-MSFT Apr 26, 2024
e7c3263
Merge branch 'vnext-wdk-support' of https://github.com/NateD-MSFT/win…
NateD-MSFT Apr 26, 2024
dca2606
Cargo auto-fixes
NateD-MSFT Apr 27, 2024
963d12c
Clippy fixes
NateD-MSFT Apr 27, 2024
5d575f3
Undo accidental change to types.rs
NateD-MSFT Apr 27, 2024
bd557e5
Refactors to address PR feedback.
NateD-MSFT May 1, 2024
df43c89
Fix TOML formatting
NateD-MSFT May 1, 2024
43366e2
Merge branch 'main' into vnext-wdk-support
NateD-MSFT May 1, 2024
ef2eba6
Fix new clippy lint.
NateD-MSFT May 1, 2024
f3de079
Fix doc bug.
NateD-MSFT May 1, 2024
db51319
Fix a formatting issue that slipped in.
NateD-MSFT May 1, 2024
31b4bd1
Refactor `validate_wdk_version_format` into utils.rs
NateD-MSFT May 1, 2024
dcaeb14
Use a single collection instead of iterators
NateD-MSFT May 2, 2024
810e31b
Comment fix
NateD-MSFT May 2, 2024
2ce9838
Apply suggestions from code review
NateD-MSFT May 3, 2024
15c5458
Refactor and add a new enum value. Still has a bug
NateD-MSFT May 8, 2024
6a66900
Merge branch 'vnext-wdk-support' of https://github.com/NateD-MSFT/win…
NateD-MSFT May 8, 2024
0cbea24
This borrow actually is required here
NateD-MSFT May 8, 2024
75c09a2
Significant refactoring and renaming
NateD-MSFT May 9, 2024
754e1f9
BUGGY: Attempt to refactor samples logic into makefiles
NateD-MSFT May 9, 2024
cb6ce1d
TOML formatting fix
NateD-MSFT May 9, 2024
2ad53a5
Various typos and language fixes
NateD-MSFT May 9, 2024
fb129de
BUGGY: Add new plugin to work with cargo make paths
NateD-MSFT May 9, 2024
140208d
Merge branch 'vnext-wdk-support' of https://github.com/NateD-MSFT/win…
NateD-MSFT May 9, 2024
916fe8f
Fix an updated function name
NateD-MSFT May 9, 2024
504a7d5
Merge branch 'main' into vnext-wdk-support
NateD-MSFT May 9, 2024
337f363
Merge branch 'main' into vnext-wdk-support
NateD-MSFT May 9, 2024
bb5da2e
Update crates/wdk-build/rust-driver-sample-makefile.toml
NateD-MSFT May 13, 2024
a33c93d
Fix conditional-script behavior
NateD-MSFT May 16, 2024
f0cf0e4
Clippy/fmt fixes
NateD-MSFT May 16, 2024
71ad073
Merge branch 'vnext-wdk-support' of https://github.com/NateD-MSFT/win…
NateD-MSFT May 16, 2024
9871806
Merge branch 'main' into vnext-wdk-support
NateD-MSFT May 16, 2024
cb9b7d5
Remove pub marker on utils
NateD-MSFT May 16, 2024
d38bddf
Merge branch 'vnext-wdk-support' of https://github.com/NateD-MSFT/win…
NateD-MSFT May 16, 2024
52c9ce6
Add version field to WDKVersionStringFormatError
NateD-MSFT May 23, 2024
193d123
Merge branch 'main' into vnext-wdk-support
NateD-MSFT May 30, 2024
5f2ac57
Fix a missing reference in make script
NateD-MSFT May 30, 2024
8cb3311
A few more fixes to the make script
NateD-MSFT May 30, 2024
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
2 changes: 1 addition & 1 deletion crates/sample-kmdf-driver/Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extend = "../wdk-build/rust-driver-makefile.toml"

[env]
WDK_BUILD_ADDITIONAL_INFVERIF_FLAGS = "/msft"
WDK_IS_SAMPLE = true
NateD-MSFT marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions crates/wdk-build/rust-driver-makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ script = '''

wdk_build::cargo_make::validate_and_forward_args();
wdk_build::cargo_make::setup_path()?;

let wdk_version = wdk_build::cargo_make::setup_wdk_version()?;
wdk_build::cargo_make::set_sample_infverif(wdk_version)?;
'''

[tasks.copy-inx-to-output]
Expand Down Expand Up @@ -177,13 +180,16 @@ args = [
"1.33",
]


[tasks.infverif]
NateD-MSFT marked this conversation as resolved.
Show resolved Hide resolved
private = true
dependencies = ["stampinf"]
condition = { env_not_set = ["WDK_INF_NEW_VERSION"] }
wmmc88 marked this conversation as resolved.
Show resolved Hide resolved
command = "infverif"
args = [
"/v",
"/w",
"@@decode(WDK_IS_SAMPLE,true,${WDK_INFVERIF_SAMPLE_FLAG})",
wmmc88 marked this conversation as resolved.
Show resolved Hide resolved
"@@split(WDK_BUILD_ADDITIONAL_INFVERIF_FLAGS, )",
"${WDK_BUILD_OUTPUT_DIRECTORY}/${CARGO_MAKE_CRATE_FS_NAME}.inf",
]
Expand Down
84 changes: 84 additions & 0 deletions crates/wdk-build/src/cargo_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ use crate::{
};

const PATH_ENV_VAR: &str = "Path";
const WDK_VERSION_ENV_VAR: &str = "WDK_VER";
wmmc88 marked this conversation as resolved.
Show resolved Hide resolved
/// The name of the environment variable we store the appropriate `InfVerif`
/// flag for samples in.
const SAMPLE_ENV_VAR: &str = "WDK_INFVERIF_SAMPLE_FLAG";
/// The first WDK version with the new `InfVerif` behavior.
const WDK_INF_NEW_VERSION: i32 = 25798;
NateD-MSFT marked this conversation as resolved.
Show resolved Hide resolved
const WDK_INF_NEW_VERSION_FLAG: &str = "WDK_INF_NEW_VERSION";

/// The name of the environment variable that cargo-make uses during `cargo
/// build` and `cargo test` commands
Expand Down Expand Up @@ -492,6 +499,57 @@ pub fn setup_path() -> Result<(), ConfigError> {
Ok(())
}

/// Adds the WDK version to the environment.
///
/// # Errors
///
/// This function returns a [`ConfigError::WDKContentRootDetectionError`] if the
/// WDK content root directory could not be found.
pub fn setup_wdk_version() -> Result<String, ConfigError> {
let Some(wdk_content_root) = detect_wdk_content_root() else {
return Err(ConfigError::WDKContentRootDetectionError);
};
let version = get_latest_windows_sdk_version(&wdk_content_root.join("Lib"))?;
prepend_to_semicolon_delimited_env_var(WDK_VERSION_ENV_VAR, &version);
forward_env_var_to_cargo_make(WDK_VERSION_ENV_VAR);
Ok(version)
}

/// Sets the `WDK_INFVERIF_SAMPLE_FLAG` environment variable to contain the
/// appropriate flag for building samples.
///
/// # Errors
///
/// This function returns a [`ConfigError::WDKContentRootDetectionError`] if the
/// WDK version is ill-formed (that is, it does not match the form
/// 10.x.yyyyy.z).
wmmc88 marked this conversation as resolved.
Show resolved Hide resolved
pub fn set_sample_infverif<S: AsRef<str>>(version: S) -> Result<(), ConfigError> {
NateD-MSFT marked this conversation as resolved.
Show resolved Hide resolved
let wdk_version = version.as_ref();
let mut version_parts = wdk_version.split('.');
let version_number = version_parts
.nth(2)
.and_then(|version_str| version_str.parse::<i32>().ok());

if let Some(version) = version_number {
let sample_flag = if version > WDK_INF_NEW_VERSION {
"/samples"
} else {
"/msft"
};
std::env::set_var(SAMPLE_ENV_VAR, sample_flag);
forward_env_var_to_cargo_make(SAMPLE_ENV_VAR);
if version > WDK_INF_NEW_VERSION {
std::env::set_var(WDK_INF_NEW_VERSION_FLAG, "true");
forward_env_var_to_cargo_make(WDK_INF_NEW_VERSION_FLAG);
}
return Ok(());
}

// If we get this far, we weren't able to parse the WDK version number from the
// path
Err(ConfigError::WDKContentRootDetectionError)
}

/// Returns the path to the WDK build output directory for the current
/// cargo-make flow
///
Expand Down Expand Up @@ -706,3 +764,29 @@ fn forward_env_var_to_cargo_make<S: AsRef<str>>(env_var_name: S) {
);
}
}

#[cfg(test)]
mod tests {
use crate::ConfigError;

const WDK_TEST_OLD_INF_VERSION: &str = "10.0.22061.0";
const WDK_TEST_NEW_INF_VERSION: &str = "10.0.26100.0";

#[test]
fn check_env_passing() -> Result<(), ConfigError> {
crate::cargo_make::set_sample_infverif(WDK_TEST_OLD_INF_VERSION)?;
let env_string = std::env::var_os(crate::cargo_make::SAMPLE_ENV_VAR).map_or_else(
|| panic!("Couldn't get OS string"),
|os_env_string| os_env_string.to_string_lossy().into_owned(),
);
assert_eq!(env_string, "/msft");

crate::cargo_make::set_sample_infverif(WDK_TEST_NEW_INF_VERSION)?;
let env_string = std::env::var_os(crate::cargo_make::SAMPLE_ENV_VAR).map_or_else(
|| panic!("Couldn't get OS string"),
|os_env_string| os_env_string.to_string_lossy().into_owned(),
);
assert_eq!(env_string, "/samples");
Ok(())
}
}
Loading