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

Are /* and ../* ignore options useful? #1

Open
winksaville opened this issue Aug 20, 2022 · 1 comment
Open

Are /* and ../* ignore options useful? #1

winksaville opened this issue Aug 20, 2022 · 1 comment

Comments

@winksaville
Copy link

What do ignore "/" and "../" do?

"--ignore",
"../*",
"--ignore",
"/*",

I believe they do nothing in grcov and are superfluous.

Here's how I arrive at that conclusion

I've added some debug logging to grcov and investigated how globset works and AFAICT --ignore "/*" would would ignore files that have an absolute path that begins with a / and --ignore "../*" would ignore any explicitly relative paths that begin with ../.

After looking at the original code in fn rewrite_paths:

    if let Some(p) = &source_dir {
        assert!(p.is_absolute());
    }


    // Traverse source dir and store all paths, reversed.
    let mut file_to_paths: FxHashMap<String, Vec<PathBuf>> = FxHashMap::default();
    if let Some(ref source_dir) = source_dir {
        for entry in WalkDir::new(&source_dir)
            .into_iter()
            .filter_entry(|e| !is_hidden(e) && !is_symbolic_link(e))
        {
            let entry = entry
                .unwrap_or_else(|_| panic!("Failed to open directory '{}'.", source_dir.display()));


            let full_path = entry.path();
            if !full_path.is_file() {
                continue;
            }


            let path = full_path.strip_prefix(&source_dir).unwrap().to_path_buf();
            if to_ignore_globset.is_match(&path) {
                continue;
            }


            let name = entry.file_name().to_str().unwrap().to_string();
            match file_to_paths.entry(name) {
                hash_map::Entry::Occupied(f) => f.into_mut().push(path),
                hash_map::Entry::Vacant(v) => {
                    v.insert(vec![path]);
                }
            };
        }
    }

I added some debug logging to print the full_path and path:

            println!("checking full_path: {:?}", full_path);
            let path = full_path.strip_prefix(&source_dir).unwrap().to_path_buf();
            println!("checking  stripped: {:?}", path);
            if to_ignore_globset.is_match(&path) {
                println!("ignoring     path: {:?}", path);
                continue;
            }

And here is some output where `--ignore "xtask/*" is processed:

checking full_path: "/home/wink/prgs/rust/myrepos/workspace-template-with-xtask/xtask/Cargo.lock"
checking  stripped: "xtask/Cargo.lock"
ignoring     path: "xtask/Cargo.lock"
checking full_path: "/home/wink/prgs/rust/myrepos/workspace-template-with-xtask/xtask/Cargo.toml"
checking  stripped: "xtask/Cargo.toml"
ignoring     path: "xtask/Cargo.toml"
checking full_path: "/home/wink/prgs/rust/myrepos/workspace-template-with-xtask/xtask/src/main.rs"
checking  stripped: "xtask/src/main.rs"
ignoring     path: "xtask/src/main.rs"

As can be seen, full_path always begins with / and path never begins with / or ../ but instead is always
relative to source_dir. To me, that means that "/" and "../" will never match path and are therefore superfluous.

@winksaville winksaville changed the title Are /* and ../* ignore options functional? Are /* and ../* ignore options useful? Aug 21, 2022
@jondot
Copy link
Owner

jondot commented Nov 18, 2022

@winksaville I'm stunned that I missed this comment!
Sorry for that, looks like you did quite a research
I'd be happy to accept a PR that fixes this
Again -- apologies for missing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants