Skip to content

Commit c8a5dcd

Browse files
committed
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
1 parent 62b5992 commit c8a5dcd

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
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/cargotest/support/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Package {
141141
map.insert("name".to_string(), dep.name.to_json());
142142
map.insert("req".to_string(), dep.vers.to_json());
143143
map.insert("features".to_string(), dep.features.to_json());
144-
map.insert("default_features".to_string(), false.to_json());
144+
map.insert("default_features".to_string(), true.to_json());
145145
map.insert("target".to_string(), dep.target.to_json());
146146
map.insert("optional".to_string(), false.to_json());
147147
map.insert("kind".to_string(), dep.kind.to_json());
@@ -211,7 +211,7 @@ impl Package {
211211
for dep in self.deps.iter() {
212212
let target = match dep.target {
213213
None => String::new(),
214-
Some(ref s) => format!("target.{}.", s),
214+
Some(ref s) => format!("target.'{}'.", s),
215215
};
216216
let kind = match &dep.kind[..] {
217217
"build" => "build-",

tests/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ fn works_through_the_registry() {
200200

201201
Package::new("foo", "0.1.0").publish();
202202
Package::new("bar", "0.1.0")
203-
.target_dep("foo", "0.1.0", "'cfg(unix)'")
204-
.target_dep("foo", "0.1.0", "'cfg(windows)'")
203+
.target_dep("foo", "0.1.0", "cfg(unix)")
204+
.target_dep("foo", "0.1.0", "cfg(windows)")
205205
.publish();
206206

207207
let p = project("a")

tests/registry.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
#[macro_use]
22
extern crate cargotest;
33
extern crate hamcrest;
4+
extern crate url;
45

56
use std::fs::{self, File};
67
use std::io::prelude::*;
8+
use std::path::PathBuf;
79

810
use cargotest::cargo_process;
911
use cargotest::support::git;
1012
use cargotest::support::paths::{self, CargoPathExt};
1113
use cargotest::support::registry::{self, Package};
1214
use cargotest::support::{project, execs};
1315
use hamcrest::assert_that;
16+
use url::Url;
17+
18+
fn registry_path() -> PathBuf { paths::root().join("registry") }
19+
fn registry() -> Url { Url::from_file_path(&*registry_path()).ok().unwrap() }
1420

1521
#[test]
1622
fn simple() {
@@ -609,7 +615,9 @@ fn bad_license_file() {
609615
.file("src/main.rs", r#"
610616
fn main() {}
611617
"#);
612-
assert_that(p.cargo_process("publish").arg("-v"),
618+
assert_that(p.cargo_process("publish")
619+
.arg("-v")
620+
.arg("--host").arg(registry().to_string()),
613621
execs().with_status(101)
614622
.with_stderr_contains("\
615623
[ERROR] the license file `foo` does not exist"));
@@ -1340,3 +1348,37 @@ this warning.
13401348
[FINISHED] [..]
13411349
"));
13421350
}
1351+
1352+
#[test]
1353+
fn toml_lies_but_index_is_truth() {
1354+
Package::new("foo", "0.2.0").publish();
1355+
Package::new("bar", "0.3.0")
1356+
.dep("foo", "0.2.0")
1357+
.file("Cargo.toml", r#"
1358+
[project]
1359+
name = "bar"
1360+
version = "0.3.0"
1361+
authors = []
1362+
1363+
[dependencies]
1364+
foo = "0.1.0"
1365+
"#)
1366+
.file("src/lib.rs", "extern crate foo;")
1367+
.publish();
1368+
1369+
let p = project("foo")
1370+
.file("Cargo.toml", r#"
1371+
[project]
1372+
name = "bar"
1373+
version = "0.5.0"
1374+
authors = []
1375+
1376+
[dependencies]
1377+
bar = "0.3"
1378+
"#)
1379+
.file("src/main.rs", "fn main() {}");
1380+
p.build();
1381+
1382+
assert_that(p.cargo("build").arg("-v"),
1383+
execs().with_status(0));
1384+
}

0 commit comments

Comments
 (0)