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