* `[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/<package-name>.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
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.
an executable, `src/bin/<name>.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 `<projectname>.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 `<projectname>.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
name = "hammer"
```
-Simple `executable`:
+Simple `bin`:
```toml
[project]
authors = ["Tom Dale <tom@tomdale.net>", "Carl Lerche <me@carllerche.com>"]
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]
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
```
use toml::from_toml;
use semver::Version;
-#[deriving(Decodable,Encodable)]
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+struct SerializedManifest {
+ project: ~Project,
+ lib: Option<~[LibTarget]>,
+ bin: Option<~[ExecTarget]>
+}
+
+#[deriving(Encodable,Eq,Clone,Ord)]
struct Manifest {
- project: ~Project
+ project: ~Project,
+ lib: ~[LibTarget],
+ bin: ~[ExecTarget]
+}
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+struct Target {
+ name: ~str,
+ path: Option<~str>
}
-#[deriving(Decodable,Encodable)]
+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
}
let root = toml::parse_from_file(flags.manifest_path).unwrap();
- let manifest = from_toml::<Manifest>(root.clone());
+ let toml_manifest = from_toml::<SerializedManifest>(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 {
+ (~[], ~[])
+ }
+}