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