#[cfg(any(
feature = "build",
feature = "cargo",
feature = "git",
feature = "rustc",
feature = "si"
))]
pub(crate) mod vergen_key {
#[cfg(feature = "build")]
use crate::constants::{BUILD_DATE_NAME, BUILD_TIMESTAMP_NAME};
#[cfg(feature = "cargo")]
use crate::constants::{
CARGO_DEBUG, CARGO_DEPENDENCIES, CARGO_FEATURES, CARGO_OPT_LEVEL, CARGO_TARGET_TRIPLE,
};
#[cfg(feature = "git")]
use crate::constants::{
GIT_BRANCH_NAME, GIT_COMMIT_AUTHOR_EMAIL, GIT_COMMIT_AUTHOR_NAME, GIT_COMMIT_COUNT,
GIT_COMMIT_DATE_NAME, GIT_COMMIT_MESSAGE, GIT_COMMIT_TIMESTAMP_NAME, GIT_DESCRIBE_NAME,
GIT_DIRTY_NAME, GIT_SHA_NAME,
};
#[cfg(feature = "rustc")]
use crate::constants::{
RUSTC_CHANNEL_NAME, RUSTC_COMMIT_DATE, RUSTC_COMMIT_HASH, RUSTC_HOST_TRIPLE_NAME,
RUSTC_LLVM_VERSION, RUSTC_SEMVER_NAME,
};
#[cfg(feature = "si")]
use crate::constants::{
SYSINFO_CPU_BRAND, SYSINFO_CPU_CORE_COUNT, SYSINFO_CPU_FREQUENCY, SYSINFO_CPU_NAME,
SYSINFO_CPU_VENDOR, SYSINFO_MEMORY, SYSINFO_NAME, SYSINFO_OS_VERSION, SYSINFO_USER,
};
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub enum VergenKey {
#[cfg(feature = "build")]
BuildDate,
#[cfg(feature = "build")]
BuildTimestamp,
#[cfg(feature = "cargo")]
CargoDebug,
#[cfg(feature = "cargo")]
CargoFeatures,
#[cfg(feature = "cargo")]
CargoOptLevel,
#[cfg(feature = "cargo")]
CargoTargetTriple,
#[cfg(feature = "cargo")]
CargoDependencies,
#[cfg(feature = "git")]
GitBranch,
#[cfg(feature = "git")]
GitCommitAuthorEmail,
#[cfg(feature = "git")]
GitCommitAuthorName,
#[cfg(feature = "git")]
GitCommitCount,
#[cfg(feature = "git")]
GitCommitDate,
#[cfg(feature = "git")]
GitCommitMessage,
#[cfg(feature = "git")]
GitCommitTimestamp,
#[cfg(feature = "git")]
GitDescribe,
#[cfg(feature = "git")]
GitSha,
#[cfg(feature = "git")]
GitDirty,
#[cfg(feature = "rustc")]
RustcChannel,
#[cfg(feature = "rustc")]
RustcCommitDate,
#[cfg(feature = "rustc")]
RustcCommitHash,
#[cfg(feature = "rustc")]
RustcHostTriple,
#[cfg(feature = "rustc")]
RustcLlvmVersion,
#[cfg(feature = "rustc")]
RustcSemver,
#[cfg(feature = "si")]
SysinfoName,
#[cfg(feature = "si")]
SysinfoOsVersion,
#[cfg(feature = "si")]
SysinfoUser,
#[cfg(feature = "si")]
SysinfoMemory,
#[cfg(feature = "si")]
SysinfoCpuVendor,
#[cfg(feature = "si")]
SysinfoCpuCoreCount,
#[cfg(feature = "si")]
SysinfoCpuName,
#[cfg(feature = "si")]
SysinfoCpuBrand,
#[cfg(feature = "si")]
SysinfoCpuFrequency,
}
impl VergenKey {
#[must_use]
pub fn name(self) -> &'static str {
match self {
#[cfg(feature = "build")]
VergenKey::BuildDate => BUILD_DATE_NAME,
#[cfg(feature = "build")]
VergenKey::BuildTimestamp => BUILD_TIMESTAMP_NAME,
#[cfg(feature = "cargo")]
VergenKey::CargoDebug => CARGO_DEBUG,
#[cfg(feature = "cargo")]
VergenKey::CargoFeatures => CARGO_FEATURES,
#[cfg(feature = "cargo")]
VergenKey::CargoOptLevel => CARGO_OPT_LEVEL,
#[cfg(feature = "cargo")]
VergenKey::CargoTargetTriple => CARGO_TARGET_TRIPLE,
#[cfg(feature = "cargo")]
VergenKey::CargoDependencies => CARGO_DEPENDENCIES,
#[cfg(feature = "git")]
VergenKey::GitBranch => GIT_BRANCH_NAME,
#[cfg(feature = "git")]
VergenKey::GitCommitAuthorEmail => GIT_COMMIT_AUTHOR_EMAIL,
#[cfg(feature = "git")]
VergenKey::GitCommitAuthorName => GIT_COMMIT_AUTHOR_NAME,
#[cfg(feature = "git")]
VergenKey::GitCommitCount => GIT_COMMIT_COUNT,
#[cfg(feature = "git")]
VergenKey::GitCommitDate => GIT_COMMIT_DATE_NAME,
#[cfg(feature = "git")]
VergenKey::GitCommitMessage => GIT_COMMIT_MESSAGE,
#[cfg(feature = "git")]
VergenKey::GitCommitTimestamp => GIT_COMMIT_TIMESTAMP_NAME,
#[cfg(feature = "git")]
VergenKey::GitDescribe => GIT_DESCRIBE_NAME,
#[cfg(feature = "git")]
VergenKey::GitSha => GIT_SHA_NAME,
#[cfg(feature = "git")]
VergenKey::GitDirty => GIT_DIRTY_NAME,
#[cfg(feature = "rustc")]
VergenKey::RustcChannel => RUSTC_CHANNEL_NAME,
#[cfg(feature = "rustc")]
VergenKey::RustcCommitDate => RUSTC_COMMIT_DATE,
#[cfg(feature = "rustc")]
VergenKey::RustcCommitHash => RUSTC_COMMIT_HASH,
#[cfg(feature = "rustc")]
VergenKey::RustcHostTriple => RUSTC_HOST_TRIPLE_NAME,
#[cfg(feature = "rustc")]
VergenKey::RustcLlvmVersion => RUSTC_LLVM_VERSION,
#[cfg(feature = "rustc")]
VergenKey::RustcSemver => RUSTC_SEMVER_NAME,
#[cfg(feature = "si")]
VergenKey::SysinfoName => SYSINFO_NAME,
#[cfg(feature = "si")]
VergenKey::SysinfoOsVersion => SYSINFO_OS_VERSION,
#[cfg(feature = "si")]
VergenKey::SysinfoUser => SYSINFO_USER,
#[cfg(feature = "si")]
VergenKey::SysinfoMemory => SYSINFO_MEMORY,
#[cfg(feature = "si")]
VergenKey::SysinfoCpuVendor => SYSINFO_CPU_VENDOR,
#[cfg(feature = "si")]
VergenKey::SysinfoCpuCoreCount => SYSINFO_CPU_CORE_COUNT,
#[cfg(feature = "si")]
VergenKey::SysinfoCpuName => SYSINFO_CPU_NAME,
#[cfg(feature = "si")]
VergenKey::SysinfoCpuBrand => SYSINFO_CPU_BRAND,
#[cfg(feature = "si")]
VergenKey::SysinfoCpuFrequency => SYSINFO_CPU_FREQUENCY,
}
}
}
}
#[cfg(not(any(
feature = "build",
feature = "cargo",
feature = "git",
feature = "rustc",
feature = "si"
)))]
pub(crate) mod vergen_key {
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub enum VergenKey {
Empty,
}
impl VergenKey {
#[must_use]
pub fn name(self) -> &'static str {
match self {
VergenKey::Empty => "",
}
}
}
}
#[cfg(all(
test,
not(any(
feature = "build",
feature = "cargo",
feature = "git",
feature = "rustc",
feature = "si"
))
))]
mod test {
use super::vergen_key::VergenKey;
use anyhow::Result;
use std::{
cmp::Ordering,
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
io::Write,
};
#[test]
fn empty_name() {
assert!(VergenKey::Empty.name().is_empty());
}
#[test]
#[allow(clippy::clone_on_copy, clippy::redundant_clone)]
fn vergen_key_clone_works() {
let key = VergenKey::Empty;
let another = key.clone();
assert_eq!(another, key);
}
#[test]
fn vergen_key_debug_works() -> Result<()> {
let key = VergenKey::Empty;
let mut buf = vec![];
write!(buf, "{key:?}")?;
assert!(!buf.is_empty());
Ok(())
}
#[test]
fn vergen_key_ord_works() {
assert_eq!(VergenKey::Empty.cmp(&VergenKey::Empty), Ordering::Equal);
}
#[test]
fn vergen_key_partial_ord_works() {
assert_eq!(
VergenKey::Empty.partial_cmp(&VergenKey::Empty),
Some(Ordering::Equal)
);
}
#[test]
fn vergen_key_hash_works() {
let mut hasher = DefaultHasher::new();
VergenKey::Empty.hash(&mut hasher);
assert_eq!(15_130_871_412_783_076_140, hasher.finish());
}
}
#[cfg(all(test, all(feature = "build", feature = "cargo")))]
mod test {
use super::vergen_key::VergenKey;
use anyhow::Result;
use std::{
cmp::Ordering,
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
io::Write,
};
#[test]
#[allow(clippy::clone_on_copy, clippy::redundant_clone)]
fn vergen_key_clone_works() {
let key = VergenKey::BuildDate;
let another = key.clone();
assert_eq!(another, key);
}
#[test]
fn vergen_key_debug_works() -> Result<()> {
let key = VergenKey::BuildDate;
let mut buf = vec![];
write!(buf, "{key:?}")?;
assert!(!buf.is_empty());
Ok(())
}
#[test]
fn vergen_key_ord_works() {
assert_eq!(
VergenKey::CargoDebug.cmp(&VergenKey::BuildDate),
Ordering::Greater
);
}
#[test]
fn vergen_key_partial_ord_works() {
assert_eq!(
VergenKey::CargoDebug.partial_cmp(&VergenKey::BuildDate),
Some(Ordering::Greater)
);
}
#[test]
fn vergen_key_hash_works() {
let mut hasher = DefaultHasher::new();
VergenKey::BuildDate.hash(&mut hasher);
assert_eq!(13_646_096_770_106_105_413, hasher.finish());
}
}