@@ -11,6 +11,9 @@ use std::path::PathBuf;
1111
1212use crate :: Project ;
1313
14+ #[ cfg( feature = "xcodegen" ) ]
15+ use crate :: xcodegen;
16+
1417/// Managed Workspace
1518#[ derive( Debug ) ]
1619pub struct Workspace {
@@ -94,14 +97,17 @@ impl Workspace {
9497 }
9598
9699 /// Regenerate compiled commands and xcodeGen if project.yml exists
97- #[ cfg( feature = "xcode" ) ]
98- pub async fn on_dirctory_change (
100+ #[ cfg( all ( feature = "xcode" , feature = "watcher" ) ) ]
101+ pub async fn on_directory_change (
99102 & mut self ,
100103 path : PathBuf ,
101104 _event : notify:: EventKind ,
102105 ) -> Result < ( ) > {
103- if self . is_xcodegen_project ( ) {
106+ if crate :: xcodegen :: is_workspace ( self ) {
104107 let is_config_file = path. file_name ( ) . unwrap ( ) . eq ( "project" ) ;
108+ // FIXME: should've been true
109+ tracing:: debug!( "is_config_file: {is_config_file}" ) ;
110+
105111 self . update_xcodeproj ( is_config_file) . await ?;
106112 }
107113
@@ -112,55 +118,31 @@ impl Workspace {
112118 }
113119
114120 /// Update .compile commands
121+ #[ cfg( feature = "xcodegen" ) ]
115122 pub async fn update_xcodeproj ( & mut self , update_config : bool ) -> Result < ( ) > {
116- /*
117- FIXME: make xCodeGen binary path configurable.
118-
119- Current implementation will not work unless the user has xcodeGen located in
120- `~/.mint/bin/xcodegen`. Should either make it configurable as well as support a
121- number of paths by default.
122- */
123- let xcodegen_path = dirs:: home_dir ( ) . unwrap ( ) . join ( ".mint/bin/xcodegen" ) ;
124- // TODO: move xcodegen generate command to it's own module
125- let xcodegen = tokio:: process:: Command :: new ( xcodegen_path)
126- . current_dir ( self . root . clone ( ) )
127- . stdout ( std:: process:: Stdio :: null ( ) )
128- . arg ( "generate" )
129- . spawn ( )
130- . expect ( "Failed to start xcodeGen." )
131- . wait ( )
132- . await
133- . expect ( "Failed to run xcodeGen." ) ;
134-
135- if xcodegen. success ( ) {
136- tracing:: info!( "Updated {}.xcodeproj" , self . name( ) ) ;
137- if update_config {
138- tracing:: debug!( "Updated internal state.{}.project" , self . name( ) ) ;
139- let path = self . xcodegen_config_path ( ) ;
140- self . project = Project :: new_from_project_yml ( self . root . clone ( ) , path) . await ?;
123+ match xcodegen:: generate ( & self . root ) . await {
124+ Ok ( msg) => {
125+ tracing:: info!( "Updated {}.xcodeproj" , self . name( ) ) ;
126+ tracing:: trace!( "{:?}" , msg) ;
127+ if update_config {
128+ tracing:: info!( "Updated internal state.{}.project" , self . name( ) ) ;
129+ self . project = Project :: new_from_project_yml (
130+ self . root . clone ( ) ,
131+ xcodegen:: config_path ( self ) ,
132+ )
133+ . await ?;
134+ }
135+ Ok ( ( ) )
136+ }
137+ Err ( e) => {
138+ tracing:: error!( "{:?}" , e) ;
139+ Err ( e)
141140 }
142141 }
143-
144- Ok ( ( ) )
145142 }
146143
147- /// TODO: move xcodegen related code to it's own module
148- /// Checks whether current workspace is xcodegen project.
149- pub fn is_xcodegen_project ( & self ) -> bool {
150- self . xcodegen_config_path ( ) . exists ( )
151- }
152-
153- pub fn xcodegen_config_path ( & self ) -> PathBuf {
154- /*
155- TODO: support otherways to identify xcodegen project
156-
157- Some would have xcodegen config as json file or
158- have different location to where they store xcodegen project config.
159- */
160- self . root . join ( "project.yml" )
161- }
162144 pub fn get_ignore_patterns ( & self ) -> Option < Vec < String > > {
163- if self . is_xcodegen_project ( ) {
145+ if crate :: xcodegen :: is_workspace ( self ) {
164146 return Some ( self . project . config ( ) . ignore . clone ( ) ) ;
165147 }
166148 return None ;
0 commit comments