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/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
cd libs/rust-toml && make
cp libs/rust-toml/lib/*.rlib target/libs
-target/libs/$(HAMMER_LIB): target libs/hammer.rs/src/lib.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
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<~[LibTarget]>,
- bin: Option<~[ExecTarget]>
+ 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 {
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
println!("{}", encoded);
}
-fn normalize(lib: &Option<~[LibTarget]>, bin: &Option<~[ExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) {
+fn normalize(lib: &Option<~[SerializedLibTarget]>, bin: &Option<~[SerializedExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) {
if lib.is_some() && bin.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!("src/{}.rs", l.name));
+ 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();
- if b.path.is_none() {
- b.path = Some(format!("src/bin/{}.rs", b.name));
+ let mut path = b.path.clone();
+ if path.is_none() {
+ path = Some(format!("src/bin/{}.rs", b.name.clone()));
}
- b
+ ExecTarget{ path: path.unwrap(), name: b.name }
});
- (~[l.clone()], b)
+ (~[LibTarget{ path: path.unwrap(), name: l.name }], b)
} 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!("src/{}.rs", l.name));
+ let l = lib.clone().unwrap()[0];
+ let mut path = l.path.clone();
+
+ if path.is_none() {
+ path = Some(format!("src/{}.rs", l.name));
}
- (~[l.clone()], ~[])
+
+ (~[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();
- if b.path.is_none() {
- b.path = Some(format!("src/{}.rs", b.name));
+ let mut path = b.path.clone();
+ if path.is_none() {
+ path = Some(format!("src/bin/{}.rs", b.name.clone()));
}
- b
+ ExecTarget{ path: path.unwrap(), name: b.name }
});
(~[], b)
} else {
#[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
*/
fn main() {
- let mut arguments = args();
- arguments.shift();
+ let mut reader = io::stdin();
+ let input = reader.read_to_str().unwrap();
- if arguments[0] != ~"--" {
- fail!("LOL");
+ 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 {
- arguments.shift();
+ fail!("Failed to execute")
}
+}
- match Process::new("rustc", arguments.as_slice()) {
- Ok(mut process) => {
- let stdout = process.stdout.get_mut_ref();
- println!("output: {:s}", stdout.read_to_str().unwrap());
-
- let stderr = process.stderr.get_mut_ref();
- println!("err: {:s}", stderr.read_to_str().unwrap());
- },
- Err(e) => fail!("Failed to execute: {}", e)
- };
+fn join(path: &Path, part: ~str) -> ~str {
+ path.join(part).as_str().unwrap().to_owned()
}