@@ -37,28 +37,10 @@ pub enum ProjectWorkspace {
37
37
/// the current workspace.
38
38
#[ derive( Debug , Clone ) ]
39
39
pub struct PackageRoot {
40
- /// Path to the root folder
41
- path : AbsPathBuf ,
42
40
/// Is a member of the current workspace
43
- is_member : bool ,
44
- out_dir : Option < AbsPathBuf > ,
45
- }
46
- impl PackageRoot {
47
- pub fn new_member ( path : AbsPathBuf ) -> PackageRoot {
48
- Self { path, is_member : true , out_dir : None }
49
- }
50
- pub fn new_non_member ( path : AbsPathBuf ) -> PackageRoot {
51
- Self { path, is_member : false , out_dir : None }
52
- }
53
- pub fn path ( & self ) -> & AbsPath {
54
- & self . path
55
- }
56
- pub fn out_dir ( & self ) -> Option < & AbsPath > {
57
- self . out_dir . as_deref ( )
58
- }
59
- pub fn is_member ( & self ) -> bool {
60
- self . is_member
61
- }
41
+ pub is_member : bool ,
42
+ pub include : Vec < AbsPathBuf > ,
43
+ pub exclude : Vec < AbsPathBuf > ,
62
44
}
63
45
64
46
#[ derive( Debug , Clone , PartialEq , Eq , Hash , Ord , PartialOrd ) ]
@@ -195,18 +177,38 @@ impl ProjectWorkspace {
195
177
/// the root is a member of the current workspace
196
178
pub fn to_roots ( & self ) -> Vec < PackageRoot > {
197
179
match self {
198
- ProjectWorkspace :: Json { project } => {
199
- project. roots . iter ( ) . map ( |r| PackageRoot :: new_member ( r. path . clone ( ) ) ) . collect ( )
200
- }
180
+ ProjectWorkspace :: Json { project } => project
181
+ . roots
182
+ . iter ( )
183
+ . map ( |r| {
184
+ let path = r. path . clone ( ) ;
185
+ let include = vec ! [ path] ;
186
+ PackageRoot { is_member : true , include, exclude : Vec :: new ( ) }
187
+ } )
188
+ . collect ( ) ,
201
189
ProjectWorkspace :: Cargo { cargo, sysroot } => cargo
202
190
. packages ( )
203
- . map ( |pkg| PackageRoot {
204
- path : cargo[ pkg] . root ( ) . to_path_buf ( ) ,
205
- is_member : cargo[ pkg] . is_member ,
206
- out_dir : cargo[ pkg] . out_dir . clone ( ) ,
191
+ . map ( |pkg| {
192
+ let is_member = cargo[ pkg] . is_member ;
193
+ let pkg_root = cargo[ pkg] . root ( ) . to_path_buf ( ) ;
194
+
195
+ let mut include = vec ! [ pkg_root. clone( ) ] ;
196
+ include. extend ( cargo[ pkg] . out_dir . clone ( ) ) ;
197
+
198
+ let mut exclude = vec ! [ pkg_root. join( ".git" ) ] ;
199
+ if is_member {
200
+ exclude. push ( pkg_root. join ( "target" ) ) ;
201
+ } else {
202
+ exclude. push ( pkg_root. join ( "tests" ) ) ;
203
+ exclude. push ( pkg_root. join ( "examples" ) ) ;
204
+ exclude. push ( pkg_root. join ( "benches" ) ) ;
205
+ }
206
+ PackageRoot { is_member, include, exclude }
207
207
} )
208
- . chain ( sysroot. crates ( ) . map ( |krate| {
209
- PackageRoot :: new_non_member ( sysroot[ krate] . root_dir ( ) . to_path_buf ( ) )
208
+ . chain ( sysroot. crates ( ) . map ( |krate| PackageRoot {
209
+ is_member : false ,
210
+ include : vec ! [ sysroot[ krate] . root_dir( ) . to_path_buf( ) ] ,
211
+ exclude : Vec :: new ( ) ,
210
212
} ) )
211
213
. collect ( ) ,
212
214
}
0 commit comments