From 32f9ae1631ea1a6d2e7ee24f434aa2e144aca1d0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 9 Feb 2026 15:08:55 +0800 Subject: [PATCH] add --gitrev argument to xtask this allows build systems that lack git state to build an image. The effective git revision must be correctly computed by the build system or substituted for everything to work correctly. Note that completely faking the entry will lead to subtle problems down the road; for example, a purpose of the revision is to check which versions are compatible for upgrades against each other (some upgrade paths require a hop through an older version). Faking this can bypass the mechanism and then lead to instability down the road. However, some build systems (such as guix) strip out the git state, but the revision can be safely generated in the calling environment and passed as a variable. --- xtask/src/main.rs | 10 +++++++++- xtask/src/versioning.rs | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 933699e6a..8647b5b6b 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -58,7 +58,12 @@ fn main() -> Result<(), Box> { let mut builder = Builder::new(); // encodes a timestamp into the build, unless '--no-timestamp' is passed let do_version = env::args().filter(|x| x == "--no-timestamp").count() == 0; - generate_version(do_version); + let manual_version = get_flag("--gitrev")?; + if manual_version.is_empty() { + generate_version(do_version, None); + } else { + generate_version(do_version, Some(manual_version[0].to_owned())); + } if do_version { builder.add_feature("timestamp"); }; @@ -927,6 +932,7 @@ fn print_help() { [--debug-loader] [--offline] [--change-target] + [--gitrev revision] [cratespecs] is a list of 0 or more items of the following syntax: [name] crate 'name' to be built from local source @@ -953,6 +959,8 @@ be merged in with explicit app/service treatment with the following flags: [--swap offset:size] Specify a region for swap memory. The behavior of this depends on the target. [--change-target] Used to clean the cached target/*/*/build/SVD_PATH when changing build targets. This will also force a full rebuild every time the flag is specified. +[--gitrev revision] Force a git revision and do not execute `git describe --long` as part of the build process. For build systems that lack git state. + Note: there is no sanity checking on the passed revision. If it's specified incorrectly, subtle, weird things could happen. - An 'app' must be enumerated in apps/manifest.json. A pre-processor configures the launch menu based on the list of specified apps. diff --git a/xtask/src/versioning.rs b/xtask/src/versioning.rs index 00d4b7bc6..944448f9e 100644 --- a/xtask/src/versioning.rs +++ b/xtask/src/versioning.rs @@ -8,13 +8,26 @@ use std::process::Command; use chrono::Local; -pub(crate) fn generate_version(add_timestamp: bool) { - let output = if cfg!(target_os = "windows") { - Command::new("cmd").args(["/C", "git describe --long"]).output().expect("failed to execute process") - } else { - Command::new("sh").arg("-c").arg("git describe --long").output().expect("failed to execute process") +pub(crate) fn generate_version(add_timestamp: bool, forced_version: Option) { + let gitver = { + if let Some(ver) = forced_version { + ver.as_bytes().to_vec() + } else { + let output = if cfg!(target_os = "windows") { + Command::new("cmd") + .args(["/C", "git describe --long"]) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg("git describe --long") + .output() + .expect("failed to execute process") + }; + output.stdout + } }; - let gitver = output.stdout; let semver = String::from_utf8_lossy(&gitver); let version_file = "services/xous-ticktimer/src/version.rs";