coreutils/mkmain.rs
kwantam d4f39e1638 dependency builds use Cargo
With this change, individual submodules can specify their dependencies with
an additional file called "deps.mk" in the subdir. When building, only
the dependencies that are necessary are built, using cargo, and then linked.

This greatly simplifies adding new dependencies: add the package in
deps/Cargo.toml, and add the appropriate line in "deps.mk" in the
src/utilname/ directory, and the dependency will be built automatically
as needed.

This also removes the need to use git submodules.
2015-04-25 22:18:03 -04:00

42 lines
959 B
Rust

#![feature(exit_status)]
use std::env;
use std::io::Write;
use std::fs::File;
static TEMPLATE: &'static str = "\
#![feature(exit_status)]
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
use std::env;
use uu@UTIL_CRATE@::uumain;
fn main() {
env::set_exit_status(uumain(env::args().collect()));
}
";
fn main() {
let args : Vec<String> = env::args().collect();
if args.len() != 3 {
println!("usage: mkbuild <crate> <outfile>");
env::set_exit_status(1);
return;
}
let crat = match &args[1][..] {
"false" => "uufalse",
"test" => "uutest",
"true" => "uutrue",
_ => &args[1][..],
};
let outfile = &args[2][..];
let main = TEMPLATE.replace("@UTIL_CRATE@", crat);
match File::create(outfile) {
Ok(mut out) => match out.write_all(main.as_bytes()) {
Err(e) => panic!("{}", e),
_ => (),
},
Err(e) => panic!("{}", e),
}
}