diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 666de248a0e..324085734f2 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -6,9 +6,7 @@ use util::{CargoResult, human}; pub fn read_manifest(contents: &[u8], source_id: &SourceId) -> CargoResult<(Manifest, Vec)> { - util::toml::to_manifest(contents, source_id).map_err(|err| { - human(err.to_str()) - }) + util::toml::to_manifest(contents, source_id).map_err(human) } pub fn read_package(path: &Path, source_id: &SourceId) diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index fb937f01f7c..09035efce88 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -292,18 +292,18 @@ pub fn internal_error(error: S1, } as Box } -pub fn internal(error: S1) -> Box { +pub fn internal(error: S) -> Box { box ConcreteCargoError { - description: error.as_slice().to_str(), + description: error.to_str(), detail: None, cause: None, is_human: false } as Box } -pub fn human(error: S) -> Box { +pub fn human(error: S) -> Box { box ConcreteCargoError { - description: error.as_slice().to_str(), + description: error.to_str(), detail: None, cause: None, is_human: true diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index cf1c0158ee9..9ae5c023daf 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -23,7 +23,9 @@ pub fn to_manifest(contents: &[u8], manifest\n\n{}", e))) }; - toml_manifest.to_manifest(source_id) + toml_manifest.to_manifest(source_id).map_err(|err| { + human(format!("Cargo.toml is not a valid manifest\n\n{}", err)) + }) } pub fn parse(toml: &str, file: &str) -> CargoResult { @@ -73,7 +75,8 @@ pub struct DetailedTomlDependency { #[deriving(Encodable,Decodable,PartialEq,Clone)] pub struct TomlManifest { - project: Box, + package: Option>, + project: Option>, lib: Option>, bin: Option>, dependencies: Option>, @@ -146,13 +149,16 @@ impl TomlManifest { None => () } + let project = self.project.as_ref().or_else(|| self.package.as_ref()); + let project = try!(project.require(|| human("No `package` or `project` section found."))); + Ok((Manifest::new( - &Summary::new(&self.project.to_package_id(source_id.get_url()), + &Summary::new(&project.to_package_id(source_id.get_url()), deps.as_slice()), targets.as_slice(), &Path::new("target"), sources, - self.project.build.clone()), + project.build.clone()), nested_paths)) } } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 0b8be061784..4e7cb58e8a7 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -48,7 +48,7 @@ test!(cargo_compile_with_invalid_manifest { execs() .with_status(101) .with_stderr("Cargo.toml is not a valid manifest\n\n\ - expected a section for the key `project`\n")) + No `package` or `project` section found.\n")) }) test!(cargo_compile_with_invalid_manifest2 {