From 03943b7dbb3c160a9bf1bed3bcf32e909abd25aa Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 4 Mar 2014 17:48:31 -0800 Subject: [PATCH] Add sketch of cargo-verify-project --- Makefile | 17 ++++++-- commands/cargo-rustc/main.rs | 4 +- commands/cargo-verify-project/main.rs | 56 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 commands/cargo-verify-project/main.rs diff --git a/Makefile b/Makefile index 04fcba93d..b20c65bed 100644 --- 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 diff --git a/commands/cargo-rustc/main.rs b/commands/cargo-rustc/main.rs index 15745a5d6..390a57138 100644 --- a/commands/cargo-rustc/main.rs +++ b/commands/cargo-rustc/main.rs @@ -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 index 000000000..afc6d00ee --- /dev/null +++ b/commands/cargo-verify-project/main.rs @@ -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); +}