Support [package] or [project]

The plan is to free up [project] for simpler config plus output flags
like -O that don't make sense in packages.
This commit is contained in:
Yehuda Katz 2014-06-23 16:57:27 -07:00
parent 6ac9d779ba
commit 86b2a2a432
4 changed files with 16 additions and 12 deletions

View File

@ -6,9 +6,7 @@ use util::{CargoResult, human};
pub fn read_manifest(contents: &[u8], source_id: &SourceId)
-> CargoResult<(Manifest, Vec<Path>)>
{
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)

View File

@ -292,18 +292,18 @@ pub fn internal_error<S1: Str, S2: Str>(error: S1,
} as Box<CargoError>
}
pub fn internal<S1: Str>(error: S1) -> Box<CargoError> {
pub fn internal<S: Show>(error: S) -> Box<CargoError> {
box ConcreteCargoError {
description: error.as_slice().to_str(),
description: error.to_str(),
detail: None,
cause: None,
is_human: false
} as Box<CargoError>
}
pub fn human<S: Str>(error: S) -> Box<CargoError> {
pub fn human<S: Show>(error: S) -> Box<CargoError> {
box ConcreteCargoError {
description: error.as_slice().to_str(),
description: error.to_str(),
detail: None,
cause: None,
is_human: true

View File

@ -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<toml::Table> {
@ -73,7 +75,8 @@ pub struct DetailedTomlDependency {
#[deriving(Encodable,Decodable,PartialEq,Clone)]
pub struct TomlManifest {
project: Box<TomlProject>,
package: Option<Box<TomlProject>>,
project: Option<Box<TomlProject>>,
lib: Option<Vec<TomlLibTarget>>,
bin: Option<Vec<TomlBinTarget>>,
dependencies: Option<HashMap<String, TomlDependency>>,
@ -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))
}
}

View File

@ -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 {