-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.rs
More file actions
53 lines (44 loc) · 1.38 KB
/
Copy pathbuild.rs
File metadata and controls
53 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::process::Command;
fn normalized_version(raw: &str) -> String {
let trimmed = raw.trim();
if let Some(without_prefix) = trimmed.strip_prefix('v')
&& without_prefix
.chars()
.next()
.is_some_and(|ch| ch.is_ascii_digit())
{
return without_prefix.to_string();
}
trimmed.to_string()
}
fn version_from_git() -> Option<String> {
let output = Command::new("git")
.args(["describe", "--tags", "--always", "--dirty"])
.output()
.ok()?;
if !output.status.success() {
return None;
}
let value = String::from_utf8(output.stdout).ok()?;
let normalized = normalized_version(value.trim());
if normalized.is_empty() {
return None;
}
Some(normalized)
}
fn build_version() -> String {
if let Ok(version) = std::env::var("OPENCODE_KANBAN_VERSION") {
let normalized = normalized_version(&version);
if !normalized.is_empty() {
return normalized;
}
}
version_from_git().unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string())
}
fn main() {
println!("cargo:rerun-if-env-changed=OPENCODE_KANBAN_VERSION");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/packed-refs");
let version = build_version();
println!("cargo:rustc-env=OPENCODE_KANBAN_BUILD_VERSION={version}");
}