mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
make the rebuild process smarter so we're not triggering if stuff didn't change
This commit is contained in:
parent
1eaa4211d4
commit
323f737a4b
2 changed files with 61 additions and 48 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# set RUSTFLAGS=--remap-path-prefix=F:\largework\rust-win\code\xous-core\=build
|
||||
# $env:RUSTFLAGS="--remap-path-prefix=$(Get-Location)=build"
|
||||
|
||||
cargo xtask hw-image precursors/soc.svd
|
||||
cargo xtask app-image ball repl
|
||||
# cargo xtask minimal precursors/soc.svd
|
||||
|
||||
CertUtil -hashfile precursors/bbram-test1.nky MD5
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use std::{
|
|||
use std::fs::OpenOptions;
|
||||
use chrono::Local;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::fmt::Write as StdWrite;
|
||||
|
||||
type DynError = Box<dyn std::error::Error>;
|
||||
|
||||
|
|
@ -185,7 +186,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
Some("app-image") => {
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
let mut pkgs = base_pkgs.to_vec();
|
||||
let mut pkgs = hw_pkgs.to_vec();
|
||||
let apps: Vec<String> = args.collect();
|
||||
for app in &apps {
|
||||
pkgs.push(app);
|
||||
|
|
@ -1057,10 +1058,7 @@ fn whycheproof_import() -> Result<(), DynError> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
// fn dist_dir() -> PathBuf {
|
||||
// project_root().join("target/dist")
|
||||
// }
|
||||
|
||||
////////////////////////// Versioning infrastructure
|
||||
fn generate_version() {
|
||||
let output = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd")
|
||||
|
|
@ -1112,6 +1110,7 @@ pub(crate) fn get_version() -> crate::api::VersionString {
|
|||
out.write_all(s.as_bytes()).expect("couldn't write our version template header");
|
||||
}
|
||||
|
||||
////////////////////////// App manifest infrastructure
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::string::String;
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
|
|
@ -1134,40 +1133,34 @@ fn generate_app_menus(apps: &Vec::<String>) {
|
|||
let manifest: HashMap<String, AppManifest> =
|
||||
serde_json::from_str(&content).expect("Cannot parse manifest file");
|
||||
|
||||
let mut working_set = BTreeMap::<String, &AppManifest>::new();
|
||||
let mut l = HashMap::<String, HashMap::<String, String>>::new();
|
||||
// localization file
|
||||
// inject all the localization strings into the i18n file, which in theory reduces the churn on other crates that depend
|
||||
// on the global i18n file between build variants
|
||||
let mut l = BTreeMap::<String, BTreeMap::<String, String>>::new();
|
||||
for (_app, manifest) in manifest.iter() {
|
||||
for (name, translations) in &manifest.menu_name {
|
||||
let mut map = BTreeMap::<String, String>::new();
|
||||
for (language, phrase) in translations {
|
||||
map.insert(language.to_string(), phrase.to_string());
|
||||
}
|
||||
l.insert(name.to_string(), map);
|
||||
}
|
||||
}
|
||||
// output a JSON localizations file, if things have changed
|
||||
let new_i18n = serde_json::to_string(&l).unwrap();
|
||||
overwrite_if_changed(&new_i18n, "apps/i18n.json");
|
||||
|
||||
// output the Rust manifests - tailored just for the apps requested
|
||||
let mut working_set = BTreeMap::<String, &AppManifest>::new();
|
||||
// derive a working_set that is just the apps we requested
|
||||
for app in apps {
|
||||
if let Some(manifest) = manifest.get(app) {
|
||||
working_set.insert(app.to_string(), &manifest);
|
||||
for (name, translations) in &manifest.menu_name {
|
||||
let mut map = HashMap::<String, String>::new();
|
||||
for (language, phrase) in translations {
|
||||
map.insert(language.to_string(), phrase.to_string());
|
||||
}
|
||||
l.insert(name.to_string(), map);
|
||||
}
|
||||
} else {
|
||||
println!("Warning: app '{}' not found in `apps/manifest.json`, ignoring.", app);
|
||||
}
|
||||
}
|
||||
|
||||
// output a JSON localizations file
|
||||
let mut locale_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("apps/i18n.json").expect("Can't open our version file for writing");
|
||||
write!(locale_file, "{}", serde_json::to_string(&l).unwrap()).expect("couldn't write to the app locale file");
|
||||
|
||||
// output the Rust manifests
|
||||
let mut gam_tokens = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("services/gam/src/apps.rs").expect("Can't open our gam manifest for writing");
|
||||
// construct the gam_tokens
|
||||
let mut gam_tokens = String::new();
|
||||
writeln!(gam_tokens, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap();
|
||||
for (app_name, manifest) in working_set.iter() {
|
||||
writeln!(gam_tokens, "pub const APP_NAME_{}: &'static str = \"{}\";",
|
||||
|
|
@ -1182,30 +1175,25 @@ fn generate_app_menus(apps: &Vec::<String>) {
|
|||
).unwrap();
|
||||
}
|
||||
writeln!(gam_tokens, "];").unwrap();
|
||||
overwrite_if_changed(&gam_tokens, "services/gam/src/apps.rs");
|
||||
|
||||
let mut menu = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("services/status/src/app_autogen.rs").expect("Can't open our gam manifest for writing");
|
||||
// construct the app menu
|
||||
let mut menu = String::new();
|
||||
writeln!(menu, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap();
|
||||
|
||||
writeln!(menu, r####"use crate::StatusOpcode;
|
||||
use gam::{{MenuItem, MenuPayload}};
|
||||
use locales::t;
|
||||
use num_traits::*;
|
||||
use gam::{{MenuItem, MenuPayload}};
|
||||
use locales::t;
|
||||
use num_traits::*;
|
||||
|
||||
pub(crate) fn app_dispatch(gam: &gam::Gam, token: [u32; 4], index: usize) {{
|
||||
match index {{
|
||||
"####).unwrap();
|
||||
pub(crate) fn app_dispatch(gam: &gam::Gam, token: [u32; 4], index: usize) {{
|
||||
match index {{"####).unwrap();
|
||||
for (index, (app_name, _manifest)) in working_set.iter().enumerate() {
|
||||
writeln!(menu, "{} => gam.switch_to_app(gam::APP_NAME_{}, token).expect(\"couldn't raise app\"),",
|
||||
writeln!(menu, " {} => gam.switch_to_app(gam::APP_NAME_{}, token).expect(\"couldn't raise app\"),",
|
||||
index,
|
||||
app_name.to_uppercase()
|
||||
).unwrap();
|
||||
}
|
||||
writeln!(menu, r####"_ => log::error!("Invalid index for app dispatch: {{}}. Ignoring!", index),
|
||||
writeln!(menu, r####" _ => log::error!("Invalid index for app dispatch: {{}}. Ignoring!", index),
|
||||
}}
|
||||
}}
|
||||
|
||||
|
|
@ -1225,4 +1213,29 @@ pub(crate) fn app_menu_items(menu_items: &mut Vec::<MenuItem>, status_conn: u32)
|
|||
writeln!(menu, " }});\n",).unwrap();
|
||||
}
|
||||
writeln!(menu, "}}").unwrap();
|
||||
overwrite_if_changed(&menu, "services/status/src/app_autogen.rs");
|
||||
}
|
||||
|
||||
fn overwrite_if_changed(new_string: &String, old_file: &str) {
|
||||
let original = match OpenOptions::new()
|
||||
.read(true)
|
||||
.open(old_file) {
|
||||
Ok(mut ref_file) => {
|
||||
let mut buf = String::new();
|
||||
ref_file.read_to_string(&mut buf).expect("UTF-8 error in previous localization file");
|
||||
buf
|
||||
}
|
||||
_ => {
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
if &original != new_string {
|
||||
let mut new_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(old_file).expect("Can't open our gam manifest for writing");
|
||||
write!(new_file, "{}", new_string).unwrap()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue