#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
struct SerializedManifest {
- project: ~Project,
- lib: Option<~[SerializedLibTarget]>,
- bin: Option<~[SerializedExecTarget]>
+ project: ~Project,
+ lib: Option<~[SerializedLibTarget]>,
+ bin: Option<~[SerializedExecTarget]>
}
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
pub struct SerializedTarget {
- name: ~str,
- path: Option<~str>
+ name: ~str,
+ path: Option<~str>
}
pub type SerializedLibTarget = SerializedTarget;
#[deriving(Decodable,Eq,Clone,Ord)]
struct ReadManifestFlags {
- manifest_path: ~str
+ manifest_path: ~str
}
impl FlagConfig for ReadManifestFlags {
- fn config(_: Option<ReadManifestFlags>, c: FlagConfiguration) -> FlagConfiguration {
- c
- }
+ fn config(_: Option<ReadManifestFlags>, c: FlagConfiguration) -> FlagConfiguration {
+ c
+ }
}
fn main() {
- let mut decoder = FlagDecoder::new::<ReadManifestFlags>(std::os::args().tail());
- let flags: ReadManifestFlags = Decodable::decode(&mut decoder);
+ let mut decoder = FlagDecoder::new::<ReadManifestFlags>(std::os::args().tail());
+ let flags: ReadManifestFlags = Decodable::decode(&mut decoder);
- if decoder.error.is_some() {
- fail!("Error: {}", decoder.error.unwrap());
- }
+ if decoder.error.is_some() {
+ fail!("Error: {}", decoder.error.unwrap());
+ }
- let root = toml::parse_from_file(flags.manifest_path).unwrap();
+ let root = toml::parse_from_file(flags.manifest_path).unwrap();
- let toml_manifest = from_toml::<SerializedManifest>(root.clone());
+ let toml_manifest = from_toml::<SerializedManifest>(root.clone());
- let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin);
+ let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin);
- let manifest = Manifest{
- root: Path::new(flags.manifest_path).dirname_str().unwrap().to_owned(),
- project: toml_manifest.project,
- lib: lib,
- bin: bin
- };
+ let manifest = Manifest{
+ root: Path::new(flags.manifest_path).dirname_str().unwrap().to_owned(),
+ project: toml_manifest.project,
+ lib: lib,
+ bin: bin
+ };
- let encoded: ~str = Encoder::str_encode(&manifest);
+ let encoded: ~str = Encoder::str_encode(&manifest);
- println!("{}", encoded);
+ println!("{}", encoded);
}
fn normalize(lib: &Option<~[SerializedLibTarget]>, bin: &Option<~[SerializedExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) {
- if lib.is_some() && bin.is_some() {
- let l = lib.clone().unwrap()[0];
- let mut path = l.path.clone();
-
- if path.is_none() {
- path = Some(format!("src/{}.rs", l.name));
+ if lib.is_some() && bin.is_some() {
+ let l = lib.clone().unwrap()[0];
+ let mut path = l.path.clone();
+
+ if path.is_none() {
+ path = Some(format!("src/{}.rs", l.name));
+ }
+
+ let b = bin.get_ref().map(|b_ref| {
+ let b = b_ref.clone();
+ let mut path = b.path.clone();
+ if path.is_none() {
+ path = Some(format!("src/bin/{}.rs", b.name.clone()));
+ }
+ ExecTarget{ path: path.unwrap(), name: b.name }
+ });
+ (~[LibTarget{ path: path.unwrap(), name: l.name }], b)
+ } else if lib.is_some() {
+ let l = lib.clone().unwrap()[0];
+ let mut path = l.path.clone();
+
+ if path.is_none() {
+ path = Some(format!("src/{}.rs", l.name));
+ }
+
+ (~[LibTarget{ path: path.unwrap(), name: l.name }], ~[])
+ } else if bin.is_some() {
+ let b = bin.get_ref().map(|b_ref| {
+ let b = b_ref.clone();
+ let mut path = b.path.clone();
+ if path.is_none() {
+ path = Some(format!("src/bin/{}.rs", b.name.clone()));
+ }
+ ExecTarget{ path: path.unwrap(), name: b.name }
+ });
+ (~[], b)
+ } else {
+ (~[], ~[])
}
-
- let b = bin.get_ref().map(|b_ref| {
- let b = b_ref.clone();
- let mut path = b.path.clone();
- if path.is_none() {
- path = Some(format!("src/bin/{}.rs", b.name.clone()));
- }
- ExecTarget{ path: path.unwrap(), name: b.name }
- });
- (~[LibTarget{ path: path.unwrap(), name: l.name }], b)
- } else if lib.is_some() {
- let l = lib.clone().unwrap()[0];
- let mut path = l.path.clone();
-
- if path.is_none() {
- path = Some(format!("src/{}.rs", l.name));
- }
-
- (~[LibTarget{ path: path.unwrap(), name: l.name }], ~[])
- } else if bin.is_some() {
- let b = bin.get_ref().map(|b_ref| {
- let b = b_ref.clone();
- let mut path = b.path.clone();
- if path.is_none() {
- path = Some(format!("src/bin/{}.rs", b.name.clone()));
- }
- ExecTarget{ path: path.unwrap(), name: b.name }
- });
- (~[], b)
- } else {
- (~[], ~[])
- }
}
use cargo::Manifest;
/**
- cargo-rustc -- ...args
+ cargo-rustc -- ...args
- Delegate ...args to actual rustc command
+ Delegate ...args to actual rustc command
*/
fn main() {
- let mut reader = io::stdin();
- let input = reader.read_to_str().unwrap();
+ let mut reader = io::stdin();
+ let input = reader.read_to_str().unwrap();
- let json = json::from_str(input).unwrap();
- let mut decoder = json::Decoder::new(json);
- let manifest: Manifest = Decodable::decode(&mut decoder);
+ let json = json::from_str(input).unwrap();
+ let mut decoder = json::Decoder::new(json);
+ let manifest: Manifest = Decodable::decode(&mut decoder);
- //let mut arguments = args();
- //arguments.shift();
-
- //if arguments[0] != ~"--" {
- //fail!("LOL");
- //} else {
+ //let mut arguments = args();
//arguments.shift();
- //}
- let Manifest{ root, lib, .. } = manifest;
+ //if arguments[0] != ~"--" {
+ //fail!("LOL");
+ //} else {
+ //arguments.shift();
+ //}
+
+ let Manifest{ root, lib, .. } = manifest;
- let root = Path::new(root);
- let out_dir = lib[0].path;
- let target = join(&root, ~"target");
+ let root = Path::new(root);
+ let out_dir = lib[0].path;
+ let target = join(&root, ~"target");
- let args = ~[
- join(&root, out_dir),
- ~"--out-dir", target,
- ~"--crate-type", ~"lib"
- ];
+ let args = ~[
+ join(&root, out_dir),
+ ~"--out-dir", target,
+ ~"--crate-type", ~"lib"
+ ];
- match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) {
- Err(_) => fail!("Couldn't mkdir -p"),
- Ok(val) => val
- }
+ match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) {
+ Err(_) => fail!("Couldn't mkdir -p"),
+ Ok(val) => val
+ }
- println!("Executing {}", args);
+ println!("Executing {}", args);
- let mut p = Process::new("rustc", args).unwrap();
- let o = p.wait_with_output();
+ let mut p = Process::new("rustc", args).unwrap();
+ let o = p.wait_with_output();
- if o.status == std::io::process::ExitStatus(0) {
- println!("output: {:s}", std::str::from_utf8(o.output).unwrap());
- } else {
- fail!("Failed to execute")
- }
+ if o.status == std::io::process::ExitStatus(0) {
+ println!("output: {:s}", std::str::from_utf8(o.output).unwrap());
+ } else {
+ fail!("Failed to execute")
+ }
}
fn join(path: &Path, part: ~str) -> ~str {
- path.join(part).as_str().unwrap().to_owned()
+ path.join(part).as_str().unwrap().to_owned()
}
use getopts::{reqopt,getopts};
/**
- cargo-verify-project --manifest=LOCATION
+ cargo-verify-project --manifest=LOCATION
*/
fn main() {
- let arguments = args();
+ let arguments = args();
+
+ let opts = ~[
+ reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
+ ];
+
+ let matches = match getopts(arguments.tail(), opts) {
+ Ok(m) => m,
+ Err(_) => {
+ fail("missing-argument", "manifest");
+ return;
+ }
+ };
+
+ if !matches.opt_present("m") {
+ fail("missing-argument", "manifest");
+ return;
+ }
- let opts = ~[
- reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
- ];
+ let manifest = matches.opt_str("m").unwrap();
+ let file = Path::new(manifest);
- let matches = match getopts(arguments.tail(), opts) {
- Ok(m) => m,
- Err(_) => {
- fail("missing-argument", "manifest");
- return;
+ if !file.exists() {
+ fail("invalid", "not-found");
+ return;
}
- };
-
- if !matches.opt_present("m") {
- fail("missing-argument", "manifest");
- return;
- }
-
- let manifest = matches.opt_str("m").unwrap();
- let file = Path::new(manifest);
-
- if !file.exists() {
- fail("invalid", "not-found");
- return;
- }
-
- match toml::parse_from_file(file.as_str().unwrap()) {
- Err(_) => {
- fail("invalid", "invalid-format");
- return;
- },
- Ok(r) => r
- };
-
- println!("{}", "{ \"success\": \"true\" }");
+
+ match toml::parse_from_file(file.as_str().unwrap()) {
+ Err(_) => {
+ fail("invalid", "invalid-format");
+ return;
+ },
+ Ok(r) => r
+ };
+
+ println!("{}", "{ \"success\": \"true\" }");
}
fn fail(reason: &str, value: &str) {
- println!(r#"\{ "{:s}", "{:s}" \}"#, reason, value);
- set_exit_status(1);
+ println!(r#"\{ "{:s}", "{:s}" \}"#, reason, value);
+ set_exit_status(1);
}
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
pub struct Manifest {
- project: ~Project,
- root: ~str,
- lib: ~[LibTarget],
- bin: ~[ExecTarget]
+ project: ~Project,
+ root: ~str,
+ lib: ~[LibTarget],
+ bin: ~[ExecTarget]
}
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
pub struct ExecTarget {
- name: ~str,
- path: ~str
+ name: ~str,
+ path: ~str
}
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
pub struct LibTarget {
- name: ~str,
- path: ~str
+ name: ~str,
+ path: ~str
}
//pub type LibTarget = Target;
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
pub struct Project {
- name: ~str,
- version: ~str,
- authors: ~[~str]
+ name: ~str,
+ version: ~str,
+ authors: ~[~str]
}