forked from uutils/coreutils
/
mkmain.rs
37 lines (29 loc) · 790 Bytes
/
mkmain.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![allow(unstable)]
use std::io::{File, Truncate, ReadWrite};
use std::os;
use std::path::Path;
static TEMPLATE: &'static str = "\
#![allow(unstable)]
extern crate \"@UTIL_CRATE@\" as uu@UTIL_CRATE@;
use std::os;
use uu@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;
}
let crat = args[1].as_slice();
let outfile = args[2].as_slice();
let main = TEMPLATE.replace("@UTIL_CRATE@", crat);
let mut out = File::open_mode(&Path::new(outfile), Truncate, ReadWrite);
match out.write(main.as_bytes()) {
Err(e) => panic!("{}", e),
_ => (),
}
}