Revert "ksud: make it buildable without git installed"

This reverts commit 8ed3bd53ac.
This commit is contained in:
tiann
2023-02-24 11:53:04 +08:00
parent 8ed3bd53ac
commit 745f109686
2 changed files with 15 additions and 25 deletions

View File

@@ -4,43 +4,34 @@ use std::io::Write;
use std::path::Path;
use std::process::Command;
fn get_git_version() -> Result<(u32, String), std::io::Error> {
let output = Command::new("git")
.args(["rev-list", "--count", "HEAD"])
.output()?;
let output = output.stdout;
let version_code = String::from_utf8(output).expect("Failed to read git count stdout");
fn get_git_version() -> (u32, String) {
let version_code = String::from_utf8(
Command::new("git")
.args(["rev-list", "--count", "HEAD"])
.output()
.expect("Failed to get git count")
.stdout,
)
.expect("Failed to read git count stdout");
let version_code: u32 = version_code
.trim()
.parse()
.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Failed to parse git count"))?;
.expect("Failed to parse git count");
let version_code = 10000 + 200 + version_code; // For historical reasons
let version_name = String::from_utf8(
Command::new("git")
.args(["describe", "--tags", "--always"])
.output()?
.output()
.expect("Failed to get git version")
.stdout,
)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to read git describe stdout",
)
})?;
Ok((version_code, version_name))
.expect("Failed to read git version stdout");
(version_code, version_name)
}
fn main() {
let (code, name) = match get_git_version() {
Ok((code, name)) => (code, name),
Err(_) => {
// show warning if git is not installed
println!("cargo:warning=Failed to get git version, using 0.0.0");
(0, "0.0.0".to_string())
}
};
let (code, name) = get_git_version();
let out_dir = env::var("OUT_DIR").expect("Failed to get $OUT_DIR");
let out_dir = Path::new(&out_dir);
File::create(Path::new(out_dir).join("VERSION_CODE"))

View File

@@ -223,7 +223,6 @@ pub fn on_boot_completed() -> Result<()> {
let module_img = Path::new(defs::MODULE_IMG);
if module_update_img.exists() {
// this is a update and we successfully booted
std::fs::rename(module_update_img, module_img)?;
if std::fs::rename(module_update_img, module_img).is_err() {
warn!("Failed to rename images, copy it now.",);
std::fs::copy(module_update_img, module_img)