Skip to content

Commit deba40f

Browse files
authored
Merge branch 'main' into security/workflow-permissions
2 parents bcb5fff + 74b1da7 commit deba40f

9 files changed

Lines changed: 561 additions & 46 deletions

File tree

crates/cargo-wdk/src/actions/build/mod.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl<'a> BuildAction<'a> {
8585
metadata: &'a Metadata,
8686
) -> Result<Self> {
8787
// TODO: validate params
88+
anyhow::ensure!(
89+
!params.working_dir.as_os_str().is_empty(),
90+
"working_dir must not be empty"
91+
);
8892
Ok(Self {
8993
working_dir: absolute(params.working_dir)?,
9094
profile: params.profile,
@@ -151,14 +155,13 @@ impl<'a> BuildAction<'a> {
151155
);
152156

153157
let mut is_valid_dir_with_rust_projects = false;
154-
for dir in &dirs {
155-
if self.fs.dir_file_type(dir)?.is_dir()
156-
&& self.fs.exists(&dir.path().join("Cargo.toml"))
157-
{
158+
for entry in &dirs {
159+
if entry.is_dir && self.fs.exists(&entry.path.join("Cargo.toml")) {
158160
debug!(
159-
"Found atleast one valid Rust project directory: {}, continuing with the \
161+
"Found at least one valid Rust project directory: {}, continuing with the \
160162
build flow",
161-
dir.path()
163+
entry
164+
.path
162165
.file_name()
163166
.expect(
164167
"package sub directory name ended with \"..\" which is not expected"
@@ -179,26 +182,24 @@ impl<'a> BuildAction<'a> {
179182
info!("Building packages in {}", self.working_dir.display());
180183

181184
let mut failed_atleast_one_project = false;
182-
for dir in dirs {
183-
debug!("Checking dir entry: {}", dir.path().display());
184-
if !self.fs.dir_file_type(&dir)?.is_dir()
185-
|| !self.fs.exists(&dir.path().join("Cargo.toml"))
186-
{
185+
for entry in dirs {
186+
debug!("Checking dir entry: {}", entry.path.display());
187+
if !entry.is_dir || !self.fs.exists(&entry.path.join("Cargo.toml")) {
187188
debug!("Dir entry is not a valid Rust package");
188189
continue;
189190
}
190191

191-
let working_dir_path = dir.path(); // Avoids a short-lived temporary
192-
let sub_dir = working_dir_path
192+
let cargo_package_path = entry.path;
193+
let package_dir_name = cargo_package_path
193194
.file_name()
194195
.expect("package sub directory name ended with \"..\" which is not expected")
195196
.to_string_lossy();
196197

197-
debug!("Building package(s) in dir {sub_dir}");
198-
if let Err(e) = self.run_from_workspace_root(&dir.path()) {
198+
debug!("Building package(s) in dir {package_dir_name}");
199+
if let Err(e) = self.run_from_workspace_root(&cargo_package_path) {
199200
failed_atleast_one_project = true;
200201
err!(
201-
"Error building project: {sub_dir}, error: {:?}",
202+
"Error building project: {package_dir_name}, error: {:?}",
202203
anyhow::Error::new(e)
203204
);
204205
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation
2+
// License: MIT OR Apache-2.0
3+
//! This module defines error types for the clean action module.
4+
5+
use std::path::PathBuf;
6+
7+
use thiserror::Error;
8+
9+
use crate::providers::error::{CommandError, FileError};
10+
11+
/// Errors for the clean action layer
12+
#[derive(Error, Debug)]
13+
pub enum CleanActionError {
14+
#[error(transparent)]
15+
FileIo(#[from] FileError),
16+
#[error("No valid rust projects in the current working directory: {0}")]
17+
NoValidRustProjectsInTheDirectory(PathBuf),
18+
#[error("One or more projects failed to clean in the emulated workspace: {0}")]
19+
OneOrMoreRustProjectsFailedToClean(PathBuf),
20+
#[error(transparent)]
21+
CargoClean(#[from] CommandError),
22+
}

0 commit comments

Comments
 (0)