From e835922ded1bfe02c6eca6817af75fb717cc25ca Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 4 Jul 2023 17:17:41 +1000 Subject: [PATCH] Fix i18n build script not responding to env var changes Not much use declaring the cargo flag when we bake the env var into the binary! Also treat an empty variable as missing. --- .cargo/config.toml | 1 - rslib/i18n/build.rs | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index e5c67dcfb..ed1dcf7e6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,4 @@ [env] -# STRINGS_JSON = { value = "out/rslib/i18n/strings.json", relative = true } STRINGS_PY = { value = "out/pylib/anki/_fluent.py", relative = true } STRINGS_JS = { value = "out/ts/lib/ftl.js", relative = true } STRINGS_DTS = { value = "out/ts/lib/ftl.d.ts", relative = true } diff --git a/rslib/i18n/build.rs b/rslib/i18n/build.rs index 0f2478158..4baa6a709 100644 --- a/rslib/i18n/build.rs +++ b/rslib/i18n/build.rs @@ -8,7 +8,8 @@ mod python; mod typescript; mod write_strings; -use std::path::Path; +use std::env; +use std::path::PathBuf; use anki_io::create_dir_all; use anki_io::write_file_if_changed; @@ -32,10 +33,13 @@ fn main() -> Result<()> { // write strings.json file to requested path println!("cargo:rerun-if-env-changed=STRINGS_JSON"); - if let Some(path) = option_env!("STRINGS_JSON") { - let meta_json = serde_json::to_string_pretty(&modules).unwrap(); - create_dir_all(Path::new(path).parent().unwrap())?; - write_file_if_changed(path, meta_json)?; + if let Ok(path) = env::var("STRINGS_JSON") { + if !path.is_empty() { + let path = PathBuf::from(path); + let meta_json = serde_json::to_string_pretty(&modules).unwrap(); + create_dir_all(path.parent().unwrap())?; + write_file_if_changed(path, meta_json)?; + } } Ok(()) }