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)
} 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
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> {
#[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>>,
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))
}
}