Skip to content

Commit 108c487

Browse files
committed
Auto merge of #3998 - fantoine:patch-1, r=alexcrichton
Ignore malformed manifests on git dependencies Fix for #3935
2 parents 58c7e7f + c560869 commit 108c487

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/cargo/ops/cargo_read_manifest.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,22 @@ fn read_nested_packages(path: &Path,
121121

122122
let manifest_path = find_project_manifest_exact(path, "Cargo.toml")?;
123123

124-
let (manifest, nested) = read_manifest(&manifest_path, source_id, config)?;
124+
let (manifest, nested) = match read_manifest(&manifest_path, source_id, config) {
125+
Err(_) => {
126+
// Ignore malformed manifests found on git repositories
127+
//
128+
// git source try to find and read all manifests from the repository
129+
// but since it's not possible to exclude folders from this search
130+
// it's safer to ignore malformed manifests to avoid
131+
//
132+
// TODO: Add a way to exclude folders?
133+
info!("skipping malformed package found at `{}`",
134+
path.to_string_lossy());
135+
return Ok(());
136+
}
137+
Ok(tuple) => tuple
138+
};
139+
125140
let manifest = match manifest {
126141
EitherManifest::Real(manifest) => manifest,
127142
EitherManifest::Virtual(..) => return Ok(()),

tests/git.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,61 @@ fn cargo_compile_with_nested_paths() {
290290
execs().with_stdout("hello world\n"));
291291
}
292292

293+
#[test]
294+
fn cargo_compile_with_malformed_nested_paths() {
295+
let git_project = git::new("dep1", |project| {
296+
project
297+
.file("Cargo.toml", r#"
298+
[project]
299+
300+
name = "dep1"
301+
version = "0.5.0"
302+
authors = ["carlhuda@example.com"]
303+
304+
[lib]
305+
306+
name = "dep1"
307+
"#)
308+
.file("src/dep1.rs", r#"
309+
pub fn hello() -> &'static str {
310+
"hello world"
311+
}
312+
"#)
313+
.file("vendor/dep2/Cargo.toml", r#"
314+
!INVALID!
315+
"#)
316+
}).unwrap();
317+
318+
let p = project("parent")
319+
.file("Cargo.toml", &format!(r#"
320+
[project]
321+
322+
name = "parent"
323+
version = "0.5.0"
324+
authors = ["wycats@example.com"]
325+
326+
[dependencies.dep1]
327+
328+
version = "0.5.0"
329+
git = '{}'
330+
331+
[[bin]]
332+
333+
name = "parent"
334+
"#, git_project.url()))
335+
.file("src/parent.rs",
336+
&main_file(r#""{}", dep1::hello()"#, &["dep1"]));
337+
338+
p.cargo_process("build")
339+
.exec_with_output()
340+
.unwrap();
341+
342+
assert_that(&p.bin("parent"), existing_file());
343+
344+
assert_that(process(&p.bin("parent")),
345+
execs().with_stdout("hello world\n"));
346+
}
347+
293348
#[test]
294349
fn cargo_compile_with_meta_package() {
295350
let git_project = git::new("meta-dep", |project| {

0 commit comments

Comments
 (0)