@@ -19,6 +19,7 @@ use std::time::SystemTime;
19
19
#[ derive( Debug , Clone ) ]
20
20
pub struct SourceFileMeta {
21
21
pub modified : SystemTime ,
22
+ pub is_type_dev : bool ,
22
23
}
23
24
24
25
#[ derive( Debug , Clone ) ]
@@ -112,6 +113,13 @@ impl Package {
112
113
. expect ( "namespace should be set for mlmap module" ) ;
113
114
self . get_build_path ( ) . join ( format ! ( "{}.cmi" , suffix) )
114
115
}
116
+
117
+ pub fn is_source_file_type_dev ( & self , path : & Path ) -> bool {
118
+ self . source_files
119
+ . as_ref ( )
120
+ . and_then ( |sf| sf. get ( path) . map ( |sfm| sfm. is_type_dev ) )
121
+ . unwrap_or ( false )
122
+ }
115
123
}
116
124
117
125
impl PartialEq for Package {
@@ -138,6 +146,7 @@ pub fn read_folders(
138
146
package_dir : & Path ,
139
147
path : & Path ,
140
148
recurse : bool ,
149
+ is_type_dev : bool ,
141
150
) -> Result < AHashMap < PathBuf , SourceFileMeta > , Box < dyn error:: Error > > {
142
151
let mut map: AHashMap < PathBuf , SourceFileMeta > = AHashMap :: new ( ) ;
143
152
let path_buf = PathBuf :: from ( path) ;
@@ -147,6 +156,7 @@ pub fn read_folders(
147
156
path. to_owned ( ) ,
148
157
SourceFileMeta {
149
158
modified : meta. modified ( ) . unwrap ( ) ,
159
+ is_type_dev,
150
160
} ,
151
161
)
152
162
} ) ;
@@ -159,7 +169,7 @@ pub fn read_folders(
159
169
let path_ext = entry_path_buf. extension ( ) . and_then ( |x| x. to_str ( ) ) ;
160
170
let new_path = path_buf. join ( & name) ;
161
171
if metadata. file_type ( ) . is_dir ( ) && recurse {
162
- match read_folders ( filter, package_dir, & new_path, recurse) {
172
+ match read_folders ( filter, package_dir, & new_path, recurse, is_type_dev ) {
163
173
Ok ( s) => map. extend ( s) ,
164
174
Err ( e) => log:: error!( "Could not read directory: {}" , e) ,
165
175
}
@@ -174,6 +184,7 @@ pub fn read_folders(
174
184
path,
175
185
SourceFileMeta {
176
186
modified : metadata. modified ( ) . unwrap ( ) ,
187
+ is_type_dev,
177
188
} ,
178
189
) ;
179
190
}
@@ -297,11 +308,16 @@ fn read_dependencies(
297
308
project_root : & Path ,
298
309
workspace_root : & Option < PathBuf > ,
299
310
show_progress : bool ,
311
+ build_dev_deps : bool ,
300
312
) -> Vec < Dependency > {
301
- return parent_config
302
- . bs_dependencies
303
- . to_owned ( )
304
- . unwrap_or_default ( )
313
+ let mut dependencies = parent_config. bs_dependencies . to_owned ( ) . unwrap_or_default ( ) ;
314
+
315
+ // Concatenate dev dependencies if build_dev_deps is true
316
+ if build_dev_deps && let Some ( dev_deps) = parent_config. bs_dev_dependencies . to_owned ( ) {
317
+ dependencies. extend ( dev_deps) ;
318
+ }
319
+
320
+ dependencies
305
321
. iter ( )
306
322
. filter_map ( |package_name| {
307
323
if registered_dependencies_set. contains ( package_name) {
@@ -360,7 +376,8 @@ fn read_dependencies(
360
376
& canonical_path,
361
377
project_root,
362
378
workspace_root,
363
- show_progress
379
+ show_progress,
380
+ build_dev_deps
364
381
) ;
365
382
366
383
Dependency {
@@ -371,7 +388,7 @@ fn read_dependencies(
371
388
dependencies,
372
389
}
373
390
} )
374
- . collect :: < Vec < Dependency > > ( ) ;
391
+ . collect ( )
375
392
}
376
393
377
394
fn flatten_dependencies ( dependencies : Vec < Dependency > ) -> Vec < Dependency > {
@@ -461,6 +478,7 @@ fn read_packages(
461
478
project_root : & Path ,
462
479
workspace_root : & Option < PathBuf > ,
463
480
show_progress : bool ,
481
+ build_dev_deps : bool ,
464
482
) -> Result < AHashMap < String , Package > > {
465
483
let root_config = read_config ( project_root) ?;
466
484
@@ -477,6 +495,7 @@ fn read_packages(
477
495
project_root,
478
496
workspace_root,
479
497
show_progress,
498
+ build_dev_deps,
480
499
) ) ;
481
500
dependencies. iter ( ) . for_each ( |d| {
482
501
if !map. contains_key ( & d. name ) {
@@ -515,9 +534,14 @@ pub fn get_source_files(
515
534
} ;
516
535
517
536
let path_dir = Path :: new ( & source. dir ) ;
537
+ let is_type_dev = type_
538
+ . as_ref ( )
539
+ . map ( |t| t. as_str ( ) == "dev" )
540
+ . unwrap_or ( false )
541
+ . clone ( ) ;
518
542
match ( build_dev_deps, type_) {
519
543
( false , Some ( type_) ) if type_ == "dev" => ( ) ,
520
- _ => match read_folders ( filter, package_dir, path_dir, recurse) {
544
+ _ => match read_folders ( filter, package_dir, path_dir, recurse, is_type_dev ) {
521
545
Ok ( files) => map. extend ( files) ,
522
546
523
547
Err ( _e) => log:: error!(
@@ -596,7 +620,7 @@ pub fn make(
596
620
show_progress : bool ,
597
621
build_dev_deps : bool ,
598
622
) -> Result < AHashMap < String , Package > > {
599
- let map = read_packages ( root_folder, workspace_root, show_progress) ?;
623
+ let map = read_packages ( root_folder, workspace_root, show_progress, build_dev_deps ) ?;
600
624
601
625
/* Once we have the deduplicated packages, we can add the source files for each - to minimize
602
626
* the IO */
@@ -720,6 +744,8 @@ pub fn parse_packages(build_state: &mut BuildState) {
720
744
compile_dirty : false ,
721
745
last_compiled_cmt : None ,
722
746
last_compiled_cmi : None ,
747
+ // Not sure if this is correct
748
+ is_type_dev : false ,
723
749
} ,
724
750
) ;
725
751
} ) ;
@@ -772,6 +798,7 @@ pub fn parse_packages(build_state: &mut BuildState) {
772
798
compile_dirty : true ,
773
799
last_compiled_cmt : None ,
774
800
last_compiled_cmi : None ,
801
+ is_type_dev : metadata. is_type_dev ,
775
802
} ) ;
776
803
} else {
777
804
// remove last character of string: resi -> res, rei -> re, mli -> ml
@@ -833,6 +860,7 @@ pub fn parse_packages(build_state: &mut BuildState) {
833
860
compile_dirty : true ,
834
861
last_compiled_cmt : None ,
835
862
last_compiled_cmi : None ,
863
+ is_type_dev : metadata. is_type_dev ,
836
864
} ) ;
837
865
}
838
866
}
0 commit comments