Respect lock files in crates.io crates
authorAlex Crichton <alex@alexcrichton.com>
Tue, 27 Feb 2018 15:50:05 +0000 (07:50 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 27 Feb 2018 15:50:58 +0000 (07:50 -0800)
Currently Cargo doesn't publish lock files in crates.io crates but we'll
eventually be doing so, so this changes Cargo to recognize `Cargo.lock` when
it's published to crates.io as use it as the basis for resolution during `cargo
install`.

cc #2263

src/cargo/ops/resolve.rs
tests/testsuite/install.rs

index a4c754c3fc1fb3c42d9e5544522d813a077160bb..f6e57621ae51d7ab79112bc6d967a251d28e4816 100644 (file)
@@ -65,7 +65,7 @@ pub fn resolve_ws_precisely<'a>(ws: &Workspace<'a>,
 
         Some(resolve)
     } else {
-        None
+        ops::load_pkg_lockfile(ws)?
     };
 
     let method = if all_features {
index edb1dc627005dae5b5671bc8da8425d678795921..89adafc33f6e06c8bec988b74b022a9b621750bc 100644 (file)
@@ -1011,3 +1011,36 @@ fn custom_target_dir_for_git_source() {
     assert_that(&paths::root().join("target/release"),
                 existing_dir());
 }
+
+#[test]
+fn install_respects_lock_file() {
+    Package::new("bar", "0.1.0").publish();
+    Package::new("bar", "0.1.1")
+        .file("src/lib.rs", "not rust")
+        .publish();
+    Package::new("foo", "0.1.0")
+        .dep("bar", "0.1")
+        .file("src/lib.rs", "")
+        .file("src/main.rs", "
+            extern crate foo;
+            extern crate bar;
+            fn main() {}
+        ")
+        .file("Cargo.lock", r#"
+[[package]]
+name = "bar"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "foo"
+version = "0.1.0"
+dependencies = [
+ "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+"#)
+        .publish();
+
+    assert_that(cargo_process("install").arg("foo"),
+                execs().with_status(0));
+}