Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR for issue #496 #768

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/file_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum FilterType {
Both(u32),
}

#[derive(Default)]
#[derive(Default, Clone)]
pub struct FileFilter {
excl_line: Option<Regex>,
excl_start: Option<Regex>,
Expand Down
145 changes: 81 additions & 64 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,8 +108,9 @@ struct Opt {
"html",
"cobertura",
],
multiple=true
)]
output_type: OutputType,
output_type: Vec<OutputType>,
/// Specifies the output path.
#[structopt(short, long, value_name = "PATH", alias = "output-file")]
output_path: Option<PathBuf>,
Expand Down Expand Up @@ -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)
}
};
});
}
77 changes: 41 additions & 36 deletions src/path_rewriting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub fn rewrite_paths(
to_keep_dirs: &[impl AsRef<str>],
filter_option: Option<bool>,
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);

Expand Down Expand Up @@ -341,11 +341,7 @@ pub fn rewrite_paths(
Some((abs_path, rel_path, result))
});

Box::new(
results
.collect::<Vec<(PathBuf, PathBuf, CovResult)>>()
.into_iter(),
)
results.collect::<Vec<(PathBuf, PathBuf, CovResult)>>()
}

#[cfg(test)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down