Skip to content

Commit

Permalink
Print original file from which the error is coming, when there is an …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
marco-c committed May 10, 2018
1 parent eb63798 commit 4179f54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum ItemType {
pub struct WorkItem {
pub format: ItemFormat,
pub item: ItemType,
pub name: String,
}

impl WorkItem {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn consumer(working_dir: &PathBuf, result_map: &SyncCovResultMap, queue: &Wo
}

if gcov_type == GcovType::SingleFile {
let new_results = try_parse!(parse_gcov(&gcov_path), gcov_path.display());
let new_results = try_parse!(parse_gcov(&gcov_path), work_item.name);
fs::remove_file(gcov_path).unwrap();
new_results
} else {
Expand All @@ -141,7 +141,7 @@ pub fn consumer(working_dir: &PathBuf, result_map: &SyncCovResultMap, queue: &Wo
let gcov_path = entry.unwrap();
let gcov_path = gcov_path.path();

new_results.append(&mut try_parse!(parse_gcov(&gcov_path), gcov_path.display()));
new_results.append(&mut try_parse!(parse_gcov(&gcov_path), work_item.name));

fs::remove_file(gcov_path).unwrap();
}
Expand All @@ -154,11 +154,11 @@ pub fn consumer(working_dir: &PathBuf, result_map: &SyncCovResultMap, queue: &Wo
ItemType::Path(info_path) => {
let f = File::open(&info_path).expect("Failed to open lcov file");
let file = BufReader::new(&f);
try_parse!(parse_lcov(file, branch_enabled), info_path.display())
try_parse!(parse_lcov(file, branch_enabled), work_item.name)
},
ItemType::Content(info_content) => {
let buffer = BufReader::new(Cursor::new(info_content));
try_parse!(parse_lcov(buffer, branch_enabled), "")
try_parse!(parse_lcov(buffer, branch_enabled), work_item.name)
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn dir_producer(directories: &[&String], queue: &WorkQueue, ignore_orphan_gcno:
queue.push(Some(WorkItem {
format: format,
item: ItemType::Path(abs_path),
name: path.to_str().unwrap().to_string(),
}));
}
}
Expand All @@ -70,8 +71,8 @@ fn extract_file(zip_file: &mut zip::read::ZipFile, path: &PathBuf) {

fn zip_producer(tmp_dir: &Path, zip_files: &[&String], queue: &WorkQueue, ignore_orphan_gcno: bool) -> Option<Vec<u8>> {
let mut gcno_archive: Option<ZipArchive<File>> = None;
let mut gcda_archives: Vec<ZipArchive<File>> = Vec::new();
let mut info_archives: Vec<ZipArchive<File>> = Vec::new();
let mut gcda_archives: Vec<(&String,ZipArchive<File>)> = Vec::new();
let mut info_archives: Vec<(&String,ZipArchive<File>)> = Vec::new();

let mut path_mapping_file = None;

Expand All @@ -80,9 +81,9 @@ fn zip_producer(tmp_dir: &Path, zip_files: &[&String], queue: &WorkQueue, ignore
if zip_file.contains("gcno") {
gcno_archive = Some(archive);
} else if zip_file.contains("gcda") {
gcda_archives.push(archive);
gcda_archives.push((zip_file, archive));
} else if zip_file.contains("info") || zip_file.contains("grcov") || zip_file.contains("jsvm") {
info_archives.push(archive);
info_archives.push((zip_file, archive));
} else {
panic!("Unsupported archive type.");
}
Expand Down Expand Up @@ -122,7 +123,7 @@ fn zip_producer(tmp_dir: &Path, zip_files: &[&String], queue: &WorkQueue, ignore

let gcda_path_in_zip = gcno_path_in_zip.with_extension("gcda");

for (num, gcda_archive) in gcda_archives.iter_mut().enumerate() {
for (num, &mut (gcda_archive_name, ref mut gcda_archive)) in gcda_archives.iter_mut().enumerate() {
let gcno_path = path.with_file_name(format!("{}_{}.gcno", stem, num + 1));

if let Ok(mut gcda_file) = gcda_archive.by_name(&gcda_path_in_zip.to_str().unwrap().replace("\\", "/")) {
Expand All @@ -138,19 +139,21 @@ fn zip_producer(tmp_dir: &Path, zip_files: &[&String], queue: &WorkQueue, ignore
queue.push(Some(WorkItem {
format: ItemFormat::GCNO,
item: ItemType::Path(gcno_path),
name: gcda_archive_name.to_string(),
}));
} else if num == 0 && !ignore_orphan_gcno {
queue.push(Some(WorkItem {
format: ItemFormat::GCNO,
item: ItemType::Path(gcno_path),
name: gcda_archive_name.to_string(),
}));
}
}
}
}
}

for archive in &mut info_archives {
for &mut (archive_name, ref mut archive) in &mut info_archives {
for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();

Expand All @@ -163,6 +166,7 @@ fn zip_producer(tmp_dir: &Path, zip_files: &[&String], queue: &WorkQueue, ignore
queue.push(Some(WorkItem {
format: ItemFormat::INFO,
item: ItemType::Content(buffer),
name: archive_name.to_string(),
}));
}
}
Expand Down

0 comments on commit 4179f54

Please sign in to comment.