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) pub fn read_manifest(contents: &[u8], source_id: &SourceId)
-> CargoResult<(Manifest, Vec<Path>)> -> CargoResult<(Manifest, Vec<Path>)>
{ {
util::toml::to_manifest(contents, source_id).map_err(|err| { util::toml::to_manifest(contents, source_id).map_err(human)
human(err.to_str())
})
} }
pub fn read_package(path: &Path, source_id: &SourceId) 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> } as Box<CargoError>
} }
pub fn internal<S1: Str>(error: S1) -> Box<CargoError> { pub fn internal<S: Show>(error: S) -> Box<CargoError> {
box ConcreteCargoError { box ConcreteCargoError {
description: error.as_slice().to_str(), description: error.to_str(),
detail: None, detail: None,
cause: None, cause: None,
is_human: false is_human: false
} as Box<CargoError> } as Box<CargoError>
} }
pub fn human<S: Str>(error: S) -> Box<CargoError> { pub fn human<S: Show>(error: S) -> Box<CargoError> {
box ConcreteCargoError { box ConcreteCargoError {
description: error.as_slice().to_str(), description: error.to_str(),
detail: None, detail: None,
cause: None, cause: None,
is_human: true is_human: true

View File

@ -23,7 +23,9 @@ pub fn to_manifest(contents: &[u8],
manifest\n\n{}", e))) 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> { pub fn parse(toml: &str, file: &str) -> CargoResult<toml::Table> {
@ -73,7 +75,8 @@ pub struct DetailedTomlDependency {
#[deriving(Encodable,Decodable,PartialEq,Clone)] #[deriving(Encodable,Decodable,PartialEq,Clone)]
pub struct TomlManifest { pub struct TomlManifest {
project: Box<TomlProject>, package: Option<Box<TomlProject>>,
project: Option<Box<TomlProject>>,
lib: Option<Vec<TomlLibTarget>>, lib: Option<Vec<TomlLibTarget>>,
bin: Option<Vec<TomlBinTarget>>, bin: Option<Vec<TomlBinTarget>>,
dependencies: Option<HashMap<String, TomlDependency>>, dependencies: Option<HashMap<String, TomlDependency>>,
@ -146,13 +149,16 @@ impl TomlManifest {
None => () 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( 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()), deps.as_slice()),
targets.as_slice(), targets.as_slice(),
&Path::new("target"), &Path::new("target"),
sources, sources,
self.project.build.clone()), project.build.clone()),
nested_paths)) nested_paths))
} }
} }

View File

@ -48,7 +48,7 @@ test!(cargo_compile_with_invalid_manifest {
execs() execs()
.with_status(101) .with_status(101)
.with_stderr("Cargo.toml is not a valid manifest\n\n\ .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 { test!(cargo_compile_with_invalid_manifest2 {