Skip to content

Commit 1475cd5

Browse files
authored
Fix clean logic and bump to 0.5.1 (#118)
* fix: 修复清理任务处理逻辑 - 在clean_src函数中添加空命令检查,避免无清理命令时执行错误 - 在create_command函数中增加空字符串命令检查 - 优化clean_daemon函数,根据清理级别过滤需要清理的任务 - 添加详细的日志输出,便于调试和监控 Signed-off-by: longjin <longjin@DragonOS.org> * chore: 更新项目版本至0.5.1 - 将dadk、dadk-config、dadk-user包版本从0.5.0升级到0.5.1 Signed-off-by: longjin <longjin@DragonOS.org> --------- Signed-off-by: longjin <longjin@DragonOS.org>
1 parent 1d46114 commit 1475cd5

File tree

7 files changed

+84
-12
lines changed

7 files changed

+84
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ DADK是一个Rust程序,您可以通过Cargo来安装DADK。
2828
# 从GitHub安装最新版
2929
cargo install --git https://github.com/DragonOS-Community/DADK.git
3030

31-
# 从crates.io下载
32-
cargo install dadk
3331

3432
```
3533

dadk-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dadk-config"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
edition = "2021"
55
authors = [
66
"longjin <longjin@DragonOS.org>",

dadk-user/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dadk-user"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
edition = "2021"
55
description = "DragonOS Application Development Kit - user prog build"
66
license = "GPL-2.0-only"
@@ -9,7 +9,7 @@ license = "GPL-2.0-only"
99
anyhow = { version = "1.0.100", features = ["std", "backtrace"] }
1010
chrono = { version = "=0.4.35", features = ["serde"] }
1111
clap = { version = "=4.5.20", features = ["derive"] }
12-
dadk-config = { version = "0.5.0", path = "../dadk-config" }
12+
dadk-config = { version = "0.5.1", path = "../dadk-config" }
1313
derive_builder = "0.20.0"
1414
lazy_static = "1.4.0"
1515
log = "0.4.17"

dadk-user/src/executor/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ impl Executor {
425425
fn clean_src(&self) -> Result<(), ExecutorError> {
426426
let cmd: Option<Command> = self.create_command()?;
427427
if cmd.is_none() {
428+
log::warn!(
429+
"{}: No clean command specified, skipping source directory clean.",
430+
self.entity.task().name_version()
431+
);
428432
// 如果这里没有命令,则认为用户不需要在源文件目录执行清理
429433
return Ok(());
430434
}
@@ -506,6 +510,11 @@ impl Executor {
506510

507511
let raw_cmd = raw_cmd.unwrap();
508512

513+
// 如果命令是空字符串,也返回 None
514+
if raw_cmd.is_empty() {
515+
return Ok(None);
516+
}
517+
509518
let mut command = Command::new("bash");
510519
command.current_dir(self.src_work_dir().unwrap());
511520

dadk-user/src/scheduler/mod.rs

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
executor::Executor,
1919
parser::task::DADKTask,
2020
};
21+
use dadk_config::user::UserCleanLevel;
2122

2223
use self::task_deque::TASK_DEQUE;
2324

@@ -406,7 +407,10 @@ impl Scheduler {
406407
// 准备全局环境变量
407408
crate::executor::prepare_env(&self.target, &self.context)
408409
.map_err(|e| SchedulerError::RunError(format!("{:?}", e)))?;
409-
410+
log::info!(
411+
"Global environment variables prepared, action: {:?}",
412+
self.action
413+
);
410414
match self.action {
411415
Action::Build | Action::Install => {
412416
self.run_with_topo_sort()?;
@@ -461,6 +465,11 @@ impl Scheduler {
461465
}
462466

463467
pub fn execute(action: Action, dragonos_dir: PathBuf, entity: Arc<SchedEntity>) {
468+
log::info!(
469+
"Starting task {} with action {:?}",
470+
entity.task().name_version(),
471+
action
472+
);
464473
let mut executor = Executor::new(entity.clone(), action.clone(), dragonos_dir.clone())
465474
.map_err(|e| {
466475
error!(
@@ -558,8 +567,64 @@ impl Scheduler {
558567
/// 无
559568
pub fn clean_daemon(action: Action, dragonos_dir: PathBuf, r: &mut Vec<Arc<SchedEntity>>) {
560569
let mut guard = TASK_DEQUE.lock().unwrap();
561-
while !guard.queue().is_empty() && !r.is_empty() {
562-
guard.clean_task(action, dragonos_dir.clone(), r.pop().unwrap().clone());
570+
log::info!(
571+
"Starting clean daemon for {} tasks, queue length: {}",
572+
r.len(),
573+
guard.queue().len()
574+
);
575+
576+
// 清理操作不需要拓扑排序,直接处理所有任务
577+
while !r.is_empty() {
578+
let entity = r.pop().unwrap();
579+
580+
// 检查任务是否需要清理
581+
match action {
582+
// Clean(Output) 对所有任务都有效(清理构建输出目录)
583+
Action::Clean(UserCleanLevel::Output) => {
584+
log::info!(
585+
"Adding task {} to clean queue",
586+
entity.task().name_version()
587+
);
588+
guard.clean_task(action, dragonos_dir.clone(), entity.clone());
589+
}
590+
// Clean(InSrc) 和 Clean(All) 需要有源码目录
591+
Action::Clean(_level @ (UserCleanLevel::InSrc | UserCleanLevel::All)) => {
592+
// 判断任务是否有源码目录
593+
// 1. 本地路径的任务(source_path 不为 None)
594+
// 2. git 或 archive 类型的任务(会创建 source_dir)
595+
let has_source_dir = entity.task().source_path().is_some()
596+
|| matches!(
597+
entity.task().task_type,
598+
crate::parser::task::TaskType::BuildFromSource(_)
599+
| crate::parser::task::TaskType::InstallFromPrebuilt(
600+
crate::parser::task::PrebuiltSource::Archive(_)
601+
)
602+
);
603+
604+
if has_source_dir {
605+
log::info!(
606+
"Adding task {} to clean queue",
607+
entity.task().name_version()
608+
);
609+
guard.clean_task(action, dragonos_dir.clone(), entity.clone());
610+
} else {
611+
log::info!(
612+
"Skipping task {} (no source directory to clean)",
613+
entity.task().name_version()
614+
);
615+
}
616+
}
617+
618+
_ => {}
619+
}
620+
}
621+
622+
// 等待所有清理任务完成
623+
while !guard.queue().is_empty() {
624+
guard.queue_mut().retain(|x| !x.is_finished());
625+
if !guard.queue().is_empty() {
626+
std::thread::sleep(std::time::Duration::from_millis(100));
627+
}
563628
}
564629
}
565630

dadk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [
66
"xuzihao <xuzihao@DragonOS.org>"
77
]
88

9-
version = "0.5.0"
9+
version = "0.5.1"
1010
edition = "2021"
1111
description = "DragonOS Application Development Kit\nDragonOS应用开发工具"
1212
license = "GPL-2.0-only"

0 commit comments

Comments
 (0)