linera_version/version_info/
mod.rs1mod r#type;
5pub use r#type::*;
6
7pub static VERSION_INFO: VersionInfo = include!(env!("LINERA_VERSION_STATIC_PATH"));
9
10use crate::serde_pretty::Pretty;
11
12impl std::fmt::Display for VersionInfo {
13 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
14 write!(
15 formatter,
16 "\
17 Linera protocol: v{crate_version}\n\
18 RPC API hash: {rpc_hash}\n\
19 GraphQL API hash: {graphql_hash}\n\
20 WIT API hash: {wit_hash}\n\
21 Source code: {repo}/tree/{git_commit}{git_dirty}\n\
22 ",
23 repo = env!("CARGO_PKG_REPOSITORY"),
24 crate_version = self.crate_version,
25 rpc_hash = self.rpc_hash,
26 graphql_hash = self.graphql_hash,
27 wit_hash = self.wit_hash,
28 git_commit = self.git_commit,
29 git_dirty = if self.git_dirty { " (dirty)" } else { "" }
30 )
31 }
32}
33
34impl CrateVersion {
35 pub fn is_compatible_with(&self, other: &CrateVersion) -> bool {
38 if self.major == 0 {
39 self.minor == other.minor && self.patch <= other.patch
43 } else {
44 self.major == other.major && self.minor <= other.minor
45 }
46 }
47}
48
49async_graphql::scalar!(
50 CrateVersion,
51 "CrateVersion",
52 "The version of the Linera crates used in this build"
53);
54
55async_graphql::scalar!(
56 Pretty<CrateVersion, semver::Version>,
57 "CrateVersion",
58 "The version of the Linera crates used in this build"
59);
60
61impl VersionInfo {
62 pub fn log(&self) {
64 for line in format!("{self}").lines() {
65 tracing::info!("{line}");
66 }
67 }
68
69 pub fn default_clap_str() -> &'static str {
73 use std::sync::LazyLock;
74 static STRING: LazyLock<String> = LazyLock::new(|| format!("\n{}", VersionInfo::default()));
75 STRING.as_str()
76 }
77
78 pub fn is_compatible_with(&self, other: &VersionInfo) -> bool {
82 self.api_hashes() == other.api_hashes()
83 || self
84 .crate_version
85 .value
86 .is_compatible_with(&other.crate_version.value)
87 }
88}
89
90impl Default for VersionInfo {
91 fn default() -> Self {
92 VERSION_INFO.clone()
93 }
94}