1ebd83699SBo Chen // Copyright © 2020 Intel Corporation 2ebd83699SBo Chen // 3ebd83699SBo Chen // SPDX-License-Identifier: Apache-2.0 4ebd83699SBo Chen // 5ebd83699SBo Chen 6*559d1840SBo Chen #[macro_use(crate_version)] 7*559d1840SBo Chen extern crate clap; 8*559d1840SBo Chen 9ebd83699SBo Chen use std::process::Command; 10ebd83699SBo Chen 11ebd83699SBo Chen fn main() { 12*559d1840SBo Chen let mut version = crate_version!().to_string(); 13*559d1840SBo Chen 14*559d1840SBo Chen if let Ok(git_out) = Command::new("git").args(&["describe", "--dirty"]).output() { 15*559d1840SBo Chen if git_out.status.success() { 16*559d1840SBo Chen if let Ok(git_out_str) = String::from_utf8(git_out.stdout) { 17*559d1840SBo Chen version = git_out_str; 18*559d1840SBo Chen } 19*559d1840SBo Chen } 20*559d1840SBo Chen } 21ebd83699SBo Chen 22ebd83699SBo Chen // This println!() has a special behavior, as it will set the environment 23ebd83699SBo Chen // variable BUILT_VERSION, so that it can be reused from the binary. 24ebd83699SBo Chen // Particularly, this is used from src/main.rs to display the exact 25ebd83699SBo Chen // version. 26*559d1840SBo Chen println!("cargo:rustc-env=BUILT_VERSION={}", version); 27ebd83699SBo Chen } 28