2020-05-27 06:13:08 +00:00
|
|
|
// spell-checker:ignore (vars) krate
|
2020-05-04 06:25:36 +00:00
|
|
|
|
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() {
|
2020-05-25 18:38:31 +00:00
|
|
|
// println!("cargo:warning=Running build.rs");
|
|
|
|
|
2016-12-08 04:26:08 +00:00
|
|
|
if let Ok(profile) = env::var("PROFILE") {
|
|
|
|
println!("cargo:rustc-cfg=build={:?}", profile);
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:10:28 +00:00
|
|
|
let env_feature_prefix: &str = "CARGO_FEATURE_";
|
|
|
|
let feature_prefix: &str = "feat_";
|
|
|
|
let override_prefix: &str = "uu_";
|
|
|
|
|
2015-07-31 22:49:14 +00:00
|
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
2020-05-25 18:38:31 +00:00
|
|
|
// println!("cargo:warning=out_dir={}", out_dir);
|
2021-12-26 20:45:33 +00:00
|
|
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap().replace('\\', "/");
|
2020-05-25 18:38:31 +00:00
|
|
|
// println!("cargo:warning=manifest_dir={}", manifest_dir);
|
|
|
|
let util_tests_dir = format!("{}/tests/by-util", manifest_dir);
|
|
|
|
// println!("cargo:warning=util_tests_dir={}", util_tests_dir);
|
2015-07-31 22:49:14 +00:00
|
|
|
|
|
|
|
let mut crates = Vec::new();
|
|
|
|
for (key, val) in env::vars() {
|
2020-05-21 22:10:28 +00:00
|
|
|
if val == "1" && key.starts_with(env_feature_prefix) {
|
|
|
|
let krate = key[env_feature_prefix.len()..].to_lowercase();
|
2015-07-31 22:49:14 +00:00
|
|
|
match krate.as_ref() {
|
2021-07-12 15:33:24 +00:00
|
|
|
"default" | "macos" | "unix" | "windows" | "selinux" => continue, // common/standard feature names
|
|
|
|
"nightly" | "test_unimplemented" => continue, // crate-local custom features
|
2020-05-21 22:10:28 +00:00
|
|
|
"test" => continue, // over-ridden with 'uu_test' to avoid collision with rust core crate 'test'
|
|
|
|
s if s.starts_with(feature_prefix) => continue, // crate feature sets
|
|
|
|
_ => {} // util feature name
|
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 mf = File::create(Path::new(&out_dir).join("uutils_map.rs")).unwrap();
|
2020-05-25 18:38:31 +00:00
|
|
|
let mut tf = File::create(Path::new(&out_dir).join("test_modules.rs")).unwrap();
|
2015-12-08 02:42:08 +00:00
|
|
|
|
2018-03-12 08:20:58 +00:00
|
|
|
mf.write_all(
|
2022-01-11 14:45:02 +00:00
|
|
|
"type UtilityMap<T> = HashMap<&'static str, (fn(T) -> i32, fn() -> App<'static>)>;\n\
|
2021-04-02 09:56:49 +00:00
|
|
|
\n\
|
|
|
|
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n\
|
2021-10-18 21:47:09 +00:00
|
|
|
\t#[allow(unused_mut)]\n\
|
|
|
|
\t#[allow(clippy::let_and_return)]\n\
|
2021-04-02 09:56:49 +00:00
|
|
|
\tlet mut map = UtilityMap::new();\n\
|
|
|
|
"
|
2020-05-21 22:10:28 +00:00
|
|
|
.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 {
|
2020-05-04 06:25:36 +00:00
|
|
|
match krate.as_ref() {
|
2021-06-18 13:56:00 +00:00
|
|
|
// 'test' is named uu_test to avoid collision with rust core crate 'test'.
|
|
|
|
// It can also be invoked by name '[' for the '[ expr ] syntax'.
|
|
|
|
"uu_test" => {
|
|
|
|
mf.write_all(
|
|
|
|
format!(
|
|
|
|
"\
|
2021-06-15 13:35:49 +00:00
|
|
|
\tmap.insert(\"test\", ({krate}::uumain, {krate}::uu_app));\n\
|
|
|
|
\t\tmap.insert(\"[\", ({krate}::uumain, {krate}::uu_app));\n\
|
2021-06-18 13:56:00 +00:00
|
|
|
",
|
|
|
|
krate = krate
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
tf.write_all(
|
|
|
|
format!(
|
|
|
|
"#[path=\"{dir}/test_test.rs\"]\nmod test_test;\n",
|
|
|
|
dir = util_tests_dir,
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
}
|
2020-05-25 18:38:31 +00:00
|
|
|
k if k.starts_with(override_prefix) => {
|
|
|
|
mf.write_all(
|
2020-05-21 22:10:28 +00:00
|
|
|
format!(
|
2021-06-15 13:35:49 +00:00
|
|
|
"\tmap.insert(\"{k}\", ({krate}::uumain, {krate}::uu_app));\n",
|
2022-01-16 14:57:33 +00:00
|
|
|
k = &krate[override_prefix.len()..],
|
2020-05-21 22:10:28 +00:00
|
|
|
krate = krate
|
2020-05-05 06:47:26 +00:00
|
|
|
)
|
2020-05-21 22:10:28 +00:00
|
|
|
.as_bytes(),
|
|
|
|
)
|
2020-05-25 18:38:31 +00:00
|
|
|
.unwrap();
|
|
|
|
tf.write_all(
|
|
|
|
format!(
|
|
|
|
"#[path=\"{dir}/test_{k}.rs\"]\nmod test_{k};\n",
|
2022-01-16 14:57:33 +00:00
|
|
|
k = &krate[override_prefix.len()..],
|
2020-05-25 18:38:31 +00:00
|
|
|
dir = util_tests_dir,
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
"false" | "true" => {
|
|
|
|
mf.write_all(
|
2020-05-21 22:10:28 +00:00
|
|
|
format!(
|
2021-06-15 13:35:49 +00:00
|
|
|
"\tmap.insert(\"{krate}\", (r#{krate}::uumain, r#{krate}::uu_app));\n",
|
2020-05-21 22:10:28 +00:00
|
|
|
krate = krate
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
2020-05-04 06:25:36 +00:00
|
|
|
)
|
2020-05-25 18:38:31 +00:00
|
|
|
.unwrap();
|
|
|
|
tf.write_all(
|
|
|
|
format!(
|
|
|
|
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
|
|
|
|
krate = krate,
|
|
|
|
dir = util_tests_dir,
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
"hashsum" => {
|
|
|
|
mf.write_all(
|
2020-05-04 06:25:36 +00:00
|
|
|
format!(
|
2020-05-21 22:10:28 +00:00
|
|
|
"\
|
2021-06-15 13:35:49 +00:00
|
|
|
\tmap.insert(\"{krate}\", ({krate}::uumain, {krate}::uu_app_custom));\n\
|
|
|
|
\t\tmap.insert(\"md5sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha1sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha224sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha256sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha384sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha512sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha3sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha3-224sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha3-256sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha3-384sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"sha3-512sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"shake128sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
|
|
|
\t\tmap.insert(\"shake256sum\", ({krate}::uumain, {krate}::uu_app_common));\n\
|
2021-04-02 09:56:49 +00:00
|
|
|
",
|
2020-05-04 06:25:36 +00:00
|
|
|
krate = krate
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
2020-05-25 18:38:31 +00:00
|
|
|
.unwrap();
|
|
|
|
tf.write_all(
|
|
|
|
format!(
|
|
|
|
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
|
|
|
|
krate = krate,
|
|
|
|
dir = util_tests_dir,
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
mf.write_all(
|
2020-01-28 05:14:11 +00:00
|
|
|
format!(
|
2021-06-15 13:35:49 +00:00
|
|
|
"\tmap.insert(\"{krate}\", ({krate}::uumain, {krate}::uu_app));\n",
|
2020-01-28 05:14:11 +00:00
|
|
|
krate = krate
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
2020-05-25 18:38:31 +00:00
|
|
|
.unwrap();
|
|
|
|
tf.write_all(
|
|
|
|
format!(
|
|
|
|
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
|
|
|
|
krate = krate,
|
|
|
|
dir = util_tests_dir,
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
}
|
2015-07-31 22:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-08 02:42:08 +00:00
|
|
|
|
2020-02-07 09:38:26 +00:00
|
|
|
mf.write_all(b"map\n}\n").unwrap();
|
2015-12-08 02:42:08 +00:00
|
|
|
|
2015-07-31 22:49:14 +00:00
|
|
|
mf.flush().unwrap();
|
2020-05-25 18:38:31 +00:00
|
|
|
tf.flush().unwrap();
|
2015-07-31 22:49:14 +00:00
|
|
|
}
|