From 0a870f75a465c8b9eaa34508b129bb2d52204908 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 22 Feb 2023 15:58:38 +1000 Subject: [PATCH] Anki version needs to be resolved at configure run time, not build time Fixes incorrect info in wheels when version bumped --- build/configure/src/bundle.rs | 2 +- build/configure/src/main.rs | 7 +++++-- build/configure/src/pylib.rs | 5 +++-- build/configure/src/python.rs | 4 ++-- build/ninja_gen/src/configure.rs | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build/configure/src/bundle.rs b/build/configure/src/bundle.rs index 10a2cf29a..7560fe07a 100644 --- a/build/configure/src/bundle.rs +++ b/build/configure/src/bundle.rs @@ -421,7 +421,7 @@ impl BuildAction for BuildWindowsInstallers { }); build.add_inputs("", inputs![":bundle:folder:std", ":bundle:folder:alt"]); - build.add_variable("version", version); + build.add_variable("version", &version); build.add_variable("bundle_root", "$builddir/bundle"); build.add_outputs("out", outputs); } diff --git a/build/configure/src/main.rs b/build/configure/src/main.rs index 624ead264..793e9ba88 100644 --- a/build/configure/src/main.rs +++ b/build/configure/src/main.rs @@ -27,8 +27,11 @@ use web::check_sql; use crate::proto::check_proto; -fn anki_version() -> &'static str { - include_str!("../../../.version").trim() +fn anki_version() -> String { + std::fs::read_to_string(".version") + .unwrap() + .trim() + .to_string() } fn main() -> Result<()> { diff --git a/build/configure/src/pylib.rs b/build/configure/src/pylib.rs index 851208d3a..81d5c09f3 100644 --- a/build/configure/src/pylib.rs +++ b/build/configure/src/pylib.rs @@ -13,6 +13,7 @@ use ninja_gen::python::PythonTest; use ninja_gen::Build; use ninja_gen::Result; +use crate::anki_version; use crate::platform::overriden_python_target_platform; use crate::python::BuildWheel; use crate::python::GenPythonProto; @@ -88,14 +89,14 @@ pub fn build_pylib(build: &mut Build) -> Result<()> { "wheels:anki", BuildWheel { name: "anki", - version: include_str!("../../../.version").trim(), + version: anki_version(), src_folder: "pylib/anki", gen_folder: "$builddir/pylib/anki", platform: overriden_python_target_platform().or(Some(build.host_platform)), deps: inputs![ ":pylib/anki", glob!("pylib/anki/**"), - "python/requirements.anki.in" + "python/requirements.anki.in", ], }, )?; diff --git a/build/configure/src/python.rs b/build/configure/src/python.rs index a36332053..f1d0a5356 100644 --- a/build/configure/src/python.rs +++ b/build/configure/src/python.rs @@ -117,7 +117,7 @@ impl BuildAction for GenPythonProto { pub struct BuildWheel { pub name: &'static str, - pub version: &'static str, + pub version: String, pub src_folder: &'static str, pub gen_folder: &'static str, pub platform: Option, @@ -149,7 +149,7 @@ impl BuildAction for BuildWheel { "py3-none-any".into() }; let name = self.name; - let version = self.version; + let version = &self.version; let wheel_path = format!("wheels/{name}-{version}-{tag}.whl"); build.add_outputs("out", vec![wheel_path]); } diff --git a/build/ninja_gen/src/configure.rs b/build/ninja_gen/src/configure.rs index dd7e17306..aaa26722b 100644 --- a/build/ninja_gen/src/configure.rs +++ b/build/ninja_gen/src/configure.rs @@ -19,8 +19,8 @@ impl BuildAction for ConfigureBuild { fn files(&mut self, build: &mut impl FilesHandle) { build.add_inputs("cmd", inputs![":build:configure"]); - // reconfigure when env changes - build.add_inputs("", inputs!["$builddir/env"]); + // reconfigure when external inputs change + build.add_inputs("", inputs!["$builddir/env", ".version"]); build.add_outputs("", ["build.ninja"]) }