@@ -18,6 +18,7 @@ use crate::{
1818 executor:: Executor ,
1919 parser:: task:: DADKTask ,
2020} ;
21+ use dadk_config:: user:: UserCleanLevel ;
2122
2223use 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
0 commit comments