зеркало из https://github.com/mozilla/grcov.git
Separate parameters for source directory (containing files) and prefix path to remove
This commit is contained in:
Родитель
8a25917140
Коммит
a24583bd34
37
src/main.rs
37
src/main.rs
|
@ -609,7 +609,7 @@ fn output_lcov(results: &mut HashMap<String,Result>, source_dir: &String) {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_digest(path: &String) -> String {
|
||||
fn get_digest(path: &PathBuf) -> String {
|
||||
match File::open(path) {
|
||||
Ok(mut f) => {
|
||||
let mut buffer = Vec::new();
|
||||
|
@ -626,7 +626,7 @@ fn get_digest(path: &String) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
fn output_coveralls(results: &mut HashMap<String,Result>, source_dir: &String, repo_token: &String, commit_sha: &String) {
|
||||
fn output_coveralls(results: &mut HashMap<String,Result>, source_dir: &String, prefix_dir: &String, repo_token: &String, commit_sha: &String) {
|
||||
let stdout = io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
|
||||
|
@ -657,15 +657,19 @@ fn output_coveralls(results: &mut HashMap<String,Result>, source_dir: &String, r
|
|||
};
|
||||
}
|
||||
|
||||
let digest = get_digest(key);
|
||||
|
||||
let path = PathBuf::from(key);
|
||||
let unprefixed = if path.starts_with(source_dir) {
|
||||
path.strip_prefix(source_dir).unwrap().to_path_buf()
|
||||
let unprefixed = if path.starts_with(prefix_dir) {
|
||||
path.strip_prefix(prefix_dir).unwrap().to_path_buf()
|
||||
} else {
|
||||
path
|
||||
};
|
||||
|
||||
let digest = if unprefixed.is_relative() {
|
||||
get_digest(&PathBuf::from(source_dir).join(&unprefixed))
|
||||
} else {
|
||||
get_digest(&unprefixed)
|
||||
};
|
||||
|
||||
source_files.push(json!({
|
||||
"name": unprefixed,
|
||||
"source_digest": digest,
|
||||
|
@ -681,13 +685,14 @@ fn output_coveralls(results: &mut HashMap<String,Result>, source_dir: &String, r
|
|||
}
|
||||
|
||||
fn print_usage(program: &String) {
|
||||
println!("Usage: {} DIRECTORY[...] [-t OUTPUT_TYPE] [-s SOURCE_ROOT] [--token COVERALLS_REPO_TOKEN] [--commit-sha COVERALLS_COMMIT_SHA] [-z]", program);
|
||||
println!("Usage: {} DIRECTORY[...] [-t OUTPUT_TYPE] [-s SOURCE_ROOT] [-p PREFIX_PATH] [--token COVERALLS_REPO_TOKEN] [--commit-sha COVERALLS_COMMIT_SHA] [-z]", program);
|
||||
println!("You can specify one or more directories, separated by a space.");
|
||||
println!("OUTPUT_TYPE can be one of:");
|
||||
println!(" - (DEFAULT) ade for the ActiveData-ETL specific format;");
|
||||
println!(" - lcov for the lcov INFO format;");
|
||||
println!(" - coveralls for the Coveralls specific format.");
|
||||
println!("SOURCE_ROOT is the root directory of the source files (a prefix to remove from the paths).");
|
||||
println!("SOURCE_ROOT is the root directory of the source files.");
|
||||
println!("PREFIX_PATH is a prefix to remove from the paths (e.g. if grcov is run on a different machine than the one that generated the code coverage information).");
|
||||
println!("COVERALLS_REPO_TOKEN is the repository token from Coveralls, required for the 'coveralls' format.");
|
||||
println!("COVERALLS_COMMIT_SHA is the SHA of the commit used to generate the code coverage data.");
|
||||
println!("Use -z to use ZIP files instead of directories (the first ZIP file must contain the GCNO files, the following ones must contain the GCDA files).")
|
||||
|
@ -738,6 +743,7 @@ fn main() {
|
|||
}
|
||||
let mut output_type: &String = &"ade".to_string();
|
||||
let mut source_dir: &String = &String::new();
|
||||
let mut prefix_dir: &String = &String::new();
|
||||
let mut repo_token: &String = &String::new();
|
||||
let mut commit_sha: &String = &String::new();
|
||||
let mut directories: Vec<&String> = Vec::new();
|
||||
|
@ -762,6 +768,15 @@ fn main() {
|
|||
|
||||
source_dir = &args[i + 1];
|
||||
i += 1;
|
||||
} else if args[i] == "-p" {
|
||||
if args.len() <= i + 1 {
|
||||
println!("[ERROR]: Prefix path not specified.\n");
|
||||
print_usage(&args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
prefix_dir = &args[i + 1];
|
||||
i += 1;
|
||||
} else if args[i] == "--token" {
|
||||
if args.len() <= i + 1 {
|
||||
println!("[ERROR]: Repository token not specified.\n");
|
||||
|
@ -809,6 +824,10 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
if prefix_dir == "" {
|
||||
prefix_dir = source_dir;
|
||||
}
|
||||
|
||||
let tmp_dir = TempDir::new("grcov").expect("Failed to create temporary directory");
|
||||
let tmp_path = tmp_dir.path().to_owned();
|
||||
|
||||
|
@ -873,6 +892,6 @@ fn main() {
|
|||
} else if output_type == "lcov" {
|
||||
output_lcov(results_obj, source_dir);
|
||||
} else if output_type == "coveralls" {
|
||||
output_coveralls(results_obj, source_dir, repo_token, commit_sha);
|
||||
output_coveralls(results_obj, source_dir, prefix_dir, repo_token, commit_sha);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче