Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ jobs:
- name: Package Examples (via Cargo Make)
run: cargo make --cwd ./examples package-driver-flow +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }}

- name: Build Tests (via Cargo Make)
run: cargo make --cwd ./tests build +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }}

- name: Package Tests (via Cargo Make)
run: cargo make --cwd ./tests package-driver-flow +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }}

# Run cargo-wdk on examples and tests
- name: Install cargo-wdk
run: cargo +${{ matrix.rust_toolchain }} install --path=crates/cargo-wdk --profile ${{ matrix.cargo_profile }} --locked --force
Expand Down
7 changes: 6 additions & 1 deletion crates/cargo-wdk/src/actions/build/build_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct BuildTask<'a> {
verbosity_level: clap_verbosity_flag::Verbosity,
manifest_path: PathBuf,
command_exec: &'a CommandExec,
working_dir: &'a Path,
}

impl<'a> BuildTask<'a> {
Expand Down Expand Up @@ -64,6 +65,7 @@ impl<'a> BuildTask<'a> {
verbosity_level,
manifest_path: working_dir.join("Cargo.toml"),
command_exec,
working_dir,
}
}

Expand Down Expand Up @@ -100,7 +102,10 @@ impl<'a> BuildTask<'a> {
.iter()
.map(std::string::String::as_str)
.collect::<Vec<&str>>();
self.command_exec.run("cargo", &args, None)?;
// Run cargo build from the provided working directory so that config.toml
// is respected
self.command_exec
.run("cargo", &args, None, Some(self.working_dir))?;
debug!("Done");
Ok(())
}
Expand Down
16 changes: 8 additions & 8 deletions crates/cargo-wdk/src/actions/build/package_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl<'a> PackageTask<'a> {
if !wdf_version_flags.is_empty() {
args.append(&mut wdf_version_flags.iter().map(String::as_str).collect());
}
if let Err(e) = self.command_exec.run("stampinf", &args, None) {
if let Err(e) = self.command_exec.run("stampinf", &args, None, None) {
return Err(PackageTaskError::StampinfCommand(e));
}
Ok(())
Expand All @@ -338,7 +338,7 @@ impl<'a> PackageTask<'a> {
"/uselocaltime",
];

if let Err(e) = self.command_exec.run("inf2cat", &args, None) {
if let Err(e) = self.command_exec.run("inf2cat", &args, None, None) {
return Err(PackageTaskError::Inf2CatCommand(e));
}

Expand All @@ -362,7 +362,7 @@ impl<'a> PackageTask<'a> {
debug!("Checking if self signed certificate exists in WDRTestCertStore store.");
let args = ["-s", WDR_TEST_CERT_STORE];

match self.command_exec.run("certmgr.exe", &args, None) {
match self.command_exec.run("certmgr.exe", &args, None, None) {
Ok(output) if output.status.success() => String::from_utf8(output.stdout).map_or_else(
|e| Err(PackageTaskError::VerifyCertExistsInStoreInvalidCommandOutput(e)),
|stdout| Ok(stdout.contains(WDR_LOCAL_TEST_CERT)),
Expand All @@ -388,7 +388,7 @@ impl<'a> PackageTask<'a> {
&format!("CN={WDR_LOCAL_TEST_CERT}"), // FIXME: this should be a parameter
&cert_path,
];
if let Err(e) = self.command_exec.run("makecert", &args, None) {
if let Err(e) = self.command_exec.run("makecert", &args, None, None) {
return Err(PackageTaskError::CertGenerationInStoreCommand(e));
}
Ok(())
Expand All @@ -406,7 +406,7 @@ impl<'a> PackageTask<'a> {
WDR_LOCAL_TEST_CERT,
&cert_path,
];
if let Err(e) = self.command_exec.run("certmgr.exe", &args, None) {
if let Err(e) = self.command_exec.run("certmgr.exe", &args, None, None) {
return Err(PackageTaskError::CreateCertFileFromStoreCommand(e));
}
Ok(())
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<'a> PackageTask<'a> {
"SHA256",
&driver_binary_file_path,
];
if let Err(e) = self.command_exec.run("signtool", &args, None) {
if let Err(e) = self.command_exec.run("signtool", &args, None, None) {
return Err(PackageTaskError::DriverBinarySignCommand(e));
}
Ok(())
Expand All @@ -466,7 +466,7 @@ impl<'a> PackageTask<'a> {
let args = ["verify", "/v", "/pa", &driver_binary_file_path];
// TODO: Differentiate between command exec failure and signature verification
// failure
if let Err(e) = self.command_exec.run("signtool", &args, None) {
if let Err(e) = self.command_exec.run("signtool", &args, None, None) {
return Err(PackageTaskError::DriverBinarySignVerificationCommand(e));
}
Ok(())
Expand Down Expand Up @@ -504,7 +504,7 @@ impl<'a> PackageTask<'a> {
}
args.push(&inf_path);

if let Err(e) = self.command_exec.run("infverif", &args, None) {
if let Err(e) = self.command_exec.run("infverif", &args, None, None) {
return Err(PackageTaskError::InfVerificationCommand(e));
}

Expand Down
55 changes: 33 additions & 22 deletions crates/cargo-wdk/src/actions/build/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,13 +2210,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_cargo_command && args == expected_cargo_build_args
},
)
.once()
.returning(move |_, _, _| Ok(expected_output.clone()));
.returning(move |_, _, _, _| Ok(expected_output.clone()));
self
}

Expand Down Expand Up @@ -2501,7 +2502,8 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
println!("command: {command}, args: {args:?}");
println!(
Expand All @@ -2512,7 +2514,7 @@ impl TestSetupPackageExpectations for TestBuildAction {
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2567,7 +2569,8 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
println!("command: {command}, args: {args:?}");
println!(
Expand All @@ -2578,7 +2581,7 @@ impl TestSetupPackageExpectations for TestBuildAction {
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2606,13 +2609,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_certmgr_command && args == expected_certmgr_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2656,13 +2660,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_certmgr_command && args == expected_certmgr_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2704,13 +2709,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_makecert_command && args == expected_makecert_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2764,13 +2770,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_signtool_command && args == expected_signtool_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2823,13 +2830,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_signtool_command && args == expected_signtool_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2875,13 +2883,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_signtool_command && args == expected_signtool_verify_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2927,13 +2936,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_signtool_command && args == expected_signtool_verify_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down Expand Up @@ -2989,13 +2999,14 @@ impl TestSetupPackageExpectations for TestBuildAction {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&Path>|
-> bool {
command == expected_infverif_command && args == expected_infverif_args
},
)
.once()
.returning(move |_, _, _| match override_output.clone() {
.returning(move |_, _, _, _| match override_output.clone() {
Some(output) => match output.status.code() {
Some(0) => Ok(Output {
status: ExitStatus::from_raw(0),
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-wdk/src/actions/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'a> NewAction<'a> {
if let Some(flag) = trace::get_cargo_verbose_flags(self.verbosity_level) {
args.push(flag);
}
if let Err(e) = self.command_exec.run("cargo", &args, None) {
if let Err(e) = self.command_exec.run("cargo", &args, None, None) {
return Err(NewActionError::CargoNewCommand(e));
}
Ok(())
Expand Down
7 changes: 4 additions & 3 deletions crates/cargo-wdk/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Cli {
command_exec: &CommandExec,
) -> Result<CpuArchitecture> {
command_exec
.run("rustc", &["--print", "host-tuple"], None)
.run("rustc", &["--print", "host-tuple"], None, None)
.map_or_else(
|e| Err(anyhow::anyhow!("Unable to read rustc host tuple: {e}")),
|output| {
Expand Down Expand Up @@ -317,7 +317,8 @@ mod tests {
.withf(
move |command: &str,
args: &[&str],
_env_vars: &Option<&HashMap<&str, &str>>|
_env_vars: &Option<&HashMap<&str, &str>>,
_working_dir: &Option<&std::path::Path>|
-> bool {
println!("command: {command}, args: {args:?}");
println!(
Expand All @@ -328,7 +329,7 @@ mod tests {
},
)
.once()
.return_once(|_, _, _| expected_cli_result);
.return_once(|_, _, _, _| expected_cli_result);

Cli::detect_default_target_arch_using_rustc(&mock_command_exec)
}
Expand Down
6 changes: 6 additions & 0 deletions crates/cargo-wdk/src/providers/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::{
collections::HashMap,
path::Path,
process::{Command, Output, Stdio},
};

Expand All @@ -34,6 +35,7 @@ impl CommandExec {
command: &'a str,
args: &'a [&'a str],
env_vars: Option<&'a HashMap<&'a str, &'a str>>,
working_dir: Option<&'a Path>,
) -> Result<Output, CommandError> {
debug!("Running: {} {:?}", command, args);

Expand All @@ -46,6 +48,10 @@ impl CommandExec {
}
}

if let Some(working_dir) = working_dir {
cmd.current_dir(working_dir);
}

let output = cmd
.stdout(Stdio::piped())
.spawn()
Expand Down
Loading
Loading