]> git.proxmox.com Git - cargo.git/commitdiff
Ignore summaries in downloaded crates
authorAlex Crichton <alex@alexcrichton.com>
Thu, 20 Oct 2016 22:07:18 +0000 (15:07 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 25 Oct 2016 23:59:50 +0000 (16:59 -0700)
Unfortunately historical Cargo bugs have made it such that the index sometimes
differs from the actual crate we download. Let's respect the index, however,
which should be our source of truth.

Closes #3214

src/cargo/core/manifest.rs
src/cargo/sources/registry/mod.rs
tests/cargotest/support/registry.rs
tests/cfg.rs
tests/registry.rs

index e72674b9602422f2692a7fb86d73a647504290c0..c26876fc2ec9cd2fdcd915b140ad5c732a3bd67e 100644 (file)
@@ -185,7 +185,8 @@ impl Encodable for Target {
 }
 
 impl Manifest {
-    pub fn new(summary: Summary, targets: Vec<Target>,
+    pub fn new(summary: Summary,
+               targets: Vec<Target>,
                exclude: Vec<String>,
                include: Vec<String>,
                links: Option<String>,
index 3a1babafb040de2502269a12055f6aabce4eb296..13517fc08d57a0dfc677cb96435e2ee4315ed28f 100644 (file)
@@ -359,7 +359,19 @@ impl<'cfg> Source for RegistrySource<'cfg> {
         }));
         let mut src = PathSource::new(&path, &self.source_id, self.config);
         try!(src.update());
-        src.download(package)
+        let pkg = try!(src.download(package));
+
+        // Unfortunately the index and the actual Cargo.toml in the index can
+        // differ due to historical Cargo bugs. To paper over these we trash the
+        // *summary* loaded from the Cargo.toml we just downloaded with the one
+        // we loaded from the index.
+        let summaries = try!(self.index.summaries(package.name()));
+        let summary = summaries.iter().map(|s| &s.0).find(|s| {
+            s.package_id() == package
+        }).expect("summary not found");
+        let mut manifest = pkg.manifest().clone();
+        manifest.set_summary(summary.clone());
+        Ok(Package::new(manifest, pkg.manifest_path()))
     }
 
     fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
index 12e857211cc2d1e81ed3f4294a6c4f69a4d09bc0..a57dfa2632754259d02f736dfa2ad1ec7888cd0a 100644 (file)
@@ -141,7 +141,7 @@ impl Package {
             map.insert("name".to_string(), dep.name.to_json());
             map.insert("req".to_string(), dep.vers.to_json());
             map.insert("features".to_string(), dep.features.to_json());
-            map.insert("default_features".to_string(), false.to_json());
+            map.insert("default_features".to_string(), true.to_json());
             map.insert("target".to_string(), dep.target.to_json());
             map.insert("optional".to_string(), false.to_json());
             map.insert("kind".to_string(), dep.kind.to_json());
@@ -211,7 +211,7 @@ impl Package {
         for dep in self.deps.iter() {
             let target = match dep.target {
                 None => String::new(),
-                Some(ref s) => format!("target.{}.", s),
+                Some(ref s) => format!("target.'{}'.", s),
             };
             let kind = match &dep.kind[..] {
                 "build" => "build-",
index 6712af6d8694a92be92d7bd13b374c2882fab788..017f0172377c522c592377c2584e9629beab3464 100644 (file)
@@ -200,8 +200,8 @@ fn works_through_the_registry() {
 
     Package::new("foo", "0.1.0").publish();
     Package::new("bar", "0.1.0")
-            .target_dep("foo", "0.1.0", "'cfg(unix)'")
-            .target_dep("foo", "0.1.0", "'cfg(windows)'")
+            .target_dep("foo", "0.1.0", "cfg(unix)")
+            .target_dep("foo", "0.1.0", "cfg(windows)")
             .publish();
 
     let p = project("a")
index e95dc1e49ea9b122ef138d01b1910da365651691..e3cc4d8acb2998722fe3136bb6c24e60ef534277 100644 (file)
@@ -1,9 +1,11 @@
 #[macro_use]
 extern crate cargotest;
 extern crate hamcrest;
+extern crate url;
 
 use std::fs::{self, File};
 use std::io::prelude::*;
+use std::path::PathBuf;
 
 use cargotest::cargo_process;
 use cargotest::support::git;
@@ -11,6 +13,10 @@ use cargotest::support::paths::{self, CargoPathExt};
 use cargotest::support::registry::{self, Package};
 use cargotest::support::{project, execs};
 use hamcrest::assert_that;
+use url::Url;
+
+fn registry_path() -> PathBuf { paths::root().join("registry") }
+fn registry() -> Url { Url::from_file_path(&*registry_path()).ok().unwrap() }
 
 #[test]
 fn simple() {
@@ -609,7 +615,9 @@ fn bad_license_file() {
         .file("src/main.rs", r#"
             fn main() {}
         "#);
-    assert_that(p.cargo_process("publish").arg("-v"),
+    assert_that(p.cargo_process("publish")
+                 .arg("-v")
+                 .arg("--host").arg(registry().to_string()),
                 execs().with_status(101)
                        .with_stderr_contains("\
 [ERROR] the license file `foo` does not exist"));
@@ -1340,3 +1348,37 @@ this warning.
 [FINISHED] [..]
 "));
 }
+
+#[test]
+fn toml_lies_but_index_is_truth() {
+    Package::new("foo", "0.2.0").publish();
+    Package::new("bar", "0.3.0")
+            .dep("foo", "0.2.0")
+                       .file("Cargo.toml", r#"
+                               [project]
+                name = "bar"
+                version = "0.3.0"
+                authors = []
+
+                [dependencies]
+                foo = "0.1.0"
+                       "#)
+            .file("src/lib.rs", "extern crate foo;")
+                       .publish();
+
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "bar"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            bar = "0.3"
+        "#)
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    assert_that(p.cargo("build").arg("-v"),
+                execs().with_status(0));
+}