mirror of
https://github.com/ankitects/anki.git
synced 2025-12-21 10:52:57 -05:00
fix(build): treat proto/i18n's implicit outputs as inputs (#4439)
* fix(build): make proto/i18n's implicit outputs explicit * use option_env! instead of rerun-if-env-changed > As of 1.46, using env! and option_env! in source code will automatically detect changes and trigger rebuilds. https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-env-changed * ditto for STRINGS_PY and STRINGS_TS * fix comment * remove space
This commit is contained in:
parent
4c7b343231
commit
a245f8ce61
4 changed files with 12 additions and 7 deletions
|
|
@ -8,7 +8,6 @@ mod python;
|
|||
mod typescript;
|
||||
mod write_strings;
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anki_io::create_dir_all;
|
||||
|
|
@ -32,8 +31,7 @@ fn main() -> Result<()> {
|
|||
python::write_py_interface(&modules)?;
|
||||
|
||||
// write strings.json file to requested path
|
||||
println!("cargo:rerun-if-env-changed=STRINGS_JSON");
|
||||
if let Ok(path) = env::var("STRINGS_JSON") {
|
||||
if let Some(path) = option_env!("STRINGS_JSON") {
|
||||
if !path.is_empty() {
|
||||
let path = PathBuf::from(path);
|
||||
let meta_json = serde_json::to_string_pretty(&modules).unwrap();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use std::env;
|
||||
use std::fmt::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ pub fn write_py_interface(modules: &[Module]) -> Result<()> {
|
|||
render_methods(modules, &mut out);
|
||||
render_legacy_enum(modules, &mut out);
|
||||
|
||||
if let Ok(path) = env::var("STRINGS_PY") {
|
||||
if let Some(path) = option_env!("STRINGS_PY") {
|
||||
let path = PathBuf::from(path);
|
||||
create_dir_all(path.parent().unwrap())?;
|
||||
write_file_if_changed(path, out)?;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use std::env;
|
||||
use std::fmt::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -22,7 +21,7 @@ pub fn write_ts_interface(modules: &[Module]) -> Result<()> {
|
|||
render_module_map(modules, &mut ts_out);
|
||||
render_methods(modules, &mut ts_out);
|
||||
|
||||
if let Ok(path) = env::var("STRINGS_TS") {
|
||||
if let Some(path) = option_env!("STRINGS_TS") {
|
||||
let path = PathBuf::from(path);
|
||||
create_dir_all(path.parent().unwrap())?;
|
||||
write_file_if_changed(path, ts_out)?;
|
||||
|
|
|
|||
|
|
@ -335,6 +335,15 @@ pub fn write_file_if_changed(path: impl AsRef<Path>, contents: impl AsRef<[u8]>)
|
|||
.map(|existing| existing != contents)
|
||||
.unwrap_or(true)
|
||||
};
|
||||
|
||||
match std::env::var("CARGO_PKG_NAME") {
|
||||
Ok(pkg) if pkg == "anki_proto" || pkg == "anki_i18n" => {
|
||||
// at comptime for the proto/i18n crates, register implicit output as input
|
||||
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if changed {
|
||||
write_file(path, contents)?;
|
||||
Ok(true)
|
||||
|
|
|
|||
Loading…
Reference in a new issue