mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
cargo-read-manifest | cargo-rustc is working
At the moment, only the bare bones command is working with some defaults hardcoded. Also, there is a bunch of necessary cleanup and no tests. However, this marks the first end-to-end functionality in Cargo!
This commit is contained in:
parent
be4638769f
commit
904d8612a9
4
Makefile
4
Makefile
@ -2,7 +2,7 @@ RUSTC_TARGET = target
|
||||
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
|
||||
@ -27,7 +27,7 @@ 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
|
||||
|
||||
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
|
||||
|
||||
|
@ -12,14 +12,24 @@ 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<~[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 {
|
||||
@ -47,6 +57,7 @@ fn main() {
|
||||
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
|
||||
@ -57,34 +68,41 @@ fn main() {
|
||||
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 {
|
||||
|
@ -1,9 +1,16 @@
|
||||
#[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
|
||||
@ -12,23 +19,48 @@ use std::io::process::Process;
|
||||
*/
|
||||
|
||||
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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user