mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
locales: generate locales as part of normal build
This makes `locales` its own package. As a result, the system will not rebuild the locales unless necessary. Additionally, the `generate-locales` command has been updated to simply force a rebuild of this file in order to keep the previous behavior. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
5ec4da0f8f
commit
207662414e
4 changed files with 40 additions and 25 deletions
|
|
@ -7,3 +7,11 @@ name = "locales"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
glob = "0.3.0"
|
||||||
|
quote = "1.0.2"
|
||||||
|
serde_json = "1.0.41"
|
||||||
|
proc-macro2 = "1.0"
|
||||||
|
regex = "1.3.1"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
|
@ -2,16 +2,16 @@
|
||||||
// the original crate is targeted at a non-workspace, `std` project structure. The adaptations here
|
// the original crate is targeted at a non-workspace, `std` project structure. The adaptations here
|
||||||
// make it suitable for `no_std` and workspace integration.
|
// make it suitable for `no_std` and workspace integration.
|
||||||
|
|
||||||
use crate::project_root;
|
use std::collections::HashMap;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use proc_macro2::{Ident, Span, TokenStream};
|
use proc_macro2::{Ident, Span, TokenStream};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::prelude::*;
|
|
||||||
|
|
||||||
type Key = String;
|
type Key = String;
|
||||||
type Locale = String;
|
type Locale = String;
|
||||||
|
|
@ -28,7 +28,7 @@ fn read_locales() -> Translations {
|
||||||
|
|
||||||
for entry in glob(&locales).expect("Failed to read glob pattern") {
|
for entry in glob(&locales).expect("Failed to read glob pattern") {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
// println!("cargo:rerun-if-changed={}", entry.display());
|
println!("cargo:rerun-if-changed={}", entry.display());
|
||||||
let file = File::open(entry).expect("Failed to open the file");
|
let file = File::open(entry).expect("Failed to open the file");
|
||||||
let mut reader = std::io::BufReader::new(file);
|
let mut reader = std::io::BufReader::new(file);
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
|
|
@ -138,9 +138,17 @@ fn write_code(code: TokenStream) {
|
||||||
.expect("Cannot write generated i18n code");
|
.expect("Cannot write generated i18n code");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_locales() {
|
fn main() {
|
||||||
let translations = read_locales();
|
let translations = read_locales();
|
||||||
let code = generate_code(translations);
|
let code = generate_code(translations);
|
||||||
//println!("{}", &code);
|
//println!("{}", &code);
|
||||||
write_code(code);
|
write_code(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn project_root() -> PathBuf {
|
||||||
|
Path::new(&env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.ancestors()
|
||||||
|
.nth(1)
|
||||||
|
.unwrap()
|
||||||
|
.to_path_buf()
|
||||||
|
}
|
||||||
|
|
@ -7,13 +7,6 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
filetime = "0.2"
|
||||||
#"ed25519-dalek" = "1"
|
#"ed25519-dalek" = "1"
|
||||||
#"pem" = "0.8"
|
#"pem" = "0.8"
|
||||||
|
|
||||||
# locales generation
|
|
||||||
glob = "0.3.0"
|
|
||||||
quote = "1.0.2"
|
|
||||||
serde_json = "1.0.41"
|
|
||||||
proc-macro2 = "1.0"
|
|
||||||
regex = "1.3.1"
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
|
@ -5,9 +5,6 @@ use std::{
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod generate_locales;
|
|
||||||
use generate_locales::*;
|
|
||||||
|
|
||||||
type DynError = Box<dyn std::error::Error>;
|
type DynError = Box<dyn std::error::Error>;
|
||||||
|
|
||||||
const PROGRAM_TARGET: &str = "riscv32imac-unknown-xous-elf";
|
const PROGRAM_TARGET: &str = "riscv32imac-unknown-xous-elf";
|
||||||
|
|
@ -190,7 +187,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Some("burn-kernel") => update_usb(true, false, false)?,
|
Some("burn-kernel") => update_usb(true, false, false)?,
|
||||||
Some("burn-loader") => update_usb(false, true, false)?,
|
Some("burn-loader") => update_usb(false, true, false)?,
|
||||||
Some("burn-soc") => update_usb(false, false, true)?,
|
Some("burn-soc") => update_usb(false, false, true)?,
|
||||||
Some("generate-locales") => generate_locales(),
|
Some("generate-locales") => generate_locales()?,
|
||||||
_ => print_help(),
|
_ => print_help(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -289,8 +286,6 @@ fn build_hw_image(
|
||||||
extra_args: Option<&[&str]>,
|
extra_args: Option<&[&str]>,
|
||||||
extra_packages: &[&str],
|
extra_packages: &[&str],
|
||||||
) -> Result<(), DynError> {
|
) -> Result<(), DynError> {
|
||||||
generate_locales();
|
|
||||||
|
|
||||||
let svd_file = match svd {
|
let svd_file = match svd {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => return Err("svd file not specified".into()),
|
None => return Err("svd file not specified".into()),
|
||||||
|
|
@ -303,10 +298,11 @@ fn build_hw_image(
|
||||||
|
|
||||||
// Tools use this environment variable to know when to rebuild the UTRA crate.
|
// Tools use this environment variable to know when to rebuild the UTRA crate.
|
||||||
std::env::set_var("XOUS_SVD_FILE", path.canonicalize().unwrap());
|
std::env::set_var("XOUS_SVD_FILE", path.canonicalize().unwrap());
|
||||||
|
println!("XOUS_SVD_FILE: {}", path.canonicalize().unwrap().display());
|
||||||
|
|
||||||
// extract key file names; replace with defaults if not specified
|
// extract key file names; replace with defaults if not specified
|
||||||
let loaderkey_file = lkey.unwrap_or("devkey/dev.key".into());
|
let loaderkey_file = lkey.unwrap_or_else(|| "devkey/dev.key".into());
|
||||||
let kernelkey_file = kkey.unwrap_or("devkey/dev.key".into());
|
let kernelkey_file = kkey.unwrap_or_else(|| "devkey/dev.key".into());
|
||||||
|
|
||||||
let kernel = build_kernel(debug)?;
|
let kernel = build_kernel(debug)?;
|
||||||
let mut init = vec![];
|
let mut init = vec![];
|
||||||
|
|
@ -465,8 +461,6 @@ fn renode_image(debug: bool, packages: &[&str], extra_packages: &[&str]) -> Resu
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(debug: bool, init: &[&str]) -> Result<(), DynError> {
|
fn run(debug: bool, init: &[&str]) -> Result<(), DynError> {
|
||||||
generate_locales();
|
|
||||||
|
|
||||||
let stream = if debug { "debug" } else { "release" };
|
let stream = if debug { "debug" } else { "release" };
|
||||||
|
|
||||||
build(&init, debug, None, None, None)?;
|
build(&init, debug, None, None, None)?;
|
||||||
|
|
@ -559,6 +553,11 @@ fn build(
|
||||||
dir.push(subdir);
|
dir.push(subdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print!(" Command: cargo");
|
||||||
|
for arg in &args {
|
||||||
|
print!(" {}", arg);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
let status = Command::new(cargo())
|
let status = Command::new(cargo())
|
||||||
.current_dir(dir)
|
.current_dir(dir)
|
||||||
.args(&args)
|
.args(&args)
|
||||||
|
|
@ -630,6 +629,13 @@ fn project_root() -> PathBuf {
|
||||||
.to_path_buf()
|
.to_path_buf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Force the locales to be regenerated. This simply `touches`
|
||||||
|
/// the `build.rs` for locales, causing a rebuild next time.
|
||||||
|
fn generate_locales() -> Result<(), std::io::Error> {
|
||||||
|
let ts = filetime::FileTime::from_system_time(std::time::SystemTime::now());
|
||||||
|
filetime::set_file_mtime("locales/src/lib.rs", ts)
|
||||||
|
}
|
||||||
|
|
||||||
// fn dist_dir() -> PathBuf {
|
// fn dist_dir() -> PathBuf {
|
||||||
// project_root().join("target/dist")
|
// project_root().join("target/dist")
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue