@@ -7,14 +7,14 @@ use std::{
77 sync:: RwLock ,
88} ;
99
10- use log:: { error, info, warn, debug } ;
10+ use log:: { debug , error, info, warn} ;
1111
1212use crate :: {
1313 console:: { clean:: CleanLevel , Action } ,
1414 executor:: cache:: CacheDir ,
1515 parser:: task:: { CodeSource , PrebuiltSource , TaskEnv , TaskType } ,
1616 scheduler:: { SchedEntities , SchedEntity } ,
17- utils:: stdio :: StdioUtils ,
17+ utils:: file :: FileUtils ,
1818} ;
1919
2020use self :: cache:: CacheDirType ;
@@ -107,7 +107,11 @@ impl Executor {
107107 // 清理构建结果
108108 let r = self . clean ( ) ;
109109 if let Err ( e) = r {
110- error ! ( "Failed to clean task {}: {:?}" , self . entity. task( ) . name_version( ) , e) ;
110+ error ! (
111+ "Failed to clean task {}: {:?}" ,
112+ self . entity. task( ) . name_version( ) ,
113+ e
114+ ) ;
111115 }
112116 }
113117 _ => {
@@ -165,36 +169,8 @@ impl Executor {
165169
166170 // 拷贝构建结果到安装路径
167171 let build_dir: PathBuf = self . build_dir . path . clone ( ) ;
168-
169- let cmd = Command :: new ( "cp" )
170- . arg ( "-r" )
171- . arg ( build_dir. to_string_lossy ( ) . to_string ( ) + "/." )
172- . arg ( install_path)
173- . stdout ( Stdio :: null ( ) )
174- . stderr ( Stdio :: piped ( ) )
175- . spawn ( )
176- . map_err ( |e| {
177- ExecutorError :: InstallError ( format ! (
178- "Failed to install, error message: {}" ,
179- e. to_string( )
180- ) )
181- } ) ?;
182-
183- let output = cmd. wait_with_output ( ) . map_err ( |e| {
184- ExecutorError :: InstallError ( format ! (
185- "Failed to install, error message: {}" ,
186- e. to_string( )
187- ) )
188- } ) ?;
189-
190- if !output. status . success ( ) {
191- let err_msg = StdioUtils :: tail_n_str ( StdioUtils :: stderr_to_lines ( & output. stderr ) , 10 ) ;
192- return Err ( ExecutorError :: InstallError ( format ! (
193- "Failed to install, error message: {}" ,
194- err_msg
195- ) ) ) ;
196- }
197-
172+ FileUtils :: copy_dir_all ( & build_dir, & install_path)
173+ . map_err ( |e| ExecutorError :: InstallError ( e) ) ?;
198174 info ! ( "Task {} installed." , self . entity. task( ) . name_version( ) ) ;
199175
200176 return Ok ( ( ) ) ;
@@ -292,7 +268,6 @@ impl Executor {
292268 if let Some ( local_path) = self . entity . task ( ) . source_path ( ) {
293269 return local_path;
294270 }
295-
296271 return self . source_dir . as_ref ( ) . unwrap ( ) . path . clone ( ) ;
297272 }
298273
@@ -308,7 +283,15 @@ impl Executor {
308283 self . action
309284 ) ,
310285 } ,
311- _ => None ,
286+
287+ TaskType :: InstallFromPrebuilt ( _) => match self . action {
288+ Action :: Build => self . entity . task ( ) . build . build_command . clone ( ) ,
289+ Action :: Clean ( _) => self . entity . task ( ) . clean . clean_command . clone ( ) ,
290+ _ => unimplemented ! (
291+ "create_command: Action {:?} not supported yet." ,
292+ self . action
293+ ) ,
294+ } ,
312295 } ;
313296
314297 if raw_cmd. is_none ( ) {
@@ -359,14 +342,13 @@ impl Executor {
359342
360343 fn prepare_input ( & self ) -> Result < ( ) , ExecutorError > {
361344 // 拉取源文件
362- if self . source_dir . is_none ( ) {
363- return Ok ( ( ) ) ;
364- }
365345 let task = self . entity . task ( ) ;
366- let source_dir = self . source_dir . as_ref ( ) . unwrap ( ) ;
367-
368346 match & task. task_type {
369347 TaskType :: BuildFromSource ( cs) => {
348+ if self . source_dir . is_none ( ) {
349+ return Ok ( ( ) ) ;
350+ }
351+ let source_dir = self . source_dir . as_ref ( ) . unwrap ( ) ;
370352 match cs {
371353 CodeSource :: Git ( git) => {
372354 git. prepare ( source_dir)
@@ -375,15 +357,29 @@ impl Executor {
375357 // 本地源文件,不需要拉取
376358 CodeSource :: Local ( _) => return Ok ( ( ) ) ,
377359 // 在线压缩包,需要下载
378- CodeSource :: Archive ( _) => todo ! ( ) ,
360+ CodeSource :: Archive ( archive) => {
361+ archive
362+ . download_unzip ( source_dir)
363+ . map_err ( |e| ExecutorError :: PrepareEnvError ( e) ) ?;
364+ }
379365 }
380366 }
381367 TaskType :: InstallFromPrebuilt ( pb) => {
382368 match pb {
383369 // 本地源文件,不需要拉取
384- PrebuiltSource :: Local ( _) => return Ok ( ( ) ) ,
370+ PrebuiltSource :: Local ( local_source) => {
371+ let local_path = local_source. path ( ) ;
372+ let target_path = & self . build_dir . path ;
373+ FileUtils :: copy_dir_all ( & local_path, & target_path)
374+ . map_err ( |e| ExecutorError :: TaskFailed ( e) ) ?; // let mut cmd = "cp -r ".to_string();
375+ return Ok ( ( ) ) ;
376+ }
385377 // 在线压缩包,需要下载
386- PrebuiltSource :: Archive ( _) => todo ! ( ) ,
378+ PrebuiltSource :: Archive ( archive) => {
379+ archive
380+ . download_unzip ( & self . build_dir )
381+ . map_err ( |e| ExecutorError :: PrepareEnvError ( e) ) ?;
382+ }
387383 }
388384 }
389385 }
0 commit comments