forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkmain.rs
36 lines (29 loc) · 971 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
use std::env;
use std::io::Write;
use std::fs::File;
use std::path::Path;
static TEMPLATE: &'static str = "\
extern crate uu_@UTIL_CRATE@;
extern crate uucore;
use std::io::Write;
use uu_@UTIL_CRATE@::uumain;
fn main() {
uucore::panic::install_sigpipe_hook();
let code = uumain(uucore::args().collect());
// Since stdout is line-buffered by default, we need to ensure any pending
// writes are flushed before exiting. Ideally, this should be enforced by
// each utility.
//
// See: https://github.com/rust-lang/rust/issues/23818
//
std::io::stdout().flush().expect(\"could not flush stdout\");
std::process::exit(code);
}
";
pub fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let pkgname = env::var("CARGO_PKG_NAME").unwrap();
let main = TEMPLATE.replace("@UTIL_CRATE@", &pkgname);
let mut file = File::create(&Path::new(&out_dir).join("main.rs")).unwrap();
write!(file, "{}", main).unwrap();
}