@@ -81,21 +81,25 @@ pub fn llvm_profiles_to_lcov(
8181 profile_paths : & [ PathBuf ] ,
8282 binary_path : & Path ,
8383 working_dir : & Path ,
84- num_threads : usize ,
84+ num_threads : Option < usize > ,
8585) -> Result < Vec < Vec < u8 > > , String > {
8686 let profdata_path = working_dir. join ( "grcov.profdata" ) ;
8787
88- let num_threads = num_threads. to_string ( ) ;
89- let args = vec ! [
88+ let mut args = vec ! [
9089 "merge" . as_ref( ) ,
9190 "-f" . as_ref( ) ,
9291 "-" . as_ref( ) ,
9392 "-sparse" . as_ref( ) ,
9493 "-o" . as_ref( ) ,
9594 profdata_path. as_ref( ) ,
96- "--num-threads" . as_ref( ) ,
97- num_threads. as_ref( ) ,
9895 ] ;
96+ let num_threads_str: String ;
97+ // Only pass --num-threads if explicitly specified by the user
98+ if let Some ( num) = num_threads {
99+ num_threads_str = num. to_string ( ) ;
100+ args. push ( "--num-threads" . as_ref ( ) ) ;
101+ args. push ( num_threads_str. as_ref ( ) ) ;
102+ }
99103
100104 let stdin_paths: String = profile_paths. iter ( ) . fold ( "" . into ( ) , |mut a, x| {
101105 a. push_str ( x. to_string_lossy ( ) . as_ref ( ) ) ;
@@ -111,14 +115,21 @@ pub fn llvm_profiles_to_lcov(
111115 let results = binaries
112116 . into_par_iter ( )
113117 . filter_map ( |binary| {
114- let args = [
118+ let mut args = vec ! [
115119 "export" . as_ref( ) ,
116120 binary. as_ref( ) ,
117121 "--instr-profile" . as_ref( ) ,
118122 profdata_path. as_ref( ) ,
119123 "--format" . as_ref( ) ,
120124 "lcov" . as_ref( ) ,
121125 ] ;
126+ let num_threads_str: String ;
127+ // Only pass --num-threads if explicitly specified by the user
128+ if let Some ( num) = num_threads {
129+ num_threads_str = num. to_string ( ) ;
130+ args. push ( "--num-threads" . as_ref ( ) ) ;
131+ args. push ( num_threads_str. as_ref ( ) ) ;
132+ }
122133
123134 match run ( & cov_tool_path, & args) {
124135 Ok ( result) => Some ( result) ,
@@ -305,7 +316,7 @@ mod tests {
305316 & [ tmp_path. join ( "default.profraw" ) ] ,
306317 & PathBuf :: from ( "src" ) , // There is no binary file in src
307318 tmp_path,
308- 1 ,
319+ None ,
309320 ) ;
310321 assert ! ( lcovs. is_ok( ) ) ;
311322 let lcovs = lcovs. unwrap ( ) ;
@@ -322,7 +333,7 @@ mod tests {
322333 & [ tmp_path. join ( "default.profraw" ) ] ,
323334 & tmp_path. join ( binary_path) ,
324335 tmp_path,
325- 1 ,
336+ None ,
326337 ) ;
327338 assert ! ( lcovs. is_ok( ) , "Error: {}" , lcovs. unwrap_err( ) ) ;
328339 let lcovs = lcovs. unwrap ( ) ;
@@ -355,8 +366,12 @@ mod tests {
355366
356367 assert_eq ! ( status. unwrap( ) . code( ) . unwrap( ) , 0 ) ;
357368
358- let lcovs =
359- llvm_profiles_to_lcov ( & [ profdata_path] , & tmp_path. join ( binary_path) , tmp_path, 1 ) ;
369+ let lcovs = llvm_profiles_to_lcov (
370+ & [ profdata_path] ,
371+ & tmp_path. join ( binary_path) ,
372+ tmp_path,
373+ None ,
374+ ) ;
360375
361376 assert ! ( lcovs. is_ok( ) , "Error: {}" , lcovs. unwrap_err( ) ) ;
362377 let lcovs = lcovs. unwrap ( ) ;
@@ -403,7 +418,7 @@ mod tests {
403418 & [ path_with, path_without] ,
404419 & tmp_path. join ( bin_path) ,
405420 tmp_path,
406- 1 ,
421+ None ,
407422 ) ;
408423
409424 assert ! ( lcovs. is_ok( ) , "Error: {}" , lcovs. unwrap_err( ) ) ;
0 commit comments