coreutils/mkmain.rs

42 lines
908 B
Rust
Raw Normal View History

use std::io::{File, Truncate, ReadWrite};
use std::os;
use std::path::Path;
use std::str::replace;
static TEMPLATE: &'static str = "\
extern crate @UTIL_CRATE@;
use std::os;
use @UTIL_CRATE@::uumain;
fn main() {
os::set_exit_status(uumain(os::args()));
}
";
fn main() {
let args = os::args();
if args.len() != 3 {
println!("usage: mkbuild <crate> <outfile>");
os::set_exit_status(1);
return;
}
2014-07-20 01:13:55 +00:00
let crat = match args[1].as_slice() {
2014-07-12 01:12:29 +00:00
"test" => "uutest",
"true" => "uutrue",
"false" => "uufalse",
"sync" => "uusync",
s => s.clone(),
};
2014-07-20 01:13:55 +00:00
let outfile = args[2].as_slice();
let main = std::str::replace(TEMPLATE, "@UTIL_CRATE@", crat);
let mut out = File::open_mode(&Path::new(outfile), Truncate, ReadWrite);
match out.write(main.as_bytes()) {
Err(e) => fail!("{}", e),
_ => (),
}
}