Skip to content

Commit 86b2a2a

Browse files
committed
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.
1 parent 6ac9d77 commit 86b2a2a

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/cargo/ops/cargo_read_manifest.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use util::{CargoResult, human};
66
pub fn read_manifest(contents: &[u8], source_id: &SourceId)
77
-> CargoResult<(Manifest, Vec<Path>)>
88
{
9-
util::toml::to_manifest(contents, source_id).map_err(|err| {
10-
human(err.to_str())
11-
})
9+
util::toml::to_manifest(contents, source_id).map_err(human)
1210
}
1311

1412
pub fn read_package(path: &Path, source_id: &SourceId)

src/cargo/util/errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,18 @@ pub fn internal_error<S1: Str, S2: Str>(error: S1,
292292
} as Box<CargoError>
293293
}
294294

295-
pub fn internal<S1: Str>(error: S1) -> Box<CargoError> {
295+
pub fn internal<S: Show>(error: S) -> Box<CargoError> {
296296
box ConcreteCargoError {
297-
description: error.as_slice().to_str(),
297+
description: error.to_str(),
298298
detail: None,
299299
cause: None,
300300
is_human: false
301301
} as Box<CargoError>
302302
}
303303

304-
pub fn human<S: Str>(error: S) -> Box<CargoError> {
304+
pub fn human<S: Show>(error: S) -> Box<CargoError> {
305305
box ConcreteCargoError {
306-
description: error.as_slice().to_str(),
306+
description: error.to_str(),
307307
detail: None,
308308
cause: None,
309309
is_human: true

src/cargo/util/toml.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ pub fn to_manifest(contents: &[u8],
2323
manifest\n\n{}", e)))
2424
};
2525

26-
toml_manifest.to_manifest(source_id)
26+
toml_manifest.to_manifest(source_id).map_err(|err| {
27+
human(format!("Cargo.toml is not a valid manifest\n\n{}", err))
28+
})
2729
}
2830

2931
pub fn parse(toml: &str, file: &str) -> CargoResult<toml::Table> {
@@ -73,7 +75,8 @@ pub struct DetailedTomlDependency {
7375

7476
#[deriving(Encodable,Decodable,PartialEq,Clone)]
7577
pub struct TomlManifest {
76-
project: Box<TomlProject>,
78+
package: Option<Box<TomlProject>>,
79+
project: Option<Box<TomlProject>>,
7780
lib: Option<Vec<TomlLibTarget>>,
7881
bin: Option<Vec<TomlBinTarget>>,
7982
dependencies: Option<HashMap<String, TomlDependency>>,
@@ -146,13 +149,16 @@ impl TomlManifest {
146149
None => ()
147150
}
148151

152+
let project = self.project.as_ref().or_else(|| self.package.as_ref());
153+
let project = try!(project.require(|| human("No `package` or `project` section found.")));
154+
149155
Ok((Manifest::new(
150-
&Summary::new(&self.project.to_package_id(source_id.get_url()),
156+
&Summary::new(&project.to_package_id(source_id.get_url()),
151157
deps.as_slice()),
152158
targets.as_slice(),
153159
&Path::new("target"),
154160
sources,
155-
self.project.build.clone()),
161+
project.build.clone()),
156162
nested_paths))
157163
}
158164
}

tests/test_cargo_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test!(cargo_compile_with_invalid_manifest {
4848
execs()
4949
.with_status(101)
5050
.with_stderr("Cargo.toml is not a valid manifest\n\n\
51-
expected a section for the key `project`\n"))
51+
No `package` or `project` section found.\n"))
5252
})
5353

5454
test!(cargo_compile_with_invalid_manifest2 {

0 commit comments

Comments
 (0)