diff --git a/src/file_filter.rs b/src/file_filter.rs index 493d1b58b..58ebc87f5 100644 --- a/src/file_filter.rs +++ b/src/file_filter.rs @@ -7,7 +7,7 @@ pub enum FilterType { Both(u32), } -#[derive(Default)] +#[derive(Default, Clone)] pub struct FileFilter { excl_line: Option, excl_start: Option, diff --git a/src/main.rs b/src/main.rs index c3252f36f..6690a825c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use regex::Regex; use rustc_hash::FxHashMap; use serde_json::Value; use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode, WriteLogger}; +use std::borrow::Borrow; use std::fs::{self, File}; use std::ops::Deref; use std::panic; @@ -107,8 +108,9 @@ struct Opt { "html", "cobertura", ], + multiple=true )] - output_type: OutputType, + output_type: Vec, /// Specifies the output path. #[structopt(short, long, value_name = "PATH", alias = "output-file")] output_path: Option, @@ -390,68 +392,83 @@ fn main() { } } - let result_map_mutex = Arc::try_unwrap(result_map).unwrap(); - let result_map = result_map_mutex.into_inner().unwrap(); - - let path_mapping_mutex = Arc::try_unwrap(path_mapping).unwrap(); - let path_mapping = path_mapping_mutex.into_inner().unwrap(); - - let iterator = rewrite_paths( - result_map, - path_mapping, - source_root.as_deref(), - prefix_dir.as_deref(), - opt.ignore_not_existing, - &opt.ignore_dir, - &opt.keep_dir, - filter_option, - file_filter, - ); - - match opt.output_type { - OutputType::Ade => output_activedata_etl(iterator, opt.output_path.as_deref(), demangle), - OutputType::Lcov => output_lcov(iterator, opt.output_path.as_deref(), demangle), - OutputType::Coveralls => output_coveralls( - iterator, - opt.token.as_deref(), - opt.service_name.as_deref(), - &opt.service_number.unwrap_or_default(), - opt.service_job_id.as_deref(), - &opt.service_pull_request.unwrap_or_default(), - &opt.commit_sha.unwrap_or_default(), - false, - opt.output_path.as_deref(), - &opt.vcs_branch, - opt.parallel, - demangle, - ), - OutputType::CoverallsPlus => output_coveralls( - iterator, - opt.token.as_deref(), - opt.service_name.as_deref(), - &opt.service_number.unwrap_or_default(), - opt.service_job_id.as_deref(), - &opt.service_pull_request.unwrap_or_default(), - &opt.commit_sha.unwrap_or_default(), - true, - opt.output_path.as_deref(), - &opt.vcs_branch, - opt.parallel, - demangle, - ), - OutputType::Files => output_files(iterator, opt.output_path.as_deref()), - OutputType::Covdir => output_covdir(iterator, opt.output_path.as_deref()), - OutputType::Html => output_html( - iterator, - opt.output_path.as_deref(), - num_threads, - opt.branch, - ), - OutputType::Cobertura => output_cobertura( + let Opt { + service_number, + service_pull_request, + commit_sha, + output_path, + branch, + parallel, + ignore_not_existing, + .. + } = opt; + let service_number = service_number.unwrap_or_default(); + let service_pull_request = service_pull_request.unwrap_or_default(); + let commit_sha = commit_sha.unwrap_or_default(); + let output_path = output_path.as_deref(); + let ignore_dir = &opt.ignore_dir; + let keep_dir = &opt.keep_dir; + let token = opt.token.as_deref(); + let service_name = opt.service_name.as_deref(); + let service_job = opt.service_job_id.as_deref(); + let vcs_branch = &opt.vcs_branch; + opt.output_type.iter().for_each(|f| { + let result_map = Arc::clone(&result_map); + let path_mapping = Arc::clone(&path_mapping); + let result_map_mutex = Arc::try_unwrap(result_map).unwrap(); + let result_map = result_map_mutex.into_inner().unwrap(); + + let path_mapping_mutex = Arc::try_unwrap(path_mapping).unwrap(); + let path_mapping = path_mapping_mutex.into_inner().unwrap(); + let path = rewrite_paths( + result_map, + path_mapping, source_root.as_deref(), - iterator, - opt.output_path.as_deref(), - demangle, - ), - }; + prefix_dir.as_deref(), + ignore_not_existing, + ignore_dir, + keep_dir, + filter_option, + file_filter.clone(), + ); + let iterator = Box::new(path.into_iter()); + match f { + OutputType::Ade => output_activedata_etl(iterator, output_path, demangle), + OutputType::Lcov => output_lcov(iterator, output_path, demangle), + OutputType::Coveralls => output_coveralls( + iterator, + token, + service_name, + &service_number, + service_job, + &service_pull_request, + &commit_sha, + false, + output_path, + vcs_branch, + parallel, + demangle, + ), + OutputType::CoverallsPlus => output_coveralls( + iterator, + token, + service_name, + &service_number, + service_job, + &service_pull_request, + &commit_sha, + true, + output_path, + vcs_branch, + parallel, + demangle, + ), + OutputType::Files => output_files(iterator, output_path), + OutputType::Covdir => output_covdir(iterator, output_path), + OutputType::Html => output_html(iterator, output_path, num_threads, branch), + OutputType::Cobertura => { + output_cobertura(source_root.as_deref(), iterator, output_path, demangle) + } + }; + }); } diff --git a/src/path_rewriting.rs b/src/path_rewriting.rs index 73468c95f..6ce5b45a4 100644 --- a/src/path_rewriting.rs +++ b/src/path_rewriting.rs @@ -235,7 +235,7 @@ pub fn rewrite_paths( to_keep_dirs: &[impl AsRef], filter_option: Option, file_filter: crate::FileFilter, -) -> CovResultIter { +) -> Vec<(PathBuf, PathBuf, CovResult)> { let to_ignore_globset = to_globset(to_ignore_dirs); let to_keep_globset = to_globset(to_keep_dirs); @@ -341,11 +341,7 @@ pub fn rewrite_paths( Some((abs_path, rel_path, result)) }); - Box::new( - results - .collect::>() - .into_iter(), - ) + results.collect::>() } #[cfg(test)] @@ -423,16 +419,19 @@ mod tests { fn test_rewrite_paths_basic() { let mut result_map: CovResultMap = FxHashMap::default(); result_map.insert("main.cpp".to_string(), empty_result!()); - let results = rewrite_paths( - result_map, - None, - None, - None, - false, - &[""; 0], - &[""; 0], - None, - Default::default(), + let results = Box::new( + rewrite_paths( + result_map, + None, + None, + None, + false, + &[""; 0], + &[""; 0], + None, + Default::default(), + ) + .into_iter(), ); let mut count = 0; for (abs_path, rel_path, result) in results { @@ -922,16 +921,19 @@ mod tests { #[should_panic] fn test_rewrite_paths_rewrite_path_using_relative_source_directory() { let result_map: CovResultMap = FxHashMap::default(); - rewrite_paths( - result_map, - None, - Some(Path::new("tests")), - None, - true, - &[""; 0], - &[""; 0], - None, - Default::default(), + Box::new( + rewrite_paths( + result_map, + None, + Some(Path::new("tests")), + None, + true, + &[""; 0], + &[""; 0], + None, + Default::default(), + ) + .into_iter(), ) .any(|_| false); } @@ -1052,16 +1054,19 @@ mod tests { let mut result_map: CovResultMap = FxHashMap::default(); result_map.insert("java/main.java".to_string(), empty_result!()); result_map.insert("main.rs".to_string(), empty_result!()); - let results = rewrite_paths( - result_map, - None, - Some(&canonicalize_path(".").unwrap()), - None, - true, - &[""; 0], - &[""; 0], - None, - Default::default(), + let results = Box::new( + rewrite_paths( + result_map, + None, + Some(&canonicalize_path(".").unwrap()), + None, + true, + &[""; 0], + &[""; 0], + None, + Default::default(), + ) + .into_iter(), ); let mut results: Vec<(PathBuf, PathBuf, CovResult)> = results.collect(); assert!(results.len() == 1);