OXYGENHUB
◆ show-stat oxygen / build.rs
1.2 KiB · Rust · last changed build: watch FLOW_HEADS only when OXY_BUILD does not name the build (refs andymccall/oxygenflow#52) 22 days ago source blame history raw
1
//! The build's identity, for `oxy --version`: `OXY_BUILD` when a release or
2
//! an install sets it (from `oxy describe`), else the heads a Flow job is
3
//! building, else "local build".
4
fn main() {
5
    println!("cargo:rerun-if-env-changed=OXY_BUILD");
6
    // The heads name the build only when OXY_BUILD does not: a CI job that
7
    // sets it stays fresh from one state to the next (oxygenflow#52).
8
    if !std::env::var("OXY_BUILD").is_ok_and(|b| !b.trim().is_empty()) {
9
        println!("cargo:rerun-if-env-changed=FLOW_HEADS");
10
    }
11
    let build = std::env::var("OXY_BUILD")
12
        .ok()
13
        .map(|b| b.trim().to_string())
14
        .filter(|b| !b.is_empty())
15
        .or_else(|| {
16
            std::env::var("FLOW_HEADS")
17
                .ok()
18
                .and_then(|h| {
19
                    h.split('+')
20
                        .next()
21
                        .map(|x| format!("flow #{}", &x[..12.min(x.len())]))
22
                })
23
                .filter(|b| b.len() > "flow #".len())
24
        })
25
        .unwrap_or_else(|| "local build".into());
26
    println!("cargo:rustc-env=OXY_BUILD_ID={build}");
27
    println!(
28
        "cargo:rustc-env=OXY_VERSION_LONG={} ({build})",
29
        std::env::var("CARGO_PKG_VERSION").unwrap()
30
    );
31
}