Add sketch of cargo-verify-project
authorCarlhuda <wycats+carl@gmail.com>
Wed, 5 Mar 2014 01:48:31 +0000 (17:48 -0800)
committerCarlhuda <wycats+carl@gmail.com>
Wed, 5 Mar 2014 01:48:31 +0000 (17:48 -0800)
Makefile
commands/cargo-rustc/main.rs
commands/cargo-verify-project/main.rs [new file with mode: 0644]

index 04fcba93d46468ce9abb82c3e56bcdf45916cf66..b20c65bed8d4dad6996ba3cb6fc2b162e28eeef0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,24 @@
 RUSTC_TARGET = target
-RUSTC_FLAGS ?= --out-dir $(RUSTC_TARGET)
+RUSTC_FLAGS ?= --out-dir $(RUSTC_TARGET) -L $(RUSTC_TARGET)/libs
 
-default: target/cargo-rustc
+TOML_LIB := $(shell rustc --crate-file-name libs/rust-toml/src/toml/lib.rs)
+
+default: target/cargo-rustc target/cargo-verify-project
 
 clean:
        rm -rf target
 
-target/cargo-rustc: target commands/cargo-rustc/main.rs
+target/cargo-rustc: target target/libs/$(TOML_LIB) commands/cargo-rustc/main.rs
        rustc commands/cargo-rustc/main.rs $(RUSTC_FLAGS)
 
+target/cargo-verify-project: target target/libs/$(TOML_LIB) commands/cargo-verify-project/main.rs
+       rustc commands/cargo-verify-project/main.rs $(RUSTC_FLAGS)
+
+target/libs/$(TOML_LIB): libs/rust-toml/src/toml/lib.rs
+       cd libs/rust-toml && make
+       cp libs/rust-toml/lib/*.rlib target/libs
+
 target:
-       mkdir -p $(RUSTC_TARGET)
+       mkdir -p $(RUSTC_TARGET)/libs
 
 .PHONY: default clean
index 15745a5d625fa5a3e85c3942ccb4f6933980587d..390a57138a70e1b7d99170c71dd370adc96c0e5f 100644 (file)
@@ -1,6 +1,6 @@
 #[crate_id="cargo-rustc"];
 
-extern crate rustc;
+extern crate toml;
 
 use std::os::args;
 use std::io::process::Process;
@@ -15,8 +15,6 @@ fn main() {
   let mut arguments = args();
   arguments.shift();
 
-  println!("host: {}", driver::host_triple());
-
   if arguments[0] != ~"--" {
     fail!("LOL");
   } else {
diff --git a/commands/cargo-verify-project/main.rs b/commands/cargo-verify-project/main.rs
new file mode 100644 (file)
index 0000000..afc6d00
--- /dev/null
@@ -0,0 +1,56 @@
+#[crate_id="cargo-verify-project"];
+
+extern crate toml;
+extern crate getopts;
+
+use std::os::{args,set_exit_status};
+use std::io::process::Process;
+use getopts::{reqopt,getopts,OptGroup};
+
+/**
+  cargo-verify-project --manifest=LOCATION
+*/
+
+fn main() {
+  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(err) => {
+      fail("missing-argument", "manifest");
+      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;
+  }
+
+  let root = match toml::parse_from_file(file.as_str().unwrap()) {
+    Err(e) => {
+      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);
+}