2015-07-31 22:49:14 +00:00
|
|
|
use std::env;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
pub fn main() {
|
2016-12-08 04:26:08 +00:00
|
|
|
if let Ok(profile) = env::var("PROFILE") {
|
|
|
|
println!("cargo:rustc-cfg=build={:?}", profile);
|
|
|
|
}
|
|
|
|
|
2015-07-31 22:49:14 +00:00
|
|
|
let feature_prefix = "CARGO_FEATURE_";
|
|
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
|
|
|
|
|
|
|
let mut crates = Vec::new();
|
|
|
|
for (key, val) in env::vars() {
|
|
|
|
if val == "1" && key.starts_with(feature_prefix) {
|
|
|
|
let krate = key[feature_prefix.len()..].to_lowercase();
|
|
|
|
match krate.as_ref() {
|
2020-01-01 19:21:51 +00:00
|
|
|
"default" | "macos" | "unix" | "windows" => continue,
|
|
|
|
"nightly" | "test_unimplemented" => continue,
|
|
|
|
s if s.starts_with("feat_") => continue,
|
2018-03-12 08:20:58 +00:00
|
|
|
_ => {}
|
2015-07-31 22:49:14 +00:00
|
|
|
}
|
|
|
|
crates.push(krate.to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
crates.sort();
|
2015-12-08 02:42:08 +00:00
|
|
|
|
2015-07-31 22:49:14 +00:00
|
|
|
let mut cf = File::create(Path::new(&out_dir).join("uutils_crates.rs")).unwrap();
|
|
|
|
let mut mf = File::create(Path::new(&out_dir).join("uutils_map.rs")).unwrap();
|
2015-12-08 02:42:08 +00:00
|
|
|
|
2018-03-12 08:20:58 +00:00
|
|
|
mf.write_all(
|
|
|
|
"
|
2015-07-31 22:49:14 +00:00
|
|
|
type UtilityMap = HashMap<&'static str, fn(Vec<String>) -> i32>;
|
|
|
|
|
|
|
|
fn util_map() -> UtilityMap {
|
2018-03-12 08:20:58 +00:00
|
|
|
let mut map: UtilityMap = HashMap::new();\n"
|
|
|
|
.as_bytes(),
|
2020-01-28 05:14:11 +00:00
|
|
|
)
|
|
|
|
.unwrap();
|
2015-12-08 02:42:08 +00:00
|
|
|
|
2015-07-31 22:49:14 +00:00
|
|
|
for krate in crates {
|
2018-03-12 08:20:58 +00:00
|
|
|
cf.write_all(format!("extern crate uu_{krate};\n", krate = krate).as_bytes())
|
|
|
|
.unwrap();
|
2015-07-31 22:49:14 +00:00
|
|
|
|
|
|
|
match krate.as_ref() {
|
|
|
|
"hashsum" => {
|
2018-03-12 08:20:58 +00:00
|
|
|
mf.write_all(
|
|
|
|
"map.insert(\"hashsum\", uu_hashsum::uumain);
|
2015-12-08 02:42:08 +00:00
|
|
|
map.insert(\"md5sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"sha1sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"sha224sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"sha256sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"sha384sum\", uu_hashsum::uumain);
|
2016-04-16 13:17:15 +00:00
|
|
|
map.insert(\"sha512sum\", uu_hashsum::uumain);
|
2016-08-30 22:55:28 +00:00
|
|
|
map.insert(\"sha3sum\", uu_hashsum::uumain);
|
2016-04-16 13:17:15 +00:00
|
|
|
map.insert(\"sha3-224sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"sha3-256sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"sha3-384sum\", uu_hashsum::uumain);
|
2016-08-30 22:55:28 +00:00
|
|
|
map.insert(\"sha3-512sum\", uu_hashsum::uumain);
|
|
|
|
map.insert(\"shake128sum\", uu_hashsum::uumain);
|
2018-03-12 08:20:58 +00:00
|
|
|
map.insert(\"shake256sum\", uu_hashsum::uumain);\n"
|
|
|
|
.as_bytes(),
|
2020-01-28 05:14:11 +00:00
|
|
|
)
|
|
|
|
.unwrap();
|
2018-03-12 08:20:58 +00:00
|
|
|
}
|
2020-01-28 05:14:11 +00:00
|
|
|
_ => mf
|
|
|
|
.write_all(
|
|
|
|
format!(
|
|
|
|
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
|
|
|
|
krate = krate
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap(),
|
2015-07-31 22:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-08 02:42:08 +00:00
|
|
|
|
|
|
|
mf.write_all("map\n}\n".as_bytes()).unwrap();
|
|
|
|
|
2015-07-31 22:49:14 +00:00
|
|
|
cf.flush().unwrap();
|
|
|
|
mf.flush().unwrap();
|
|
|
|
}
|