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

Fix build-std updating the index on every build. #9393

Merged
merged 1 commit into from
Apr 23, 2021
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
10 changes: 8 additions & 2 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,13 @@ pub fn resolve_with_previous<'cfg>(

let keep = |p: &PackageId| pre_patch_keep(p) && !avoid_patch_ids.contains(p);

let dev_deps = ws.require_optional_deps() || has_dev_units == HasDevUnits::Yes;
// In the case where a previous instance of resolve is available, we
// want to lock as many packages as possible to the previous version
// without disturbing the graph structure.
if let Some(r) = previous {
trace!("previous: {:?}", r);
register_previous_locks(ws, registry, r, &keep);
register_previous_locks(ws, registry, r, &keep, dev_deps);
}
// Everything in the previous lock file we want to keep is prioritized
// in dependency selection if it comes up, aka we want to have
Expand All @@ -320,7 +321,6 @@ pub fn resolve_with_previous<'cfg>(
registry.add_sources(Some(member.package_id().source_id()))?;
}

let dev_deps = ws.require_optional_deps() || has_dev_units == HasDevUnits::Yes;
let summaries: Vec<(Summary, ResolveOpts)> = ws
.members_with_features(specs, cli_features)?
.into_iter()
Expand Down Expand Up @@ -455,6 +455,7 @@ fn register_previous_locks(
registry: &mut PackageRegistry<'_>,
resolve: &Resolve,
keep: &dyn Fn(&PackageId) -> bool,
dev_deps: bool,
) {
let path_pkg = |id: SourceId| {
if !id.is_path() {
Expand Down Expand Up @@ -564,6 +565,11 @@ fn register_previous_locks(
continue;
}

// If dev-dependencies aren't being resolved, skip them.
if !dep.is_transitive() && !dev_deps {
continue;
}

// If this is a path dependency, then try to push it onto our
// worklist.
if let Some(pkg) = path_pkg(dep.source_id()) {
Expand Down
11 changes: 10 additions & 1 deletion tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ fn basic() {
.build();

p.cargo("check").build_std().target_host().run();
p.cargo("build").build_std().target_host().run();
p.cargo("build")
.build_std()
.target_host()
// Importantly, this should not say [UPDATING]
// There have been multiple bugs where every build triggers and update.
.with_stderr(
"[COMPILING] foo v0.0.1 [..]\n\
[FINISHED] dev [..]",
)
.run();
p.cargo("run").build_std().target_host().run();
p.cargo("test").build_std().target_host().run();

Expand Down