From 39f49d8d32ba6a4a586dcc3aa353ae9b52017801 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Fri, 12 Jan 2024 18:02:27 +0100 Subject: [PATCH] long_version field added --- plugins/example-plugin/src/lib.rs | 3 ++- plugins/example-storage-plugin/src/lib.rs | 3 ++- plugins/zenoh-plugin-rest/src/lib.rs | 3 ++- plugins/zenoh-plugin-storage-manager/src/lib.rs | 2 ++ .../src/memory_backend/mod.rs | 5 +++-- plugins/zenoh-plugin-trait/src/manager.rs | 3 +++ .../src/manager/dynamic_plugin.rs | 6 +++++- .../src/manager/static_plugin.rs | 3 +++ plugins/zenoh-plugin-trait/src/plugin.rs | 17 +++++++++++++++++ plugins/zenoh-plugin-trait/src/vtable.rs | 7 +++++++ 10 files changed, 46 insertions(+), 6 deletions(-) diff --git a/plugins/example-plugin/src/lib.rs b/plugins/example-plugin/src/lib.rs index 006a854574..c37b45399c 100644 --- a/plugins/example-plugin/src/lib.rs +++ b/plugins/example-plugin/src/lib.rs @@ -25,7 +25,7 @@ use zenoh::plugins::{RunningPluginTrait, ZenohPlugin}; use zenoh::prelude::r#async::*; use zenoh::runtime::Runtime; use zenoh_core::zlock; -use zenoh_plugin_trait::{plugin_version, Plugin, PluginControl}; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; use zenoh_result::{bail, ZResult}; // The struct implementing the ZenohPlugin and ZenohPlugin traits @@ -46,6 +46,7 @@ impl Plugin for ExamplePlugin { // A mandatory const to define, in case of the plugin is built as a standalone executable const DEFAULT_NAME: &'static str = "example"; const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); // The first operation called by zenohd on the plugin fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { diff --git a/plugins/example-storage-plugin/src/lib.rs b/plugins/example-storage-plugin/src/lib.rs index 7757c7f458..2d51e23dfc 100644 --- a/plugins/example-storage-plugin/src/lib.rs +++ b/plugins/example-storage-plugin/src/lib.rs @@ -24,7 +24,7 @@ use zenoh_backend_traits::{ Capability, History, Persistence, Storage, StorageInsertionResult, StoredData, Volume, VolumeInstance, }; -use zenoh_plugin_trait::{plugin_version, Plugin}; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin}; use zenoh_result::ZResult; zenoh_plugin_trait::declare_plugin!(ExampleBackend); @@ -39,6 +39,7 @@ impl Plugin for ExampleBackend { const DEFAULT_NAME: &'static str = "example_backend"; const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); } pub struct ExampleBackend {} diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index 9e70f56add..79425ffd62 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -34,7 +34,7 @@ use zenoh::query::{QueryConsolidation, Reply}; use zenoh::runtime::Runtime; use zenoh::selector::TIME_RANGE_KEY; use zenoh::Session; -use zenoh_plugin_trait::{plugin_version, Plugin, PluginControl}; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; use zenoh_result::{bail, zerror, ZResult}; mod config; @@ -219,6 +219,7 @@ impl Plugin for RestPlugin { type Instance = zenoh::plugins::RunningPlugin; const DEFAULT_NAME: &'static str = "rest"; const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { // Try to initiate login. diff --git a/plugins/zenoh-plugin-storage-manager/src/lib.rs b/plugins/zenoh-plugin-storage-manager/src/lib.rs index 3af9a2887e..139d1d258a 100644 --- a/plugins/zenoh-plugin-storage-manager/src/lib.rs +++ b/plugins/zenoh-plugin-storage-manager/src/lib.rs @@ -37,6 +37,7 @@ use zenoh_backend_traits::config::StorageConfig; use zenoh_backend_traits::config::VolumeConfig; use zenoh_backend_traits::VolumeInstance; use zenoh_core::zlock; +use zenoh_plugin_trait::plugin_long_version; use zenoh_plugin_trait::plugin_version; use zenoh_plugin_trait::Plugin; use zenoh_plugin_trait::PluginControl; @@ -57,6 +58,7 @@ impl ZenohPlugin for StoragesPlugin {} impl Plugin for StoragesPlugin { const DEFAULT_NAME: &'static str = "storage_manager"; const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); type StartArgs = Runtime; type Instance = zenoh::plugins::RunningPlugin; diff --git a/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs b/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs index de6f2eed73..ebb4922c9d 100644 --- a/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs +++ b/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs @@ -19,7 +19,7 @@ use zenoh::prelude::r#async::*; use zenoh::time::Timestamp; use zenoh_backend_traits::config::{StorageConfig, VolumeConfig}; use zenoh_backend_traits::*; -use zenoh_plugin_trait::Plugin; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin}; use zenoh_result::ZResult; use crate::MEMORY_BACKEND_NAME; @@ -33,7 +33,8 @@ impl Plugin for MemoryBackend { type Instance = VolumeInstance; const DEFAULT_NAME: &'static str = MEMORY_BACKEND_NAME; - const PLUGIN_VERSION: &'static str = env!("CARGO_PKG_VERSION"); + const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); fn start(_: &str, args: &VolumeConfig) -> ZResult { Ok(Box::new(MemoryBackend { diff --git a/plugins/zenoh-plugin-trait/src/manager.rs b/plugins/zenoh-plugin-trait/src/manager.rs index ea6b88f671..48988dfe22 100644 --- a/plugins/zenoh-plugin-trait/src/manager.rs +++ b/plugins/zenoh-plugin-trait/src/manager.rs @@ -62,6 +62,9 @@ impl PluginStatus fn version(&self) -> Option<&str> { self.0.version() } + fn long_version(&self) -> Option<&str> { + self.0.long_version() + } fn path(&self) -> &str { self.0.path() } diff --git a/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs b/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs index e4df9ab7ab..3dfd0263fa 100644 --- a/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs +++ b/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs @@ -49,6 +49,7 @@ struct DynamicPluginStarter { _lib: Library, path: PathBuf, plugin_version: &'static str, + plugin_long_version: &'static str, vtable: PluginVTable, } @@ -90,6 +91,7 @@ impl _lib: lib, path, plugin_version: plugin_compatibility_record.plugin_version(), + plugin_long_version: plugin_compatibility_record.plugin_long_version(), vtable, }) } @@ -130,7 +132,9 @@ impl PluginStatus fn version(&self) -> Option<&str> { self.starter.as_ref().map(|v| v.plugin_version) } - + fn long_version(&self) -> Option<&str> { + self.starter.as_ref().map(|v| v.plugin_long_version) + } fn path(&self) -> &str { if let Some(starter) = &self.starter { starter.path() diff --git a/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs b/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs index 46566c1545..a940695538 100644 --- a/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs +++ b/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs @@ -45,6 +45,9 @@ where fn version(&self) -> Option<&str> { Some(P::PLUGIN_VERSION) } + fn long_version(&self) -> Option<&str> { + Some(P::PLUGIN_LONG_VERSION) + } fn path(&self) -> &str { "" } diff --git a/plugins/zenoh-plugin-trait/src/plugin.rs b/plugins/zenoh-plugin-trait/src/plugin.rs index 7efa4c70fa..438f57fb96 100644 --- a/plugins/zenoh-plugin-trait/src/plugin.rs +++ b/plugins/zenoh-plugin-trait/src/plugin.rs @@ -63,6 +63,8 @@ pub trait PluginStatus { fn name(&self) -> &str; /// Returns the version of the loaded plugin (usually the version of the plugin's crate) fn version(&self) -> Option<&str>; + /// Returns the long version of the loaded plugin (usually the version of the plugin's crate + git commit hash) + fn long_version(&self) -> Option<&str>; /// Returns the path of the loaded plugin fn path(&self) -> &str; /// Returns the plugin's state (Declared, Loaded, Started) @@ -78,6 +80,7 @@ pub struct PluginStatusRec<'a> { pub name: Cow<'a, str>, #[serde(skip_serializing_if = "Option::is_none")] pub version: Option>, + pub long_version: Option>, pub path: Cow<'a, str>, pub state: PluginState, pub report: PluginReport, @@ -90,6 +93,9 @@ impl PluginStatus for PluginStatusRec<'_> { fn version(&self) -> Option<&str> { self.version.as_deref() } + fn long_version(&self) -> Option<&str> { + self.long_version.as_deref() + } fn path(&self) -> &str { &self.path } @@ -107,6 +113,7 @@ impl<'a> PluginStatusRec<'a> { Self { name: Cow::Borrowed(plugin.name()), version: plugin.version().map(Cow::Borrowed), + long_version: plugin.long_version().map(Cow::Borrowed), path: Cow::Borrowed(plugin.path()), state: plugin.state(), report: plugin.report(), @@ -117,6 +124,7 @@ impl<'a> PluginStatusRec<'a> { PluginStatusRec { name: Cow::Owned(self.name.into_owned()), version: self.version.map(|v| Cow::Owned(v.into_owned())), + long_version: self.long_version.map(|v| Cow::Owned(v.into_owned())), path: Cow::Owned(self.path.into_owned()), state: self.state, report: self.report, @@ -166,12 +174,21 @@ pub trait Plugin: Sized + 'static { const DEFAULT_NAME: &'static str; /// Plugin's version. Used only for information purposes. It's recommended to use [plugin_version!] macro to generate this string. const PLUGIN_VERSION: &'static str; + /// Plugin's long version (with git commit hash). Used only for information purposes. It's recommended to use [plugin_long_version!] macro to generate this string. + const PLUGIN_LONG_VERSION: &'static str; /// Starts your plugin. Use `Ok` to return your plugin's control structure fn start(name: &str, args: &Self::StartArgs) -> ZResult; } #[macro_export] macro_rules! plugin_version { + () => { + env!("CARGO_PKG_VERSION") + }; +} + +#[macro_export] +macro_rules! plugin_long_version { () => { git_version::git_version!(prefix = "v", cargo_prefix = "v") }; diff --git a/plugins/zenoh-plugin-trait/src/vtable.rs b/plugins/zenoh-plugin-trait/src/vtable.rs index d4e51a3ade..6abdbf145d 100644 --- a/plugins/zenoh-plugin-trait/src/vtable.rs +++ b/plugins/zenoh-plugin-trait/src/vtable.rs @@ -69,6 +69,7 @@ pub struct Compatibility { start_args_version: StructVersion, instance_version: StructVersion, plugin_version: &'static str, + plugin_long_version: &'static str, } impl Compatibility { @@ -82,12 +83,14 @@ impl Compatibility { let start_args_version = StructVersion::new::(); let instance_version = StructVersion::new::(); let plugin_version = PluginType::PLUGIN_VERSION; + let plugin_long_version = PluginType::PLUGIN_LONG_VERSION; Self { rust_version, vtable_version, start_args_version, instance_version, plugin_version, + plugin_long_version, } } pub fn with_empty_plugin_version< @@ -104,11 +107,15 @@ impl Compatibility { start_args_version, instance_version, plugin_version: "", + plugin_long_version: "", } } pub fn plugin_version(&self) -> &'static str { self.plugin_version } + pub fn plugin_long_version(&self) -> &'static str { + self.plugin_long_version + } /// Returns true if rust compiler and structures version are exactly the same and /// plugin version is compatible with the requested version range in the configuration file pub fn are_compatible(&self, other: &Self) -> bool {