mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Switch to 4-space tabs
This commit is contained in:
parent
acb4cbbc25
commit
db582fcf42
@ -14,15 +14,15 @@ use std::path::Path;
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
struct SerializedManifest {
|
||||
project: ~Project,
|
||||
lib: Option<~[SerializedLibTarget]>,
|
||||
bin: Option<~[SerializedExecTarget]>
|
||||
project: ~Project,
|
||||
lib: Option<~[SerializedLibTarget]>,
|
||||
bin: Option<~[SerializedExecTarget]>
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct SerializedTarget {
|
||||
name: ~str,
|
||||
path: Option<~str>
|
||||
name: ~str,
|
||||
path: Option<~str>
|
||||
}
|
||||
|
||||
pub type SerializedLibTarget = SerializedTarget;
|
||||
@ -31,79 +31,79 @@ pub type SerializedExecTarget = SerializedTarget;
|
||||
|
||||
#[deriving(Decodable,Eq,Clone,Ord)]
|
||||
struct ReadManifestFlags {
|
||||
manifest_path: ~str
|
||||
manifest_path: ~str
|
||||
}
|
||||
|
||||
impl FlagConfig for ReadManifestFlags {
|
||||
fn config(_: Option<ReadManifestFlags>, c: FlagConfiguration) -> FlagConfiguration {
|
||||
c
|
||||
}
|
||||
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);
|
||||
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());
|
||||
}
|
||||
if decoder.error.is_some() {
|
||||
fail!("Error: {}", decoder.error.unwrap());
|
||||
}
|
||||
|
||||
let root = toml::parse_from_file(flags.manifest_path).unwrap();
|
||||
let root = toml::parse_from_file(flags.manifest_path).unwrap();
|
||||
|
||||
let toml_manifest = from_toml::<SerializedManifest>(root.clone());
|
||||
let toml_manifest = from_toml::<SerializedManifest>(root.clone());
|
||||
|
||||
let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin);
|
||||
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 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);
|
||||
let encoded: ~str = Encoder::str_encode(&manifest);
|
||||
|
||||
println!("{}", encoded);
|
||||
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 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));
|
||||
if path.is_none() {
|
||||
path = Some(format!("src/{}.rs", l.name));
|
||||
}
|
||||
|
||||
let b = bin.get_ref().map(|b_ref| {
|
||||
let 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 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 {
|
||||
(~[], ~[])
|
||||
}
|
||||
|
||||
let b = bin.get_ref().map(|b_ref| {
|
||||
let 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 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 {
|
||||
(~[], ~[])
|
||||
}
|
||||
}
|
||||
|
@ -13,57 +13,57 @@ use std::path::Path;
|
||||
use cargo::Manifest;
|
||||
|
||||
/**
|
||||
cargo-rustc -- ...args
|
||||
cargo-rustc -- ...args
|
||||
|
||||
Delegate ...args to actual rustc command
|
||||
Delegate ...args to actual rustc command
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
let mut reader = io::stdin();
|
||||
let input = reader.read_to_str().unwrap();
|
||||
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 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 {
|
||||
//let mut arguments = args();
|
||||
//arguments.shift();
|
||||
//}
|
||||
|
||||
let Manifest{ root, lib, .. } = manifest;
|
||||
//if arguments[0] != ~"--" {
|
||||
//fail!("LOL");
|
||||
//} else {
|
||||
//arguments.shift();
|
||||
//}
|
||||
|
||||
let root = Path::new(root);
|
||||
let out_dir = lib[0].path;
|
||||
let target = join(&root, ~"target");
|
||||
let Manifest{ root, lib, .. } = manifest;
|
||||
|
||||
let args = ~[
|
||||
join(&root, out_dir),
|
||||
~"--out-dir", target,
|
||||
~"--crate-type", ~"lib"
|
||||
];
|
||||
let root = Path::new(root);
|
||||
let out_dir = lib[0].path;
|
||||
let target = join(&root, ~"target");
|
||||
|
||||
match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) {
|
||||
Err(_) => fail!("Couldn't mkdir -p"),
|
||||
Ok(val) => val
|
||||
}
|
||||
let args = ~[
|
||||
join(&root, out_dir),
|
||||
~"--out-dir", target,
|
||||
~"--crate-type", ~"lib"
|
||||
];
|
||||
|
||||
println!("Executing {}", args);
|
||||
match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) {
|
||||
Err(_) => fail!("Couldn't mkdir -p"),
|
||||
Ok(val) => val
|
||||
}
|
||||
|
||||
let mut p = Process::new("rustc", args).unwrap();
|
||||
let o = p.wait_with_output();
|
||||
println!("Executing {}", args);
|
||||
|
||||
if o.status == std::io::process::ExitStatus(0) {
|
||||
println!("output: {:s}", std::str::from_utf8(o.output).unwrap());
|
||||
} else {
|
||||
fail!("Failed to execute")
|
||||
}
|
||||
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()
|
||||
path.join(part).as_str().unwrap().to_owned()
|
||||
}
|
||||
|
@ -7,49 +7,49 @@ use std::os::{args,set_exit_status};
|
||||
use getopts::{reqopt,getopts};
|
||||
|
||||
/**
|
||||
cargo-verify-project --manifest=LOCATION
|
||||
cargo-verify-project --manifest=LOCATION
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
let arguments = args();
|
||||
let arguments = args();
|
||||
|
||||
let opts = ~[
|
||||
reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
|
||||
];
|
||||
let opts = ~[
|
||||
reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
|
||||
];
|
||||
|
||||
let matches = match getopts(arguments.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(_) => {
|
||||
fail("missing-argument", "manifest");
|
||||
return;
|
||||
let matches = match getopts(arguments.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(_) => {
|
||||
fail("missing-argument", "manifest");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if !matches.opt_present("m") {
|
||||
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);
|
||||
|
||||
let manifest = matches.opt_str("m").unwrap();
|
||||
let file = Path::new(manifest);
|
||||
if !file.exists() {
|
||||
fail("invalid", "not-found");
|
||||
return;
|
||||
}
|
||||
|
||||
if !file.exists() {
|
||||
fail("invalid", "not-found");
|
||||
return;
|
||||
}
|
||||
match toml::parse_from_file(file.as_str().unwrap()) {
|
||||
Err(_) => {
|
||||
fail("invalid", "invalid-format");
|
||||
return;
|
||||
},
|
||||
Ok(r) => r
|
||||
};
|
||||
|
||||
match toml::parse_from_file(file.as_str().unwrap()) {
|
||||
Err(_) => {
|
||||
fail("invalid", "invalid-format");
|
||||
return;
|
||||
},
|
||||
Ok(r) => r
|
||||
};
|
||||
|
||||
println!("{}", "{ \"success\": \"true\" }");
|
||||
println!("{}", "{ \"success\": \"true\" }");
|
||||
}
|
||||
|
||||
fn fail(reason: &str, value: &str) {
|
||||
println!(r#"\{ "{:s}", "{:s}" \}"#, reason, value);
|
||||
set_exit_status(1);
|
||||
println!(r#"\{ "{:s}", "{:s}" \}"#, reason, value);
|
||||
set_exit_status(1);
|
||||
}
|
||||
|
22
src/cargo.rs
22
src/cargo.rs
@ -5,22 +5,22 @@ use serialize::{Decoder};
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct Manifest {
|
||||
project: ~Project,
|
||||
root: ~str,
|
||||
lib: ~[LibTarget],
|
||||
bin: ~[ExecTarget]
|
||||
project: ~Project,
|
||||
root: ~str,
|
||||
lib: ~[LibTarget],
|
||||
bin: ~[ExecTarget]
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct ExecTarget {
|
||||
name: ~str,
|
||||
path: ~str
|
||||
name: ~str,
|
||||
path: ~str
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct LibTarget {
|
||||
name: ~str,
|
||||
path: ~str
|
||||
name: ~str,
|
||||
path: ~str
|
||||
}
|
||||
|
||||
//pub type LibTarget = Target;
|
||||
@ -28,7 +28,7 @@ pub struct LibTarget {
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct Project {
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
authors: ~[~str]
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
authors: ~[~str]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user