Skip to content

Commit

Permalink
Auto merge of #3217 - alexcrichton:fix-regression, r=brson
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors authored Oct 26, 2016
2 parents ad47f0a + c8a5dcd commit be010b5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
14 changes: 13 additions & 1 deletion src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions tests/cargotest/support/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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-",
Expand Down
4 changes: 2 additions & 2 deletions tests/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 43 additions & 1 deletion tests/registry.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#[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;
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() {
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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));
}

0 comments on commit be010b5

Please sign in to comment.