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 f8a4fff91..7ee7743a3 100644 --- a/xtask/src/versioning.rs +++ b/xtask/src/versioning.rs @@ -8,13 +8,26 @@ use std::process::Command; use chrono::{Local, TimeZone, Utc}; -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";