11use {
2- super :: * ,
3- crate :: nvim:: BufferDirection ,
4- crate :: types:: { BuildConfiguration , Platform } ,
2+ super :: * , crate :: nvim:: BufferDirection , crate :: store:: DeviceLookup ,
3+ crate :: types:: BuildConfiguration ,
54} ;
65
7- #[ derive( Debug , Serialize , Deserialize ) ]
8- pub struct DeviceLookup {
9- name : String ,
10- udid : String ,
11- platform : Platform ,
12- }
13-
14- /// Run a project.
15- #[ derive( Debug , Serialize , Deserialize ) ]
16- pub struct Run {
17- pub client : Client ,
18- pub config : BuildConfiguration ,
19- pub device : Option < DeviceLookup > ,
20- pub direction : Option < BufferDirection > ,
21- }
22-
236#[ cfg( feature = "daemon" ) ]
247use {
258 crate :: constants:: DAEMON_STATE ,
269 crate :: runner:: Runner ,
10+ crate :: types:: Platform ,
11+ crate :: util:: serde:: value_or_default,
2712 crate :: xcode:: { append_build_root, build_with_loggger} ,
2813 crate :: Error ,
2914 xcodebuild:: runner:: build_settings,
3015} ;
3116
17+ /// Run a project.
18+ #[ derive( Debug , Serialize , Deserialize ) ]
19+ pub struct Run {
20+ pub client : Client ,
21+ pub config : BuildConfiguration ,
22+ #[ cfg_attr( feature = "daemon" , serde( deserialize_with = "value_or_default" ) ) ]
23+ pub device : DeviceLookup ,
24+ #[ cfg_attr( feature = "daemon" , serde( deserialize_with = "value_or_default" ) ) ]
25+ pub direction : BufferDirection ,
26+ }
27+
3228#[ cfg( feature = "daemon" ) ]
3329#[ async_trait:: async_trait]
3430impl Handler for Run {
3531 async fn handle ( self ) -> Result < ( ) > {
3632 let Client { pid, root, .. } = & self . client ;
33+ tracing:: info!( "{:#?}" , self ) ;
3734
3835 tracing:: info!( "⚙️ Running command: {}" , self . config. to_string( ) ) ;
3936
4037 let state = DAEMON_STATE . clone ( ) . lock_owned ( ) . await ;
41- let direction = self . direction . clone ( ) ;
42- let platform = if let Some ( ref d) = self . device {
43- tracing:: info!( "{:#?}" , d. platform) ;
44- Some ( d. platform . clone ( ) )
45- } else {
46- None
47- } ;
38+ let device = state. devices . from_lookup ( self . device ) ;
39+ tracing:: info!( "{:#?}" , device) ;
4840
4941 let nvim = state. clients . get ( & pid) ?;
5042 let args = {
5143 let mut args = self . config . as_args ( ) ;
52- if let Some ( ref platform ) = platform {
53- args. extend ( platform . sdk_simulator_args ( ) )
44+ if let Some ( ref device ) = device {
45+ args. extend ( device . special_build_args ( ) )
5446 }
5547 append_build_root ( & root, args) ?
5648 } ;
5749
58- let ref mut logger = nvim. new_logger ( format ! ( "Run:{}" , self . config. target) , & direction) ;
50+ let ref mut logger = nvim. logger ( ) ;
51+
52+ logger. set_title ( format ! ( "Run:{}" , self . config. target) ) ;
53+ logger. set_direction ( & self . direction ) ;
5954
6055 let settings = build_settings ( & root, & args) . await ?;
61- let platform = match platform {
62- Some ( v ) => v ,
63- None => Platform :: from_display ( & settings . platform_display_name ) ? ,
64- } ;
56+ let platform = device
57+ . as_ref ( )
58+ . map ( |d| d . platform . clone ( ) )
59+ . unwrap_or_else ( || Platform :: from_display ( & settings . platform_display_name ) . unwrap ( ) ) ;
6560
6661 let success = build_with_loggger ( logger, & root, & args, true , true ) . await ?;
6762 if !success {
@@ -81,8 +76,8 @@ impl Handler for Run {
8176 client : self . client ,
8277 state,
8378 args,
84- udid : self . device . map ( |d| d. udid ) ,
85- direction,
79+ udid : device. map ( |d| d. udid . clone ( ) ) ,
80+ direction : self . direction ,
8681 }
8782 . run ( settings)
8883 . await ?;
@@ -101,8 +96,8 @@ impl<'a> Requester<'a, Run> for Run {
10196
10297impl ToString for Run {
10398 fn to_string ( & self ) -> String {
104- if let Some ( ref device ) = self . device {
105- format ! ( "run [{}] with {}" , device . name, self . config. to_string( ) )
99+ if let Some ( ref name ) = self . device . name {
100+ format ! ( "run [{}] with {}" , name, self . config. to_string( ) )
106101 } else {
107102 format ! ( "run with {}" , self . config. to_string( ) )
108103 }
@@ -122,19 +117,15 @@ impl<'a> FromLua<'a> for Run {
122117 Ok ( Self {
123118 client : table. get ( "client" ) ?,
124119 config : table. get ( "config" ) ?,
125- direction : table. get ( "direction" ) . ok ( ) ,
120+ direction : table. get ( "direction" ) . unwrap_or_default ( ) ,
126121 device : device
127122 . map ( |d| {
128123 let name = d. get ( "name" ) . ok ( ) ?;
129124 let udid = d. get ( "udid" ) . ok ( ) ?;
130- let platform = d. get ( "platform" ) . ok ( ) ?;
131- Some ( DeviceLookup {
132- name,
133- udid,
134- platform,
135- } )
125+ Some ( DeviceLookup { name, udid } )
136126 } )
137- . flatten ( ) ,
127+ . flatten ( )
128+ . unwrap_or_default ( ) ,
138129 } )
139130 }
140131}
0 commit comments