-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release: Use version string from git if available
If the SVSM is built from the git repository, get the version string via 'git describe' to have a more acurate version identifier. The git version allows to identify from which commit the code was built. Signed-off-by: Joerg Roedel <[email protected]>
- Loading branch information
1 parent
4b459da
commit 426f409
Showing
3 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// Copyright (c) 2025 SUSE LLC | ||
// | ||
// Author: Joerg Roedel <[email protected]> | ||
|
||
use std::fs::OpenOptions; | ||
use std::io::prelude::*; | ||
use std::process::Command; | ||
use std::string::String; | ||
|
||
fn git_version() -> Result<String, ()> { | ||
let output = Command::new("git") | ||
.args(["describe", "--always", "--dirty=+"]) | ||
.output() | ||
.map_err(|_| ())?; | ||
if !output.status.success() { | ||
return Err(()); | ||
} | ||
|
||
let stdout = String::from_utf8(output.stdout).unwrap(); | ||
let mut lines = stdout.lines(); | ||
let first_line = lines.next().unwrap().trim(); | ||
|
||
Ok(String::from(first_line)) | ||
} | ||
|
||
fn write_version(version: String) { | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.write(true) | ||
.truncate(true) | ||
.open("src/git_version.rs") | ||
.unwrap(); | ||
writeln!(&mut file, "// SPDX-License-Identifier: MIT\n//").unwrap(); | ||
writeln!( | ||
&mut file, | ||
"// This file is automatically generated - Any changes will be overwritten\n//\n" | ||
) | ||
.unwrap(); | ||
writeln!(&mut file, "pub const GIT_VERSION: &str = \"{}\";", version).unwrap(); | ||
} | ||
|
||
fn main() { | ||
write_version(git_version().unwrap_or_default()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters