mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
Add --baobit-commit flag for build provenance
Adds BAOBIT_COMMIT constant to boot0/boot1 version.rs, allowing the Guix build channel commit to be embedded in firmware for reproducibility verification. - Add --baobit-commit CLI flag to xtask - Generate BAOBIT_COMMIT in boot version files - Display in audit command output - Simplify versioning.rs to always write files
This commit is contained in:
parent
4efe50d870
commit
3ea92d3bad
3 changed files with 47 additions and 42 deletions
|
|
@ -57,6 +57,7 @@ pub fn audit() {
|
||||||
crate::println!("Board type reads as: {:?}", boardtype);
|
crate::println!("Board type reads as: {:?}", boardtype);
|
||||||
crate::println!("Boot partition is: {:?}", owc.get_decoded::<AltBootCoding>());
|
crate::println!("Boot partition is: {:?}", owc.get_decoded::<AltBootCoding>());
|
||||||
crate::println!("Semver is: {}", crate::version::SEMVER);
|
crate::println!("Semver is: {}", crate::version::SEMVER);
|
||||||
|
crate::println!("Baobit commit is: {}", crate::version::BAOBIT_COMMIT);
|
||||||
crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION);
|
crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION);
|
||||||
crate::println!("Stepping is: {}", detect_stepping());
|
crate::println!("Stepping is: {}", detect_stepping());
|
||||||
let slot_mgr = bao1x_hal::acram::SlotManager::new();
|
let slot_mgr = bao1x_hal::acram::SlotManager::new();
|
||||||
|
|
|
||||||
|
|
@ -58,16 +58,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut builder = Builder::new();
|
let mut builder = Builder::new();
|
||||||
// encodes a timestamp into the build, unless '--no-timestamp' is passed
|
// encodes a timestamp into the build, unless '--no-timestamp' is passed
|
||||||
let do_version = env::args().filter(|x| x == "--no-timestamp").count() == 0;
|
let do_version = env::args().filter(|x| x == "--no-timestamp").count() == 0;
|
||||||
let git_describe = get_flag("--git-describe")?;
|
let git_describe_opt = get_flag("--git-describe")?.first().cloned();
|
||||||
let git_rev = get_flag("--git-rev")?;
|
let git_rev_opt = get_flag("--git-rev")?.first().cloned();
|
||||||
if git_describe.is_empty() {
|
let baobit_commit_opt = get_flag("--baobit-commit")?.first().cloned();
|
||||||
generate_version(do_version, None);
|
generate_version(do_version, git_describe_opt.clone(), baobit_commit_opt.clone());
|
||||||
} else {
|
if let Some(desc) = git_describe_opt {
|
||||||
generate_version(do_version, Some(git_describe[0].to_owned()));
|
builder.set_git_describe(desc);
|
||||||
builder.set_git_describe(git_describe[0].to_owned());
|
|
||||||
}
|
}
|
||||||
if !git_rev.is_empty() {
|
if let Some(rev) = git_rev_opt {
|
||||||
builder.set_git_rev(git_rev[0].to_owned());
|
builder.set_git_rev(rev);
|
||||||
}
|
}
|
||||||
if do_version {
|
if do_version {
|
||||||
builder.add_feature("timestamp");
|
builder.add_feature("timestamp");
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// It also generates timestamps, if demanded.
|
// It also generates timestamps, if demanded.
|
||||||
|
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::{Read, Write};
|
use std::io::Write;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use chrono::{Local, TimeZone, Utc};
|
use chrono::{Local, TimeZone, Utc};
|
||||||
|
|
@ -12,7 +12,11 @@ use chrono::{Local, TimeZone, Utc};
|
||||||
/// Ensures consistent version strings regardless of clone depth.
|
/// Ensures consistent version strings regardless of clone depth.
|
||||||
const GIT_ABBREV_LEN: u8 = 9;
|
const GIT_ABBREV_LEN: u8 = 9;
|
||||||
|
|
||||||
pub(crate) fn generate_version(add_timestamp: bool, forced_version: Option<String>) {
|
pub(crate) fn generate_version(
|
||||||
|
add_timestamp: bool,
|
||||||
|
forced_version: Option<String>,
|
||||||
|
baobit_commit: Option<String>,
|
||||||
|
) {
|
||||||
let gitver = {
|
let gitver = {
|
||||||
if let Some(ver) = forced_version {
|
if let Some(ver) = forced_version {
|
||||||
ver.as_bytes().to_vec()
|
ver.as_bytes().to_vec()
|
||||||
|
|
@ -32,12 +36,6 @@ pub(crate) fn generate_version(add_timestamp: bool, forced_version: Option<Strin
|
||||||
let boot0_version_file = "bao1x-boot/boot0/src/version.rs";
|
let boot0_version_file = "bao1x-boot/boot0/src/version.rs";
|
||||||
let boot1_version_file = "bao1x-boot/boot1/src/version.rs";
|
let boot1_version_file = "bao1x-boot/boot1/src/version.rs";
|
||||||
|
|
||||||
// Read the existing file to see if it needs to be updated.
|
|
||||||
let mut existing_data = Vec::new();
|
|
||||||
if let Ok(mut f) = std::fs::File::open(version_file) {
|
|
||||||
f.read_to_end(&mut existing_data).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut new_data = Vec::new();
|
let mut new_data = Vec::new();
|
||||||
print_header(&mut new_data);
|
print_header(&mut new_data);
|
||||||
if add_timestamp {
|
if add_timestamp {
|
||||||
|
|
@ -64,32 +62,39 @@ pub(crate) fn generate_version(add_timestamp: bool, forced_version: Option<Strin
|
||||||
.expect("couldn't add our semver");
|
.expect("couldn't add our semver");
|
||||||
new_data.extend_from_slice(&semver_code);
|
new_data.extend_from_slice(&semver_code);
|
||||||
|
|
||||||
if existing_data != new_data {
|
// BAOBIT_COMMIT for boot version files
|
||||||
let mut vfile = OpenOptions::new()
|
let mut baobit_commit_code = Vec::new();
|
||||||
.read(true)
|
if let Some(ref commit) = baobit_commit {
|
||||||
.write(true)
|
writeln!(baobit_commit_code, "pub const BAOBIT_COMMIT: &'static str = \"{}\";", commit)
|
||||||
.create(true)
|
.expect("couldn't add baobit commit");
|
||||||
.truncate(true)
|
} else {
|
||||||
.open(version_file)
|
writeln!(baobit_commit_code, "pub const BAOBIT_COMMIT: &'static str = \"unknown\";")
|
||||||
.expect("Can't open our version file for writing");
|
.expect("couldn't add baobit commit placeholder");
|
||||||
vfile.write_all(&new_data).expect("couldn't write new timestamp to version.rs");
|
|
||||||
let mut vfile = OpenOptions::new()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.truncate(true)
|
|
||||||
.open(boot0_version_file)
|
|
||||||
.expect("Can't open our version file for writing");
|
|
||||||
vfile.write_all(&semver_code).expect("couldn't write semver to version.rs");
|
|
||||||
let mut vfile = OpenOptions::new()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.truncate(true)
|
|
||||||
.open(boot1_version_file)
|
|
||||||
.expect("Can't open our version file for writing");
|
|
||||||
vfile.write_all(&semver_code).expect("couldn't write semver to version.rs");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut vfile = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(version_file)
|
||||||
|
.expect("Can't open our version file for writing");
|
||||||
|
vfile.write_all(&new_data).expect("couldn't write new timestamp to version.rs");
|
||||||
|
let mut vfile = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(boot0_version_file)
|
||||||
|
.expect("Can't open our version file for writing");
|
||||||
|
vfile.write_all(&semver_code).expect("couldn't write semver to version.rs");
|
||||||
|
vfile.write_all(&baobit_commit_code).expect("couldn't write baobit commit to version.rs");
|
||||||
|
let mut vfile = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(boot1_version_file)
|
||||||
|
.expect("Can't open our version file for writing");
|
||||||
|
vfile.write_all(&semver_code).expect("couldn't write semver to version.rs");
|
||||||
|
vfile.write_all(&baobit_commit_code).expect("couldn't write baobit commit to version.rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_header<U: Write>(out: &mut U) {
|
fn print_header<U: Write>(out: &mut U) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue