]> git.proxmox.com Git - cargo.git/commitdiff
Support [package] or [project]
authorYehuda Katz <wycats@gmail.com>
Mon, 23 Jun 2014 23:57:27 +0000 (16:57 -0700)
committerYehuda Katz <wycats@gmail.com>
Mon, 23 Jun 2014 23:57:27 +0000 (16:57 -0700)
The plan is to free up [project] for simpler config plus output flags
like -O that don't make sense in packages.

src/cargo/ops/cargo_read_manifest.rs
src/cargo/util/errors.rs
src/cargo/util/toml.rs
tests/test_cargo_compile.rs

index 666de248a0e99e1b253ff2535ec9e3ce797ee3c3..324085734f2c590ec8690eed8e306f34b57b716e 100644 (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)
index fb937f01f7c82bc36c6dfe44238a4056290e8700..09035efce885b3cb2e4f7dad216cd377a085cda7 100644 (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
index cf1c0158ee96227662821404a83850521e49ae91..9ae5c023daf1e680ab2d929b643083127f2dcaaf 100644 (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))
     }
 }
index 0b8be0617843dc27388ab96307c7553c30566ed0..4e7cb58e8a76837166fd3f8a4a7a2e101f746ec9 100644 (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 {