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

Less aggressively poison sources on builds #5288

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,30 @@ fn register_previous_locks<'a>(
}

// If we match *anything* in the dependency graph then we consider
// ourselves A-OK and assume that we'll resolve to that. If,
// however, nothing matches, then we poison the source of this
// dependencies and the previous lock file.
// ourselves A-OK and assume that we'll resolve to that.
if resolve.iter().any(|id| dep.matches_ignoring_source(id)) {
continue;
}

// If this dependency didn't match anything special then we may want
// to poison the source as it may have been added. If this path
// dependencies is *not* a workspace member, however, and it's an
// optional/non-transitive dependency then it won't be necessarily
// be in our lock file. If this shows up then we avoid poisoning
// this source as otherwise we'd repeatedly update the registry.
//
// TODO: this breaks adding an optional dependency in a
// non-workspace member and then simultaneously editing the
// dependency on that crate to enable the feature. For now
// this bug is better than the always updating registry
// though...
if !ws.members().any(|pkg| pkg.package_id() == member.package_id()) &&
(dep.is_optional() || !dep.is_transitive()) {
continue
}

// Ok if nothing matches, then we poison the source of this
// dependencies and the previous lock file.
for id in resolve.iter().filter(|id| id.source_id() == source) {
add_deps(resolve, id, &mut avoid_locking);
}
Expand Down
58 changes: 58 additions & 0 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::io::prelude::*;
use cargotest::sleep_ms;
use cargotest::support::{execs, project, path2url};
use cargotest::support::paths::CargoPathExt;
use cargotest::support::registry::Package;
use hamcrest::{assert_that, existing_file};

#[test]
Expand Down Expand Up @@ -1007,3 +1008,60 @@ fn no_rebuild_when_rename_dir() {
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]"),
);
}

#[test]
fn unused_optional_dep() {
Package::new("registry1", "0.1.0").publish();
Package::new("registry2", "0.1.0").publish();
Package::new("registry3", "0.1.0").publish();

let p = project("p")
.file(
"Cargo.toml",
r#"
[package]
name = "p"
authors = []
version = "0.1.0"

[dependencies]
foo = { path = "foo" }
bar = { path = "bar" }
registry1 = "*"
"#,
)
.file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.1"
authors = []

[dev-dependencies]
registry2 = "*"
Copy link
Member

Choose a reason for hiding this comment

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

So this checks only non-transitive case? Let’s add a separate test for optional dep as well?

"#,
)
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.1"
authors = []

[dependencies]
registry3 = { version = "*", optional = true }
"#,
)
.file("bar/src/lib.rs", "")
.build();

assert_that(p.cargo("build"), execs().with_status(0));
assert_that(
p.cargo("build"),
execs().with_status(0).with_stderr("[FINISHED] [..]"),
);
}