From c8a5dcd28f3ca221b4a2e0be2e153eb8089dd419 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 20 Oct 2016 15:07:18 -0700 Subject: [PATCH] Ignore summaries in downloaded crates 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 | 3 +- src/cargo/sources/registry/mod.rs | 14 ++++++++- tests/cargotest/support/registry.rs | 4 +-- tests/cfg.rs | 4 +-- tests/registry.rs | 44 ++++++++++++++++++++++++++++- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index e72674b96..c26876fc2 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -185,7 +185,8 @@ impl Encodable for Target { } impl Manifest { - pub fn new(summary: Summary, targets: Vec, + pub fn new(summary: Summary, + targets: Vec, exclude: Vec, include: Vec, links: Option, diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 3a1babafb..13517fc08 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -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 { diff --git a/tests/cargotest/support/registry.rs b/tests/cargotest/support/registry.rs index 12e857211..a57dfa263 100644 --- a/tests/cargotest/support/registry.rs +++ b/tests/cargotest/support/registry.rs @@ -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-", diff --git a/tests/cfg.rs b/tests/cfg.rs index 6712af6d8..017f01723 100644 --- a/tests/cfg.rs +++ b/tests/cfg.rs @@ -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") diff --git a/tests/registry.rs b/tests/registry.rs index e95dc1e49..e3cc4d8ac 100644 --- a/tests/registry.rs +++ b/tests/registry.rs @@ -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)); +} -- 2.39.5