build.rs (1184B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 use serde_json::Value; 6 use std::fmt; 7 8 include!(concat!(env!("OUT_DIR"), "/build-info.rs")); 9 10 pub struct BuildInfo; 11 12 impl BuildInfo { 13 pub fn version() -> &'static str { 14 crate_version!() 15 } 16 17 pub fn hash() -> Option<&'static str> { 18 COMMIT_HASH 19 } 20 21 pub fn date() -> Option<&'static str> { 22 COMMIT_DATE 23 } 24 } 25 26 impl fmt::Display for BuildInfo { 27 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 28 write!(f, "{}", BuildInfo::version())?; 29 match (BuildInfo::hash(), BuildInfo::date()) { 30 (Some(hash), Some(date)) => write!(f, " ({} {})", hash, date)?, 31 (Some(hash), None) => write!(f, " ({})", hash)?, 32 _ => {} 33 } 34 Ok(()) 35 } 36 } 37 38 impl From<BuildInfo> for Value { 39 fn from(_: BuildInfo) -> Value { 40 Value::String(BuildInfo::version().to_string()) 41 } 42 } 43 44 /// Returns build-time information about geckodriver. 45 pub fn build_info() -> BuildInfo { 46 BuildInfo {} 47 }