ksud: unify version
This commit is contained in:
43
userspace/ksud/build.rs
Normal file
43
userspace/ksud/build.rs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
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().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()
|
||||||
|
.expect("Failed to get git version")
|
||||||
|
.stdout,
|
||||||
|
)
|
||||||
|
.expect("Failed to read git version stdout");
|
||||||
|
(version_code, version_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
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"))
|
||||||
|
.expect("Failed to create VERSION_CODE")
|
||||||
|
.write_all(code.to_string().as_bytes())
|
||||||
|
.expect("Failed to write VERSION_CODE");
|
||||||
|
|
||||||
|
File::create(Path::new(out_dir).join("VERSION_NAME"))
|
||||||
|
.expect("Failed to create VERSION_NAME")
|
||||||
|
.write_all(name.trim().as_bytes())
|
||||||
|
.expect("Failed to write VERSION_NAME");
|
||||||
|
}
|
||||||
@@ -6,11 +6,11 @@ use android_logger::Config;
|
|||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
|
|
||||||
use crate::{apk_sign, debug, event, module};
|
use crate::{apk_sign, debug, defs, event, module};
|
||||||
|
|
||||||
/// KernelSU userspace cli
|
/// KernelSU userspace cli
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version = defs::VERSION_NAME, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Commands,
|
command: Commands,
|
||||||
|
|||||||
@@ -19,3 +19,7 @@ pub const MODULE_UPDATE_TMP_DIR: &str = concatcp!(WORKING_DIR, "modules_update/"
|
|||||||
pub const DISABLE_FILE_NAME: &str = "disable";
|
pub const DISABLE_FILE_NAME: &str = "disable";
|
||||||
pub const UPDATE_FILE_NAME: &str = "update";
|
pub const UPDATE_FILE_NAME: &str = "update";
|
||||||
pub const REMOVE_FILE_NAME: &str = "remove";
|
pub const REMOVE_FILE_NAME: &str = "remove";
|
||||||
|
|
||||||
|
|
||||||
|
pub const VERSION_CODE: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_CODE"));
|
||||||
|
pub const VERSION_NAME: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_NAME"));
|
||||||
@@ -209,6 +209,8 @@ fn exec_script<T: AsRef<Path>>(path: T, wait: bool) -> Result<()> {
|
|||||||
.arg("sh")
|
.arg("sh")
|
||||||
.arg(path.as_ref())
|
.arg(path.as_ref())
|
||||||
.env("ASH_STANDALONE", "1")
|
.env("ASH_STANDALONE", "1")
|
||||||
|
.env("KSU_VER_CODE", defs::VERSION_CODE)
|
||||||
|
.env("KSU_VER", defs::VERSION_NAME)
|
||||||
.env(
|
.env(
|
||||||
"PATH",
|
"PATH",
|
||||||
format!("{}:{}", env_var("PATH").unwrap(), defs::BINARY_DIR),
|
format!("{}:{}", env_var("PATH").unwrap(), defs::BINARY_DIR),
|
||||||
|
|||||||
Reference in New Issue
Block a user