diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 2246d2215..e25e108b7 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -18,7 +18,7 @@ pub fn read_package(path: &Path, source_id: &SourceId) let data = try!(file.read_to_end()); let layout = project_layout(&path.dir_path()); - let (manifest, nested) = + let (manifest, nested) = try!(read_manifest(data.as_slice(), layout, source_id)); Ok((Package::new(manifest, path, source_id), nested)) @@ -32,11 +32,14 @@ pub fn read_packages(path: &Path, log!(5, "looking for root package: {}, source_id={}", path.display(), source_id); try!(process_possible_package(path, &mut all_packages, source_id, &mut visited)); - try!(walk(path, true, |dir| { + try!(walk(path, true, |root, dir| { log!(5, "looking for child package: {}", dir.display()); + if root && dir.join("target").is_dir() { return Ok(false); } + if root { return Ok(true) } if dir.filename_str() == Some(".git") { return Ok(false); } if dir.join(".git").exists() { return Ok(false); } - try!(process_possible_package(dir, &mut all_packages, source_id, &mut visited)); + try!(process_possible_package(dir, &mut all_packages, source_id, + &mut visited)); Ok(true) })); @@ -48,15 +51,17 @@ pub fn read_packages(path: &Path, } } -fn walk(path: &Path, is_root: bool, callback: |&Path| -> CargoResult) -> CargoResult<()> { +fn walk(path: &Path, is_root: bool, + callback: |bool, &Path| -> CargoResult) -> CargoResult<()> { if path.is_dir() { - if !is_root { - let continues = try!(callback(path)); - if !continues { log!(5, "Found submodule at {}", path.display()); return Ok(()); } + let continues = try!(callback(is_root, path)); + if !continues { + log!(5, "not processing {}", path.display()); + return Ok(()); } for dir in try!(fs::readdir(path)).iter() { - try!(walk(dir, false, |x| callback(x))) + try!(walk(dir, false, |a, x| callback(a, x))) } } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index c27f0c114..39544b371 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1257,3 +1257,20 @@ test!(deletion_causes_failure { "#); assert_that(p.cargo_process("cargo-build"), execs().with_status(101)); }) + +test!(bad_cargo_toml_in_target_dir { + let p = project("world") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + fn main() {} + "#) + .file("target/Cargo.toml", "bad-toml"); + + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); + assert_that(process(p.bin("foo")), execs().with_status(0)); +})