-RUSTC_TARGET = target
-RUSTC_FLAGS ?= --out-dir $(RUSTC_TARGET) -L $(RUSTC_TARGET)/libs
+RUSTC ?= rustc
+# RUSTC_FLAGS ?= --out-dir $(RUSTC_TARGET) -L $(RUSTC_TARGET)/libs
TOML_LIB := $(shell rustc --crate-file-name libs/rust-toml/src/toml/lib.rs)
HAMMER_LIB := $(shell rustc --crate-file-name libs/hammer.rs/src/hammer.rs)
-LIBCARGO_LIB := $(shell rustc --crate-file-name libcargo/cargo.rs)
-default: dependencies commands
+# Link flags to pull in dependencies
+DEPS = -L libs/hammer.rs/target -L libs/rust-toml/lib
+SRC = $(wildcard src/*.rs)
+BINS = cargo-read-manifest \
+ cargo-rustc \
+ cargo-verify-project
-dependencies: target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) target/libs/$(LIBCARGO_LIB)
+BIN_TARGETS = $(patsubst %,target/%,$(BINS))
-commands: target/cargo-rustc target/cargo-verify-project target/cargo-read-manifest
+all: $(BIN_TARGETS)
-clean:
- rm -rf target
+# Builds the hammer dependency
+hammer:
+ cd libs/hammer.rs && make
-target/cargo-rustc: target dependencies target/libs/$(TOML_LIB) commands/cargo-rustc/main.rs
- rustc commands/cargo-rustc/main.rs $(RUSTC_FLAGS)
+toml:
+ cd libs/rust-toml && make
-target/cargo-verify-project: target dependencies target/libs/$(TOML_LIB) commands/cargo-verify-project/main.rs
- rustc commands/cargo-verify-project/main.rs $(RUSTC_FLAGS)
+# === Cargo
-target/cargo-read-manifest: target dependencies target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) commands/cargo-read-manifest/main.rs
- rustc commands/cargo-read-manifest/main.rs $(RUSTC_FLAGS)
+target:
+ mkdir -p target
-target/libs/$(TOML_LIB): target libs/rust-toml/src/toml/lib.rs
- cd libs/rust-toml && make
- cp libs/rust-toml/lib/*.rlib target/libs
+libcargo: target $(SRC)
+ $(RUSTC) --out-dir target src/cargo.rs
-target/libs/$(HAMMER_LIB): target libs/hammer.rs/src/hammer.rs
- cd libs/hammer.rs && make
- cp libs/hammer.rs/target/*.rlib target/libs
+# === Commands
-target/libs/$(LIBCARGO_LIB): target libcargo/cargo.rs
- cd libcargo && make
- cp libcargo/target/*.rlib target/libs/
+$(BIN_TARGETS): target/%: src/bin/%.rs hammer toml libcargo
+ $(RUSTC) $(DEPS) -Ltarget --out-dir target $<
-target:
- mkdir -p $(RUSTC_TARGET)/libs
+clean:
+ rm -rf target
+
+distclean: clean
+ cd libs/hamcrest-rust && make clean
+ cd libs/hammer.rs && make clean
+ cd libs/rust-toml && make clean
-.PHONY: default clean dependencies commands
+.PHONY: all clean distclean test hammer libcargo
+++ /dev/null
-#[crate_id="cargo-read-manifest"];
-
-extern crate cargo;
-extern crate hammer;
-extern crate serialize;
-extern crate toml;
-extern crate semver;
-
-use hammer::{FlagDecoder,FlagConfig,FlagConfiguration};
-use serialize::{Decoder,Decodable};
-use serialize::json::Encoder;
-use toml::from_toml;
-use semver::Version;
-use cargo::{Manifest,LibTarget,ExecTarget,Project};
-use std::path::Path;
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-struct SerializedManifest {
- project: ~Project,
- lib: Option<~[SerializedLibTarget]>,
- bin: Option<~[SerializedExecTarget]>
-}
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct SerializedTarget {
- name: ~str,
- path: Option<~str>
-}
-
-pub type SerializedLibTarget = SerializedTarget;
-pub type SerializedExecTarget = SerializedTarget;
-
-
-#[deriving(Decodable,Eq,Clone,Ord)]
-struct ReadManifestFlags {
- manifest_path: ~str
-}
-
-impl FlagConfig for ReadManifestFlags {
- 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);
-
- if decoder.error.is_some() {
- fail!("Error: {}", decoder.error.unwrap());
- }
-
- let root = toml::parse_from_file(flags.manifest_path).unwrap();
-
- let toml_manifest = from_toml::<SerializedManifest>(root.clone());
-
- 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 encoded: ~str = Encoder::str_encode(&manifest);
-
- 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));
- }
-
- let b = bin.get_ref().map(|b_ref| {
- let mut 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 mut 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 {
- (~[], ~[])
- }
-}
+++ /dev/null
-#[crate_id="cargo-rustc"];
-
-extern crate toml;
-extern crate serialize;
-extern crate cargo;
-
-use std::os::args;
-use std::io;
-use std::io::process::Process;
-use serialize::json;
-use serialize::{Decoder,Decodable};
-use std::path::Path;
-use cargo::{Manifest,LibTarget,ExecTarget,Project};
-
-/**
- cargo-rustc -- ...args
-
- Delegate ...args to actual rustc command
-*/
-
-fn main() {
- 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 mut arguments = args();
- //arguments.shift();
-
- //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 args = ~[
- join(&root, out_dir),
- ~"--out-dir", target,
- ~"--crate-type", ~"lib"
- ];
-
- io::fs::mkdir_recursive(&root.join("target"), io::UserRWX);
-
- println!("Executing {}", args);
-
- 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")
- }
-}
-
-fn join(path: &Path, part: ~str) -> ~str {
- path.join(part).as_str().unwrap().to_owned()
-}
+++ /dev/null
-#[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);
-}
+++ /dev/null
-LIBCARGO_LIB := $(shell rustc --crate-file-name cargo.rs)
-
-default: target/$(LIBCARGO_LIB)
-
-target:
- mkdir -p target
-
-clean:
- rm -rf target
-
-target/$(LIBCARGO_LIB): target cargo.rs
- rustc cargo.rs --out-dir target
-
-.PHONY: default clean
+++ /dev/null
-#[crate_type="rlib"];
-
-extern crate serialize;
-use serialize::{Decoder};
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct Manifest {
- project: ~Project,
- root: ~str,
- lib: ~[LibTarget],
- bin: ~[ExecTarget]
-}
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct ExecTarget {
- name: ~str,
- path: ~str
-}
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct LibTarget {
- name: ~str,
- path: ~str
-}
-
-//pub type LibTarget = Target;
-//pub type ExecTarget = Target;
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct Project {
- name: ~str,
- version: ~str,
- authors: ~[~str]
-}
-
--- /dev/null
+#[crate_id="cargo-read-manifest"];
+
+extern crate cargo;
+extern crate hammer;
+extern crate serialize;
+extern crate toml;
+extern crate semver;
+
+use hammer::{FlagDecoder,FlagConfig,FlagConfiguration};
+use serialize::{Decoder,Decodable};
+use serialize::json::Encoder;
+use toml::from_toml;
+use semver::Version;
+use cargo::{Manifest,LibTarget,ExecTarget,Project};
+use std::path::Path;
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+struct SerializedManifest {
+ project: ~Project,
+ lib: Option<~[SerializedLibTarget]>,
+ bin: Option<~[SerializedExecTarget]>
+}
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct SerializedTarget {
+ name: ~str,
+ path: Option<~str>
+}
+
+pub type SerializedLibTarget = SerializedTarget;
+pub type SerializedExecTarget = SerializedTarget;
+
+
+#[deriving(Decodable,Eq,Clone,Ord)]
+struct ReadManifestFlags {
+ manifest_path: ~str
+}
+
+impl FlagConfig for ReadManifestFlags {
+ 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);
+
+ if decoder.error.is_some() {
+ fail!("Error: {}", decoder.error.unwrap());
+ }
+
+ let root = toml::parse_from_file(flags.manifest_path).unwrap();
+
+ let toml_manifest = from_toml::<SerializedManifest>(root.clone());
+
+ 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 encoded: ~str = Encoder::str_encode(&manifest);
+
+ 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));
+ }
+
+ let b = bin.get_ref().map(|b_ref| {
+ let mut 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 mut 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 {
+ (~[], ~[])
+ }
+}
--- /dev/null
+#[crate_id="cargo-rustc"];
+
+extern crate toml;
+extern crate serialize;
+extern crate cargo;
+
+use std::os::args;
+use std::io;
+use std::io::process::Process;
+use serialize::json;
+use serialize::{Decoder,Decodable};
+use std::path::Path;
+use cargo::{Manifest,LibTarget,ExecTarget,Project};
+
+/**
+ cargo-rustc -- ...args
+
+ Delegate ...args to actual rustc command
+*/
+
+fn main() {
+ 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 mut arguments = args();
+ //arguments.shift();
+
+ //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 args = ~[
+ join(&root, out_dir),
+ ~"--out-dir", target,
+ ~"--crate-type", ~"lib"
+ ];
+
+ io::fs::mkdir_recursive(&root.join("target"), io::UserRWX);
+
+ println!("Executing {}", args);
+
+ 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")
+ }
+}
+
+fn join(path: &Path, part: ~str) -> ~str {
+ path.join(part).as_str().unwrap().to_owned()
+}
--- /dev/null
+#[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);
+}
--- /dev/null
+#[crate_type="rlib"];
+
+extern crate serialize;
+use serialize::{Decoder};
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct Manifest {
+ project: ~Project,
+ root: ~str,
+ lib: ~[LibTarget],
+ bin: ~[ExecTarget]
+}
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct ExecTarget {
+ name: ~str,
+ path: ~str
+}
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct LibTarget {
+ name: ~str,
+ path: ~str
+}
+
+//pub type LibTarget = Target;
+//pub type ExecTarget = Target;
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct Project {
+ name: ~str,
+ version: ~str,
+ authors: ~[~str]
+}