Skip to content
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b9db4c5
feat: implement clean action module with errors and tests
svasista-ms Apr 1, 2026
ef2d04e
feat: add clean subcommand to CLI
svasista-ms Apr 1, 2026
4075932
feat: add integration tests for `cargo wdk clean` command
svasista-ms Apr 1, 2026
9ce3a8e
refactor: run clean command within build command integration tests
svasista-ms Apr 2, 2026
4b58929
refactor: update CleanActionError types and test names based on metho…
svasista-ms Apr 2, 2026
64e7bcc
refactor(tests): run clean command again after the build command and …
svasista-ms Apr 6, 2026
fbf1c4b
refactor(tests): remove unnecessary Clippy lint suppression for mocka…
svasista-ms Apr 6, 2026
9cbdc66
refactor: simplify project validation logic in clean action
svasista-ms Apr 6, 2026
915366a
refactor: update CargoClean error
svasista-ms Apr 6, 2026
3fe851f
refactor: simplify subdirectory name extraction in run method
svasista-ms Apr 6, 2026
6bb2c93
refactor: add documentation for CleanAction struct
svasista-ms Apr 6, 2026
b7e2469
refactor: add validation for non-empty working directory in CleanAction
svasista-ms Apr 6, 2026
6e1fe56
refactor: improve test function names for clarity in CleanAction tests
svasista-ms Apr 7, 2026
ed2a887
refactor: add validation to ensure working directory is not empty in …
svasista-ms Apr 20, 2026
47285be
refactor: enhance error handling in CleanAction tests
svasista-ms Apr 20, 2026
95a2721
refactor: add assertions to verify target directories do not exist af…
svasista-ms Apr 20, 2026
3aee35d
refactor: improve error handling in new_fails_if_working_dir_is_empty…
svasista-ms Apr 27, 2026
730a953
refactor: move logging of cleaning packages to conditional check in r…
svasista-ms Apr 27, 2026
80cc4ec
refactor: move tests into CleanAction `mod.rs` file
svasista-ms Apr 28, 2026
abf8412
refactor: directory entry handling in CleanAction and BuildAction
svasista-ms May 4, 2026
8a5961a
docs: add cargo-wdk preview callout to Cargo Make section in README (…
krishnakumar4a4 Apr 14, 2026
5d37942
refactor: fix `collapsable_if` lint, rust 1.95 `assert_matches` desta…
leon-xd Apr 16, 2026
740225c
feat!: stack-based format buffer for `wdk` crate (#611)
leon-xd Apr 17, 2026
2567210
fix(cargo-wdk): use `--message-format=json-render-diagnostics` in the…
svasista-ms May 1, 2026
4cb3626
refactor(wdk-build): fix clippy lints (#655)
svasista-ms May 5, 2026
42a67e3
fix: correct typo in debug log message
svasista-ms May 5, 2026
b23b0b7
refactor: use `DirFileTypeError` variant when `file_type()` fails ins…
svasista-ms May 5, 2026
90a8726
fix: about string for the clean subcommand
svasista-ms May 5, 2026
69f895e
Merge branch 'main' into clean-command
svasista-ms May 5, 2026
3fd27e4
refactor: update variable names for clarity in build and clean actions
svasista-ms May 7, 2026
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
27 changes: 14 additions & 13 deletions crates/cargo-wdk/src/actions/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ impl<'a> BuildAction<'a> {
metadata: &'a Metadata,
) -> Result<Self> {
// TODO: validate params
anyhow::ensure!(
!params.working_dir.as_os_str().is_empty(),
"working_dir must not be empty"
);
Ok(Self {
working_dir: absolute(params.working_dir)?,
profile: params.profile,
Expand Down Expand Up @@ -151,14 +155,13 @@ impl<'a> BuildAction<'a> {
);

let mut is_valid_dir_with_rust_projects = false;
for dir in &dirs {
if self.fs.dir_file_type(dir)?.is_dir()
&& self.fs.exists(&dir.path().join("Cargo.toml"))
{
for entry in &dirs {
if entry.is_dir && self.fs.exists(&entry.path.join("Cargo.toml")) {
debug!(
"Found atleast one valid Rust project directory: {}, continuing with the \
"Found at least one valid Rust project directory: {}, continuing with the \
build flow",
dir.path()
entry
.path
.file_name()
.expect(
"package sub directory name ended with \"..\" which is not expected"
Expand All @@ -179,23 +182,21 @@ impl<'a> BuildAction<'a> {
info!("Building packages in {}", self.working_dir.display());

let mut failed_atleast_one_project = false;
for dir in dirs {
debug!("Checking dir entry: {}", dir.path().display());
if !self.fs.dir_file_type(&dir)?.is_dir()
|| !self.fs.exists(&dir.path().join("Cargo.toml"))
{
for entry in dirs {
debug!("Checking dir entry: {}", entry.path.display());
if !entry.is_dir || !self.fs.exists(&entry.path.join("Cargo.toml")) {
debug!("Dir entry is not a valid Rust package");
continue;
}

let working_dir_path = dir.path(); // Avoids a short-lived temporary
let working_dir_path = entry.path;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment even applies here as we are not really switching into the directory during this loop.

https://github.com/microsoft/windows-drivers-rs/pull/638/changes#r3199700749

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to cargo_package_path 👍

let sub_dir = working_dir_path
.file_name()
.expect("package sub directory name ended with \"..\" which is not expected")
.to_string_lossy();

debug!("Building package(s) in dir {sub_dir}");
if let Err(e) = self.run_from_workspace_root(&dir.path()) {
if let Err(e) = self.run_from_workspace_root(&working_dir_path) {
failed_atleast_one_project = true;
err!(
"Error building project: {sub_dir}, error: {:?}",
Expand Down
22 changes: 22 additions & 0 deletions crates/cargo-wdk/src/actions/clean/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation
// License: MIT OR Apache-2.0
//! This module defines error types for the clean action module.

use std::path::PathBuf;

use thiserror::Error;

use crate::providers::error::{CommandError, FileError};

/// Errors for the clean action layer
#[derive(Error, Debug)]
pub enum CleanActionError {
#[error(transparent)]
FileIo(#[from] FileError),
#[error("No valid rust projects in the current working directory: {0}")]
NoValidRustProjectsInTheDirectory(PathBuf),
#[error("One or more projects failed to clean in the emulated workspace: {0}")]
OneOrMoreRustProjectsFailedToClean(PathBuf),
#[error(transparent)]
CargoClean(#[from] CommandError),
}
Loading
Loading