feat: add common_version customization (#7869)

* feat: add product name customization

* chore: update tests
This commit is contained in:
Ning Sun
2026-03-26 18:18:06 +08:00
committed by GitHub
parent 1118fe243f
commit 08ded45c7a
15 changed files with 44 additions and 17 deletions

View File

@@ -43,14 +43,19 @@ impl Function for VersionFunction {
let version = match func_ctx.query_ctx.channel() {
Channel::Mysql => {
format!(
"{}-greptimedb-{}",
"{}-{}-{}",
std::env::var("GREPTIMEDB_MYSQL_SERVER_VERSION")
.unwrap_or_else(|_| "8.4.2".to_string()),
common_version::product_name(),
common_version::version()
)
}
Channel::Postgres => {
format!("PostgreSQL 16.3 GreptimeDB {}", common_version::version())
format!(
"PostgreSQL 16.3 {} {}",
common_version::product_name(),
common_version::version()
)
}
_ => common_version::version().to_string(),
};

View File

@@ -29,6 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let refresh = profile == "release";
println!("cargo:rerun-if-env-changed=RUSTC");
println!("cargo:rerun-if-env-changed=GREPTIME_PRODUCT_NAME");
// The "CARGO_WORKSPACE_DIR" is set manually (not by Rust itself) in Cargo config file, to
// solve the problem where the "CARGO_MANIFEST_DIR" is not what we want when this repo is
@@ -44,6 +45,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let product_version = load_product_version(&workspace_root);
println!("cargo:rustc-env=GREPTIME_PRODUCT_VERSION={product_version}");
let product_name = load_product_name();
println!("cargo:rustc-env=GREPTIME_PRODUCT_NAME={product_name}");
let repository = open_repository(&workspace_root);
if refresh {
@@ -100,6 +104,10 @@ fn load_product_version(workspace_root: &Path) -> String {
.unwrap_or_else(|| env::var("CARGO_PKG_VERSION").unwrap())
}
fn load_product_name() -> String {
env::var("GREPTIME_PRODUCT_NAME").unwrap_or_else(|_| "GreptimeDB".to_string())
}
fn emit_workspace_watch_list(
workspace_root: &Path,
repository: Option<&Repository>,

View File

@@ -109,6 +109,10 @@ pub const fn version() -> &'static str {
BUILD_INFO.version
}
pub const fn product_name() -> &'static str {
env!("GREPTIME_PRODUCT_NAME")
}
pub const fn verbose_version() -> &'static str {
const_format::formatcp!(
"\nbranch: {}\ncommit: {}\nclean: {}\nversion: {}",