Skip to content

Commit

Permalink
Support [package] or [project]
Browse files Browse the repository at this point in the history
The plan is to free up [project] for simpler config plus output flags
like -O that don't make sense in packages.
  • Loading branch information
wycats committed Jun 23, 2014
1 parent 6ac9d77 commit 86b2a2a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/cargo/ops/cargo_read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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>>,
Expand Down Expand Up @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 86b2a2a

Please sign in to comment.