mod r#type;
pub use r#type::*;
pub static VERSION_INFO: VersionInfo = include!(env!("LINERA_VERSION_STATIC_PATH"));
use crate::serde_pretty::Pretty;
impl std::fmt::Display for VersionInfo {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
formatter,
"\
Linera protocol: v{crate_version}\n\
RPC API hash: {rpc_hash}\n\
GraphQL API hash: {graphql_hash}\n\
WIT API hash: {wit_hash}\n\
Source code: {repo}/tree/{git_commit}{git_dirty}\n\
",
repo = env!("CARGO_PKG_REPOSITORY"),
crate_version = self.crate_version,
rpc_hash = self.rpc_hash,
graphql_hash = self.graphql_hash,
wit_hash = self.wit_hash,
git_commit = self.git_commit,
git_dirty = if self.git_dirty { " (dirty)" } else { "" }
)
}
}
impl CrateVersion {
pub fn is_compatible_with(&self, other: &CrateVersion) -> bool {
if self.major == 0 {
self.minor == other.minor && self.patch <= other.patch
} else {
self.major == other.major && self.minor <= other.minor
}
}
}
async_graphql::scalar!(
CrateVersion,
"CrateVersion",
"The version of the Linera crates used in this build"
);
async_graphql::scalar!(
Pretty<CrateVersion, semver::Version>,
"CrateVersion",
"The version of the Linera crates used in this build"
);
impl VersionInfo {
pub fn log(&self) {
for line in format!("{self}").lines() {
tracing::info!("{line}");
}
}
pub fn default_clap_str() -> &'static str {
use std::sync::LazyLock;
static STRING: LazyLock<String> = LazyLock::new(|| format!("\n{}", VersionInfo::default()));
STRING.as_str()
}
pub fn is_compatible_with(&self, other: &VersionInfo) -> bool {
self.api_hashes() == other.api_hashes()
|| self
.crate_version
.value
.is_compatible_with(&other.crate_version.value)
}
}
impl Default for VersionInfo {
fn default() -> Self {
VERSION_INFO.clone()
}
}