From c52c02013e3ab64fceabf80c6491dde4b672c6a6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 10 Oct 2022 02:53:15 +0800 Subject: [PATCH] add command line feature flags back to xtask; detect & track language changes --- xtask/src/main.rs | 13 +++++++++++++ xtask/src/utils.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 2dc90b55e..412416eda 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -134,6 +134,19 @@ fn main() -> Result<(), Box> { builder.add_apps(&extra_apps); let extra_services = get_flag("--service")?; builder.add_services(&extra_services); + // extract features, and especially track language features + let features = get_flag("--feature")?; + let mut language_set = false; + for feature in features { + builder.add_feature(&feature); + if feature.starts_with("xous/lang-") { + track_language_changes(&feature)?; + language_set = true; + } + } + if !language_set { // the default language is english + track_language_changes("en")?; + } // ---- now process the verb plus position dependent arguments ---- let mut args = env::args(); diff --git a/xtask/src/utils.rs b/xtask/src/utils.rs index a3a0c2e10..936acbcd9 100644 --- a/xtask/src/utils.rs +++ b/xtask/src/utils.rs @@ -1,5 +1,5 @@ use std::{ - fs::File, + fs::{File, OpenOptions}, io::{Read, Write}, path::{Path, PathBuf}, process::Command, @@ -375,3 +375,36 @@ pub(crate) fn whycheproof_import() -> Result<(), crate::DynError> { return Ok(()); } + +pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynError> { + let last_config = format!("target/{}/LAST_LANG", TARGET_TRIPLE); + std::fs::create_dir_all(format!("target/{}/", TARGET_TRIPLE)).unwrap(); + let mut contents = String::new(); + + let changed = match OpenOptions::new() + .read(true) + .open(&last_config) { + Ok(mut file) => { + file.read_to_string(&mut contents).unwrap(); + if contents != last_lang { + true + } else { + false + } + } + _ => true + }; + if changed { + println!("Locale language changed to {}", last_lang); + let mut file = OpenOptions::new() + .create(true) + .write(true) + .truncate(true) + .open(&last_config).unwrap(); + write!(file, "{}", last_lang).unwrap(); + generate_locales()? + } else { + println!("No change to the target locale language of {}", contents); + } + Ok(()) +} \ No newline at end of file