Skip to content

Commit 51eec2c

Browse files
authored
Auto merge of #3217 - alexcrichton:fix-regression, r=brson
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
2 parents 9a0801d + 41ff55e commit 51eec2c

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/cargo/core/manifest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ impl Encodable for Target {
185185
}
186186

187187
impl Manifest {
188-
pub fn new(summary: Summary, targets: Vec<Target>,
188+
pub fn new(summary: Summary,
189+
targets: Vec<Target>,
189190
exclude: Vec<String>,
190191
include: Vec<String>,
191192
links: Option<String>,

src/cargo/sources/registry/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,19 @@ impl<'cfg> Source for RegistrySource<'cfg> {
359359
}));
360360
let mut src = PathSource::new(&path, &self.source_id, self.config);
361361
try!(src.update());
362-
src.download(package)
362+
let pkg = try!(src.download(package));
363+
364+
// Unfortunately the index and the actual Cargo.toml in the index can
365+
// differ due to historical Cargo bugs. To paper over these we trash the
366+
// *summary* loaded from the Cargo.toml we just downloaded with the one
367+
// we loaded from the index.
368+
let summaries = try!(self.index.summaries(package.name()));
369+
let summary = summaries.iter().map(|s| &s.0).find(|s| {
370+
s.package_id() == package
371+
}).expect("summary not found");
372+
let mut manifest = pkg.manifest().clone();
373+
manifest.set_summary(summary.clone());
374+
Ok(Package::new(manifest, pkg.manifest_path()))
363375
}
364376

365377
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {

tests/registry.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,3 +1340,37 @@ this warning.
13401340
[FINISHED] [..]
13411341
"));
13421342
}
1343+
1344+
#[test]
1345+
fn toml_lies_but_index_is_truth() {
1346+
Package::new("foo", "0.2.0").publish();
1347+
Package::new("bar", "0.3.0")
1348+
.dep("foo", "0.2.0")
1349+
.file("Cargo.toml", r#"
1350+
[project]
1351+
name = "bar"
1352+
version = "0.3.0"
1353+
authors = []
1354+
1355+
[dependencies]
1356+
foo = "0.1.0"
1357+
"#)
1358+
.file("src/lib.rs", "extern crate foo;")
1359+
.publish();
1360+
1361+
let p = project("foo")
1362+
.file("Cargo.toml", r#"
1363+
[project]
1364+
name = "bar"
1365+
version = "0.5.0"
1366+
authors = []
1367+
1368+
[dependencies]
1369+
bar = "0.3"
1370+
"#)
1371+
.file("src/main.rs", "fn main() {}");
1372+
p.build();
1373+
1374+
assert_that(p.cargo("build").arg("-v"),
1375+
execs().with_status(0));
1376+
}

0 commit comments

Comments
 (0)