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

distinguish between normal dependency and dev-dependency #65

Open
Sherlock-Holo opened this issue Mar 23, 2020 · 3 comments
Open

distinguish between normal dependency and dev-dependency #65

Sherlock-Holo opened this issue Mar 23, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@Sherlock-Holo
Copy link

I use libc in unit test and doc example, but not use in codes. When I let libc under [dependencies], udeps doesn't realize it is unnecessary.

Could you make udeps distinguish dependency between normal dependency and dev-dependency so we can write [dependencies] more precisely.

@est31 est31 added the enhancement New feature or request label Mar 23, 2020
@est31
Copy link
Owner

est31 commented Mar 23, 2020

The only info cargo-udeps has access to is "was this library used in the build". And as we are basically doing a dev build of the library, dev-dependencies are included. We'd have to build the library twice, once a dev build to check the dev-dependencies, and once a non-dev build to check any normal dependencies that might only be used as dev-dependencies. It's doable but makes running cargo-udeps a bit slower.

@Sherlock-Holo
Copy link
Author

maybe can add an option like --accurate to make a full scan to check any normal dependencies that might only be used as dev-dependencies? Without this option, only check one times to speed up?

@qryxip
Copy link
Collaborator

qryxip commented Mar 25, 2020

You can find such dependencies with cargo +nightly udeps && cargo +nightly udeps --all-targets because cargo-udeps currently skips dependencies that are not appear in the rustc options.

[dependencies]
if_chain = "1.0.0"

[dev-dependencies]
fn main() {
    todo!();
}

#[cfg(test)]
mod tests {
    use if_chain as _;
}
$ cargo +nightly udeps
    Checking aaaaa v0.0.0 (/home/ryo/src/local/scripts/rs/aaaaa)
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
info: Loading save analysis from "/home/ryo/src/local/scripts/rs/target/debug/deps/save-analysis/aaaaa-38d512ac7a9caa23.json"
unused dependencies:
`aaaaa v0.0.0 (/home/ryo/src/local/scripts/rs/aaaaa)`
└─── dependencies
     └─── "if_chain"
Note: These dependencies might be used by other targets.
      To find dependencies that are not used by any target, enable `--all-targets`.
Note: They might be false-positive.
      For example, `cargo-udeps` cannot detect usage of crates that are only used in doc-tests.
      To ignore some of dependencies, write `package.metadata.cargo-udeps.ignore` in Cargo.toml.
$ echo "$?"
1

But it may be a good idea to add an option like --accurate.

We can add --output pretty or something as well.

`package v0.0.0 (/path/to/package)`
├─── dependencies
│    ├─── `library_a` ✓ Used.
│    │                1/1 lib,
│    │                1/1 lib (profile=test),
│    │                1/1 bin(s),
│    │                1/1 bin(s) (profile=test),
│    │                0/0 example(s),
│    │                5/5 test(s)
│    ├─── `library_b` ✓ Used. (ignored)
│    │                0/0 lib,
│    │                0/0 lib (profile=test),
│    │                0/0 bin(s),
│    │                0/0 bin(s) (profile=test),
│    │                0/0 example(s),
│    │                0/0 test(s)
│    ├─── `library_c` ✗ Unused. (requested with `--accurate`)
│    │                0/0 lib,
│    │                1/1 lib (profile=test),
│    │                0/0 bin(s),
│    │                1/1 bin(s) (profile=test),
│    │                0/0 example(s),
│    │                5/5 test(s)
│    ├─── `library_d` ✗ Unused.
│    │                0/0 lib,
│    │                0/0 lib (profile=test),
│    │                0/0 bin(s),
│    │                0/0 bin(s) (profile=test),
│    │                0/0 example(s),
│    │                0/0 test(s)
└─── build-dependencies
     └─── `library_e` ✓ Used.
                      1/1 build-script

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

No branches or pull requests

3 participants