diff --git a/DESIGN/MANIFEST.md b/DESIGN/MANIFEST.md index 194ccff5a..76377fd52 100644 --- a/DESIGN/MANIFEST.md +++ b/DESIGN/MANIFEST.md @@ -7,7 +7,7 @@ The `Cargo.toml` file contains several top-level sections: * `[project]`: project-specific details, such as name, version and author * `[[lib]]`: information about the main library file, if one exists. By default, the main library file is `src/.rs` -* `[[executable]]`: optionally repeated information about executables +* `[[bin]]`: optionally repeated information about executables that the project is generating. This can both be used for projects that primarily build executables, as well as projects that contain utility executables (such as an HTTP library that comes with a web @@ -53,9 +53,9 @@ Note that we plan to support multiple `Cargo.toml` files in Cargo's git support, so you don't have to have a separate git repository per library. -## The `[[executable]]` Section +## The `[[bin]]` Section -The `executable` section is optionally repeated. It is designed for +The `bin` section is optionally repeated. It is designed for projects whose main raison d'ĂȘtre is a single executable, or for projects that want to provide utility executables alongside a primary library. @@ -71,18 +71,18 @@ standalone library limited to the bare minimum requirements. an executable, `src/bin/.rs` if the project has both a lib and executable, see below) -## Projects Containing Both `lib` and `executable` +## Projects Containing Both `lib` and `bin` Most projects will primarily produce either a library or an executable. Such projects should name the main crate file `.rs` and -omit the optional `path` from the `lib` or `executable` sections. +omit the optional `path` from the `lib` or `bin` sections. Projects that contain both a library and one or more executables should generally use `.rs` for their library, and `bin/*.rs` for the executables. These rules are also the default behavior if `path` is left off of `lib` -or `executable` sections. +or `bin` sections. ## Example Manifests @@ -101,7 +101,7 @@ authors = ["Yehuda Katz "] name = "hammer" ``` -Simple `executable`: +Simple `bin`: ```toml [project] @@ -111,13 +111,13 @@ version = "0.5.0" authors = ["Tom Dale ", "Carl Lerche "] tags = ["performance", "profiling"] -[[executable]] +[[bin]] name = "skylight" path = "bin/skylight.rs" # supports existing project structures ``` -A project with both a lib and an `executable`: +A project with both a `lib` and an `bin`: ```toml [project] @@ -131,11 +131,11 @@ tags = ["performance", "profiling"] name = "skylight" # path defaults to src/skylight.rs -[[executable]] +[[bin]] name = "skylight" # path defaults to src/bin/skylight.rs -[[executable]] +[[bin]] name = "skylight-setup" # path defaults to src/bin/skylight-setup.rs ``` diff --git a/commands/cargo-read-manifest/main.rs b/commands/cargo-read-manifest/main.rs index 4cba6dd37..498a5c76f 100644 --- a/commands/cargo-read-manifest/main.rs +++ b/commands/cargo-read-manifest/main.rs @@ -11,19 +11,37 @@ use serialize::json::Encoder; use toml::from_toml; use semver::Version; -#[deriving(Decodable,Encodable)] -struct Manifest { - project: ~Project +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] +struct SerializedManifest { + project: ~Project, + lib: Option<~[LibTarget]>, + bin: Option<~[ExecTarget]> } -#[deriving(Decodable,Encodable)] +#[deriving(Encodable,Eq,Clone,Ord)] +struct Manifest { + project: ~Project, + lib: ~[LibTarget], + bin: ~[ExecTarget] +} + +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] +struct Target { + name: ~str, + path: Option<~str> +} + +type LibTarget = Target; +type ExecTarget = Target; + +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] struct Project { name: ~str, version: ~str, authors: ~[~str] } -#[deriving(Decodable)] +#[deriving(Decodable,Eq,Clone,Ord)] struct ReadManifestFlags { manifest_path: ~str } @@ -44,8 +62,40 @@ fn main() { let root = toml::parse_from_file(flags.manifest_path).unwrap(); - let manifest = from_toml::(root.clone()); + let toml_manifest = from_toml::(root.clone()); + + let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin); + + let manifest = Manifest{ + project: toml_manifest.project, + lib: lib, + bin: bin + }; + let encoded: ~str = Encoder::str_encode(&manifest); println!("{}", encoded); } + +fn normalize(lib: &Option<~[LibTarget]>, bin: &Option<~[ExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) { + if lib.is_some() && bin.is_some() { + (~[], ~[]) + } else if lib.is_some() { + let mut l = lib.clone().unwrap()[0]; // crashes if lib = [] is provided in the Toml file + if l.path.is_none() { + l.path = Some(format!("{}.rs", l.name)); + } + (~[l.clone()], ~[]) + } else if bin.is_some() { + let b = bin.get_ref().map(|b_ref| { + let mut b = b_ref.clone(); + if b.path.is_none() { + b.path = Some(format!("{}.rs", b.name)); + } + b + }); + (~[], b) + } else { + (~[], ~[]) + } +}