]> git.proxmox.com Git - cargo.git/commitdiff
Fix build-std updating the index on every build.
authorEric Huss <eric@huss.org>
Fri, 23 Apr 2021 00:17:15 +0000 (17:17 -0700)
committerEric Huss <eric@huss.org>
Fri, 23 Apr 2021 00:18:26 +0000 (17:18 -0700)
src/cargo/ops/resolve.rs
tests/build-std/main.rs

index e122f4e67786d3b7180e2030d8f84da5b82ed54a..34921b2fb5c1cb7ec5f5183578e2fa2cc6c03eb0 100644 (file)
@@ -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
@@ -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()
@@ -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() {
@@ -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()) {
index d5aa6ca54b8a244da5abab532d3aaa7f746df7fd..c1355b317ce79001ff23f37a9307c5a126c702c8 100644 (file)
@@ -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();