Skip to content

Commit ce4a608

Browse files
author
Bastian Schubert
committed
[mozilla#496 multiple outputs]
1 parent 085de2e commit ce4a608

File tree

5 files changed

+97
-92
lines changed

5 files changed

+97
-92
lines changed

src/cobertura.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ use quick_xml::{
33
Writer,
44
};
55
use rustc_hash::FxHashMap;
6-
use std::io::{BufWriter, Cursor, Write};
76
use std::path::Path;
87
use std::time::{SystemTime, UNIX_EPOCH};
8+
use std::{
9+
io::{BufWriter, Cursor, Write},
10+
path::PathBuf,
11+
};
912
use symbolic_common::Name;
1013
use symbolic_demangle::{Demangle, DemangleOptions};
1114

12-
use crate::defs::CovResultIter;
13-
use crate::output::get_target_output_writable;
15+
use crate::{output::get_target_output_writable, CovResult};
1416

1517
macro_rules! demangle {
1618
($name: expr, $demangle: expr, $options: expr) => {{
@@ -229,12 +231,13 @@ impl ToString for ConditionType {
229231
}
230232

231233
fn get_coverage(
232-
results: CovResultIter,
234+
results: &[(PathBuf, PathBuf, CovResult)],
233235
sources: Vec<String>,
234236
demangle: bool,
235237
demangle_options: DemangleOptions,
236238
) -> Coverage {
237239
let packages: Vec<Package> = results
240+
.iter()
238241
.map(|(_, rel_path, result)| {
239242
let all_lines: Vec<u32> = result.lines.iter().map(|(k, _)| k).cloned().collect();
240243

@@ -246,13 +249,12 @@ fn get_coverage(
246249
}
247250
start_indexes.sort_unstable();
248251

249-
let functions = result.functions;
250-
let result_lines = result.lines;
251-
let result_branches = result.branches;
252+
// let result_lines = result.lines.clone();
253+
// let result_branches = result.branches.clone();
252254

253255
let line_from_number = |number| {
254-
let hits = result_lines.get(&number).cloned().unwrap_or_default();
255-
if let Some(branches) = result_branches.get(&number) {
256+
let hits = result.lines.get(&number).cloned().unwrap_or_default();
257+
if let Some(branches) = result.branches.get(&number) {
256258
let conditions = branches
257259
.iter()
258260
.enumerate()
@@ -272,7 +274,8 @@ fn get_coverage(
272274
}
273275
};
274276

275-
let methods: Vec<Method> = functions
277+
let methods: Vec<Method> = result
278+
.functions
276279
.iter()
277280
.map(|(name, function)| {
278281
let mut func_end = end;
@@ -329,7 +332,7 @@ fn get_coverage(
329332

330333
pub fn output_cobertura(
331334
source_dir: Option<&Path>,
332-
results: CovResultIter,
335+
results: &[(PathBuf, PathBuf, CovResult)],
333336
output_file: Option<&Path>,
334337
demangle: bool,
335338
) {

src/defs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pub type JobSender = Sender<Option<WorkItem>>;
5858

5959
pub type CovResultMap = FxHashMap<String, CovResult>;
6060
pub type SyncCovResultMap = Mutex<CovResultMap>;
61-
pub type CovResultIter = Box<dyn Iterator<Item = (PathBuf, PathBuf, CovResult)>>;
6261

6362
#[derive(Debug, Default)]
6463
pub struct CDStats {

src/main.rs

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct Opt {
8787
short = "t",
8888
long,
8989
long_help = "\
90-
Sets a custom output type:\n\
90+
Comma separated list of custom output types:\n\
9191
- *html* for a HTML coverage report;\n\
9292
- *coveralls* for the Coveralls specific format;\n\
9393
- *lcov* for the lcov INFO format;\n\
@@ -96,26 +96,18 @@ struct Opt {
9696
- *ade* for the ActiveData-ETL specific format;\n\
9797
- *files* to only return a list of files.\n\
9898
- *markdown* for human easy read.\n\
99+
- *cobertura* for output in coberura format.\n\
99100
",
100101
value_name = "OUTPUT TYPE",
101102
default_value = "lcov",
102103
requires_ifs = &[
103104
("coveralls", "coveralls-auth"),
104105
("coveralls+", "coveralls-auth"),
105106
],
106-
possible_values = &[
107-
"ade",
108-
"lcov",
109-
"coveralls",
110-
"coveralls+",
111-
"files",
112-
"covdir",
113-
"html",
114-
"cobertura",
115-
"markdown",
116-
],
107+
108+
use_delimiter = true
117109
)]
118-
output_type: OutputType,
110+
output_types: Vec<OutputType>,
119111
/// Specifies the output path.
120112
#[structopt(short, long, value_name = "PATH", alias = "output-file")]
121113
output_path: Option<PathBuf>,
@@ -422,52 +414,59 @@ fn main() {
422414
file_filter,
423415
);
424416

425-
match opt.output_type {
426-
OutputType::Ade => output_activedata_etl(iterator, opt.output_path.as_deref(), demangle),
427-
OutputType::Lcov => output_lcov(iterator, opt.output_path.as_deref(), demangle),
428-
OutputType::Coveralls => output_coveralls(
429-
iterator,
430-
opt.token.as_deref(),
431-
opt.service_name.as_deref(),
432-
&opt.service_number.unwrap_or_default(),
433-
opt.service_job_id.as_deref(),
434-
&opt.service_pull_request.unwrap_or_default(),
435-
&opt.commit_sha.unwrap_or_default(),
436-
false,
437-
opt.output_path.as_deref(),
438-
&opt.vcs_branch,
439-
opt.parallel,
440-
demangle,
441-
),
442-
OutputType::CoverallsPlus => output_coveralls(
443-
iterator,
444-
opt.token.as_deref(),
445-
opt.service_name.as_deref(),
446-
&opt.service_number.unwrap_or_default(),
447-
opt.service_job_id.as_deref(),
448-
&opt.service_pull_request.unwrap_or_default(),
449-
&opt.commit_sha.unwrap_or_default(),
450-
true,
451-
opt.output_path.as_deref(),
452-
&opt.vcs_branch,
453-
opt.parallel,
454-
demangle,
455-
),
456-
OutputType::Files => output_files(iterator, opt.output_path.as_deref()),
457-
OutputType::Covdir => output_covdir(iterator, opt.output_path.as_deref()),
458-
OutputType::Html => output_html(
459-
iterator,
460-
opt.output_path.as_deref(),
461-
num_threads,
462-
opt.branch,
463-
opt.output_config_file.as_deref(),
464-
),
465-
OutputType::Cobertura => output_cobertura(
466-
source_root.as_deref(),
467-
iterator,
468-
opt.output_path.as_deref(),
469-
demangle,
470-
),
471-
OutputType::Markdown => output_markdown(iterator, opt.output_path.as_deref()),
472-
};
417+
let service_number = opt.service_number.unwrap_or_default();
418+
let service_pull_request = opt.service_pull_request.unwrap_or_default();
419+
let commit_sha = opt.commit_sha.unwrap_or_default();
420+
for output_type in &opt.output_types {
421+
match output_type {
422+
OutputType::Ade => {
423+
output_activedata_etl(&iterator, opt.output_path.as_deref(), demangle)
424+
}
425+
OutputType::Lcov => output_lcov(&iterator, opt.output_path.as_deref(), demangle),
426+
OutputType::Coveralls => output_coveralls(
427+
&iterator,
428+
opt.token.as_deref(),
429+
opt.service_name.as_deref(),
430+
&service_number,
431+
opt.service_job_id.as_deref(),
432+
&service_pull_request,
433+
&commit_sha,
434+
false,
435+
opt.output_path.as_deref(),
436+
&opt.vcs_branch,
437+
opt.parallel,
438+
demangle,
439+
),
440+
OutputType::CoverallsPlus => output_coveralls(
441+
&iterator,
442+
opt.token.as_deref(),
443+
opt.service_name.as_deref(),
444+
&service_number,
445+
opt.service_job_id.as_deref(),
446+
&service_pull_request,
447+
&commit_sha,
448+
true,
449+
opt.output_path.as_deref(),
450+
&opt.vcs_branch,
451+
opt.parallel,
452+
demangle,
453+
),
454+
OutputType::Files => output_files(&iterator, opt.output_path.as_deref()),
455+
OutputType::Covdir => output_covdir(&iterator, opt.output_path.as_deref()),
456+
OutputType::Html => output_html(
457+
&iterator,
458+
opt.output_path.as_deref(),
459+
num_threads,
460+
opt.branch,
461+
opt.output_config_file.as_deref(),
462+
),
463+
OutputType::Cobertura => output_cobertura(
464+
source_root.as_deref(),
465+
&iterator,
466+
opt.output_path.as_deref(),
467+
demangle,
468+
),
469+
OutputType::Markdown => output_markdown(&iterator, opt.output_path.as_deref()),
470+
};
471+
}
473472
}

src/output.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ pub fn get_target_output_writable(output_file: Option<&Path>) -> Box<dyn Write>
7070
write_target
7171
}
7272

73-
pub fn output_activedata_etl(results: CovResultIter, output_file: Option<&Path>, demangle: bool) {
73+
pub fn output_activedata_etl(
74+
results: &[(PathBuf, PathBuf, CovResult)],
75+
output_file: Option<&Path>,
76+
demangle: bool,
77+
) {
7478
let demangle_options = DemangleOptions::name_only();
7579
let mut writer = BufWriter::new(get_target_output_writable(output_file));
7680

@@ -180,7 +184,7 @@ pub fn output_activedata_etl(results: CovResultIter, output_file: Option<&Path>,
180184
}
181185
}
182186

183-
pub fn output_covdir(results: CovResultIter, output_file: Option<&Path>) {
187+
pub fn output_covdir(results: &[(PathBuf, PathBuf, CovResult)], output_file: Option<&Path>) {
184188
let mut writer = BufWriter::new(get_target_output_writable(output_file));
185189
let mut relative: FxHashMap<PathBuf, Rc<RefCell<CDDirStats>>> = FxHashMap::default();
186190
let global = Rc::new(RefCell::new(CDDirStats::new("".to_string())));
@@ -226,7 +230,7 @@ pub fn output_covdir(results: CovResultIter, output_file: Option<&Path>) {
226230

227231
prev_stats.borrow_mut().files.push(CDFileStats::new(
228232
path.file_name().unwrap().to_str().unwrap().to_string(),
229-
result.lines,
233+
result.lines.clone(),
230234
));
231235
}
232236

@@ -236,7 +240,11 @@ pub fn output_covdir(results: CovResultIter, output_file: Option<&Path>) {
236240
serde_json::to_writer(&mut writer, &global.into_json()).unwrap();
237241
}
238242

239-
pub fn output_lcov(results: CovResultIter, output_file: Option<&Path>, demangle: bool) {
243+
pub fn output_lcov(
244+
results: &[(PathBuf, PathBuf, CovResult)],
245+
output_file: Option<&Path>,
246+
demangle: bool,
247+
) {
240248
let demangle_options = DemangleOptions::name_only();
241249
let mut writer = BufWriter::new(get_target_output_writable(output_file));
242250
writer.write_all(b"TN:\n").unwrap();
@@ -413,7 +421,7 @@ fn get_coveralls_git_info(commit_sha: &str, vcs_branch: &str) -> Value {
413421
}
414422

415423
pub fn output_coveralls(
416-
results: CovResultIter,
424+
results: &[(PathBuf, PathBuf, CovResult)],
417425
repo_token: Option<&str>,
418426
service_name: Option<&str>,
419427
service_number: &str,
@@ -455,7 +463,7 @@ pub fn output_coveralls(
455463
if !with_function_info {
456464
source_files.push(json!({
457465
"name": rel_path,
458-
"source_digest": get_digest(abs_path),
466+
"source_digest": get_digest(abs_path.clone()),
459467
"coverage": coverage,
460468
"branches": branches,
461469
}));
@@ -471,7 +479,7 @@ pub fn output_coveralls(
471479

472480
source_files.push(json!({
473481
"name": rel_path,
474-
"source_digest": get_digest(abs_path),
482+
"source_digest": get_digest(abs_path.clone()),
475483
"coverage": coverage,
476484
"branches": branches,
477485
"functions": functions,
@@ -505,15 +513,15 @@ pub fn output_coveralls(
505513
serde_json::to_writer(&mut writer, &result).unwrap();
506514
}
507515

508-
pub fn output_files(results: CovResultIter, output_file: Option<&Path>) {
516+
pub fn output_files(results: &[(PathBuf, PathBuf, CovResult)], output_file: Option<&Path>) {
509517
let mut writer = BufWriter::new(get_target_output_writable(output_file));
510518
for (_, rel_path, _) in results {
511519
writeln!(writer, "{}", rel_path.display()).unwrap();
512520
}
513521
}
514522

515523
pub fn output_html(
516-
results: CovResultIter,
524+
results: &[(PathBuf, PathBuf, CovResult)],
517525
output_dir: Option<&Path>,
518526
num_threads: usize,
519527
branch_enabled: bool,
@@ -559,9 +567,9 @@ pub fn output_html(
559567
for (abs_path, rel_path, result) in results {
560568
sender
561569
.send(Some(HtmlItem {
562-
abs_path,
563-
rel_path,
564-
result,
570+
abs_path: abs_path.to_path_buf(),
571+
rel_path: rel_path.to_path_buf(),
572+
result: result.clone(),
565573
}))
566574
.unwrap();
567575
}
@@ -587,7 +595,7 @@ pub fn output_html(
587595
html::gen_coverage_json(&global.stats, &config, &output);
588596
}
589597

590-
pub fn output_markdown(results: CovResultIter, output_file: Option<&Path>) {
598+
pub fn output_markdown(results: &[(PathBuf, PathBuf, CovResult)], output_file: Option<&Path>) {
591599
#[derive(Tabled)]
592600
struct LineSummary {
593601
file: String,

src/path_rewriting.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn rewrite_paths(
235235
to_keep_dirs: &[impl AsRef<str>],
236236
filter_option: Option<bool>,
237237
file_filter: crate::FileFilter,
238-
) -> CovResultIter {
238+
) -> Vec<(PathBuf, PathBuf, CovResult)> {
239239
let to_ignore_globset = to_globset(to_ignore_dirs);
240240
let to_keep_globset = to_globset(to_keep_dirs);
241241

@@ -341,11 +341,7 @@ pub fn rewrite_paths(
341341
Some((abs_path, rel_path, result))
342342
});
343343

344-
Box::new(
345-
results
346-
.collect::<Vec<(PathBuf, PathBuf, CovResult)>>()
347-
.into_iter(),
348-
)
344+
results.collect()
349345
}
350346

351347
#[cfg(test)]

0 commit comments

Comments
 (0)