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

Improve message for multiple links to native lib #4515

Merged
merged 2 commits into from
Sep 21, 2017

Conversation

lukaslueg
Copy link
Contributor

Proposal for a fix to #1006, as advertised in my comment; as discussed briefly with alexcrichton on IRC.

In case multiple packages link to the same library, the error message is now

error: More than one package links to native library a, which can only be linked once.

Package a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a) links to native library a.
(Dependency via foo v0.5.0 (file:///home/lukas/dev/issue1006test))

Package b-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a/b) also links to native library a.
(Dependency via a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a) => foo v0.5.0 (file:///home/lukas/dev/issue1006test))

Try updating or pinning your dependencies to ensure that native library a is only linked once.

In case the root-package itself is an offender:

Package foo v0.5.0 (file:///home/lukas/dev/issue1006test) links to native library a.
(This is the root-package)

IMHO the wording is much clearer now (the term "native library" and "package" are repeated on purpose); printing the whole dependency-chain from the offending package up to the root allows the user to at least figure out where the native library actually comes in.

Added a unit-test, which all pass. Please scrutinize this carefully, it's my first PR for cargo.

If a native library is linked multiple times, present the user with a
clear error message, indicating the offending packages and their
dependency-chain.

Fixes rust-lang#1006
@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

let mut pkg_path_desc = String::from("(Dependency via ");
let mut dep_path_iter = dep_path.into_iter().peekable();
while let Some(dep) = dep_path_iter.next() {
write!(pkg_path_desc, "{}", dep).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could have some newlines in it? I could imagine that the dependencies here are sometimes pretty deep, so this may take up a lot of terminal space

while let Some(dep) = dep_path_iter.next() {
write!(pkg_path_desc, "{}", dep).unwrap();
if dep_path_iter.peek().is_some() {
pkg_path_desc.push_str(" => ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this point the other way? The directionality here would entice me to interpret this as "the left depends on the right", but I think it's the other way?

We could also expand this a bit more perhaps like:

Package `foo v0.4.0` also links to native library `{}`.
    ... which is depended on by `bar v0.4.0`
    ... which is depended on by `test v0.3.0`

let describe_path = |pkgid: &PackageId| -> String {
let dep_path = resolve.path_to_top(pkgid);
if dep_path.is_empty() {
String::from("(This is the root-package)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case the root package should likely be pretty recognizable, so perhaps the output could be suppressed here?

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@lukaslueg
Copy link
Contributor Author

lukaslueg commented Sep 21, 2017

While compiling foo, how about

error: Mulliple packages link to native library a, but native libraries can be linked only once.

The root-package links to native library a.

Package b-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a/b)
    ... which is depended on by a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a)
    ... which is depended on by foo v0.5.0 (file:///home/lukas/dev/issue1006test))
also links to native library a.

Try updating or pinning your dependencies to ensure that native library a is only linked once.

Is the last sentence the best piece of advice we can give?

@alexcrichton
Copy link
Member

That looks like a great message to me!

I think it's fine to jettison the last clause about changing deps with this improvement

@lukaslueg
Copy link
Contributor Author

The message is now

error: Multiple packages link to native library a. A native library can be linked only once.

Package a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a)
    ... which is depended on by foo v0.5.0 (file:///home/lukas/dev/issue1006test)
links to native library a.

Package b-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a/b)
    ... which is depended on by a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a)
    ... which is depended on by foo v0.5.0 (file:///home/lukas/dev/issue1006test)
also links to native library a.

or

error: Multiple packages link to native library a. A native library can be linked only once.

The root-package links to native library a.

Package a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a)
    ... which is depended on by foo v0.5.0 (file:///home/lukas/dev/issue1006test)
also links to native library a.

@alexcrichton
Copy link
Member

@bors: r+

Looks great, thanks!

@bors
Copy link
Contributor

bors commented Sep 21, 2017

📌 Commit 45b4a55 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Sep 21, 2017

⌛ Testing commit 45b4a55 with merge a5b734d...

bors added a commit that referenced this pull request Sep 21, 2017
Improve message for multiple links to native lib

Proposal for a fix to #1006, as advertised in my comment; as discussed briefly with alexcrichton on IRC.

In case multiple packages link to the same library, the error message is now

> error: More than one package links to native library `a`, which can only be linked once.
>
> Package a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a) links to native library `a`.
> (Dependency via foo v0.5.0 (file:///home/lukas/dev/issue1006test))
>
> Package b-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a/b) also links to native library `a`.
> (Dependency via a-sys v0.5.0 (file:///home/lukas/dev/issue1006test/a) => foo v0.5.0 (file:///home/lukas/dev/issue1006test))
>
> Try updating or pinning your dependencies to ensure that native library `a` is only linked once.
>

In case the root-package itself is an offender:

> Package foo v0.5.0 (file:///home/lukas/dev/issue1006test) links to native library `a`.
> (This is the root-package)
>

IMHO the wording is much clearer now (the term "native library" and "package" are repeated on purpose); printing the whole dependency-chain from the offending package up to the root allows the user to at least figure out where the native library actually comes in.

Added a unit-test, which all pass. Please scrutinize this carefully, it's my first PR for cargo.
@bors
Copy link
Contributor

bors commented Sep 21, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing a5b734d to master...

@bors bors merged commit 45b4a55 into rust-lang:master Sep 21, 2017
@lukaslueg lukaslueg deleted the issue1006 branch March 27, 2018 06:11
@ehuss ehuss added this to the 1.22.0 milestone Feb 6, 2022
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

Successfully merging this pull request may close these issues.

5 participants