graphql-engine/v3/crates/engine/build.rs
Samir Talwar dfccac348e Use Clippy to help simplify conditions. (#648)
Just because it's fewer lines of code.

1. Invert `if`/`else` blocks with negative conditions.
2. Unwrap redundant `else` blocks.
3. Simplify a few branches to `let … else`.
4. Replace a `match` with `if let`.

V3_GIT_ORIGIN_REV_ID: 4f10730b688d21c1fc86a45ee5fb4adf008b3d94
2024-05-31 13:02:00 +00:00

27 lines
1009 B
Rust

fn main() -> Result<(), String> {
// Ensure that we rebuild if the version is specified.
println!("cargo:rerun-if-env-changed=RELEASE_VERSION");
// On release builds, use the Git commit as a backup if the version is not set.
// On debug builds, use "dev".
// If we fail to get the Git information, fail.
let build_profile = std::env::var("PROFILE").map_err(|err| err.to_string())?;
let release_version = if build_profile == "release" {
if let Some(version) = option_env!("RELEASE_VERSION") {
version.to_string()
} else {
let git_commit_ref = build_data::get_git_commit_short()?;
let git_dirty = build_data::get_git_dirty().unwrap_or(false);
if git_dirty {
format!("{git_commit_ref}-dirty")
} else {
git_commit_ref
}
}
} else {
"dev".to_string()
};
println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION={release_version}");
Ok(())
}