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

Reject manifest with duplicate dependencies in different targets #2491

Merged
merged 1 commit into from
Mar 31, 2016

Conversation

JIghtuse
Copy link
Contributor

Closes #2023

@rust-highfive
Copy link

r? @huonw

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

@JIghtuse
Copy link
Contributor Author

This solution looks a bit mouthful and its correctness depends on the order of process_dependencies calls: common deps should be processed before platform-specific ones. But all other fixes I tried were even uglier. Any thoughts how to improve the code?

Ah, also, test will most likely fail (on platforms different from x86_64-unknown-linux-gnu). I don't know how to make it platform-agnostic. Or should we just call it on one platform instead?
Hm, let's just see what CI says. Probably test will pass.

@JIghtuse
Copy link
Contributor Author

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned huonw Mar 17, 2016
@alexcrichton
Copy link
Member

I think that we may want to tweak this a bit actually. So right now Cargo actually supports duplicate names just fine (between dev, build, deps, target-specific deps, etc), so long as the same name resolves to the same crate.

Maybe this check could be placed after all the dependencies have been shoved into a vector? That way it could ensure that all dependencies with the same name come from the same source (regardless of kind)

@JIghtuse
Copy link
Contributor Author

@alexcrichton ok, I'll try to do that.
Btw, looks like test fails due to recent concurrency runs fixes.

@alexcrichton
Copy link
Member

Oops! Should be fixed in #2496

@JIghtuse
Copy link
Contributor Author

Would it be enough to check that all dependencies with the same name() has the same source_id()? If so, new commit follows.

@JIghtuse
Copy link
Contributor Author

The weird and funny thing about #2023 is that it builds first time, and fails second time when we have Cargo.lock. Really confusing behavior.

for dep in deps.iter() {
let name = dep.name();
let sources = names_sources.entry(name).or_insert(HashSet::new());
if sources.insert(dep.source_id()) && sources.len() > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this be if !sources.insert(source_id)? I think insert returns false if it was already present

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is. But this line means "if insertion was successful, and we now has more than 1 source". So we check sources length only if we inserted something. Actually, I thought to split this line on two because we mostly care about number of sources (second part of the condition).

We can miss different sources if we will check it with !sources.insert(source_id). Say, we have source1 and source2 for the same dependency name. On both iterations it will return false and if-branch will not be executed.

So, would it be better to leave it as is or split it on two lines?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right! In that case we don't need the value here to be a HashSet<SourceId>, right? If it's just a SourceId we could just compare against what was already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, indeed. Will fix it asap.

@alexcrichton
Copy link
Member

Looks good to me! Just one minor nit.

@alexcrichton alexcrichton added the relnotes Release-note worthy label Mar 21, 2016
@JIghtuse
Copy link
Contributor Author

@alexcrichton any update on this? =) I've removed unneeded HashSet.

@alexcrichton
Copy link
Member

Oh oops! Thanks for the ping, and feel free to ping the PR whenever you update it, unfortunately github doesn't send out notifications for that...

@bors: r+ 12dbfa3

@bors
Copy link
Contributor

bors commented Mar 31, 2016

⌛ Testing commit 12dbfa3 with merge fae9c53...

bors added a commit that referenced this pull request Mar 31, 2016
Reject manifest with duplicate dependencies in different targets

Closes #2023
@bors
Copy link
Contributor

bors commented Mar 31, 2016

💔 Test failed - cargo-win-gnu-64

@alexcrichton
Copy link
Member

@bors: retry

On Thu, Mar 31, 2016 at 10:00 AM, bors notifications@github.com wrote:

[image: 💔] Test failed - cargo-win-gnu-64
http://buildbot.rust-lang.org/builders/cargo-win-gnu-64/builds/436


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#2491 (comment)

@bors
Copy link
Contributor

bors commented Mar 31, 2016

⚡ Previous build results for cargo-linux-64 are reusable. Rebuilding only cargo-cross-linux, cargo-linux-32, cargo-mac-32, cargo-mac-64, cargo-win-gnu-32, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64...

@bors
Copy link
Contributor

bors commented Mar 31, 2016

@bors bors merged commit 12dbfa3 into rust-lang:master Mar 31, 2016
@wagenet
Copy link

wagenet commented Oct 7, 2016

What if the targets are mutually exclusive? It seems like that should be allowed.

@alexcrichton
Copy link
Member

@wagenet oh this was definitely not intended to error out on legitimate cases, if that's happening please feel free to file an issue!

@wagenet
Copy link

wagenet commented Oct 12, 2016

@alexcrichton see #3195. Thanks!

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

Successfully merging this pull request may close these issues.

6 participants