From ee5782ff8b7b62ef111f581534976d74e327fd5c Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Fri, 23 Mar 2018 10:28:15 +0000 Subject: [PATCH] Add versioning and build information (#851) * add build-time versioning info * add build-time versioning info --- Cargo.toml | 4 ++++ src/bin/grin.rs | 33 ++++++++++++++++++++++++++++ src/bin/tui/constants.rs | 3 +++ src/bin/tui/menu.rs | 1 + src/bin/tui/mod.rs | 1 + src/bin/tui/ui.rs | 10 ++++++--- src/bin/tui/version.rs | 46 ++++++++++++++++++++++++++++++++++++++++ src/build/build.rs | 29 +++++++++++++++++++++++++ 8 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/bin/tui/version.rs create mode 100644 src/build/build.rs diff --git a/Cargo.toml b/Cargo.toml index 0218a3ae0..c5a4fe200 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Grin Developers "] exclude = ["**/*.grin", "**/*.grin2"] publish = false +build = "src/build/build.rs" [workspace] members = ["api", "chain", "config", "core", "grin", "keychain", "p2p", "store", "util", "pool", "wallet"] @@ -41,3 +42,6 @@ tag="grin_integration_1" # TODO - once "patch" is available we should be able to clean up the workspace dependencies # [patch.crate-io] # secp256k1zkp = { git = "https://github.com/mimblewimble/rust-secp256k1-zkp" } + +[build-dependencies] +built = "^0.2.3" diff --git a/src/bin/grin.rs b/src/bin/grin.rs index e63a0f2d8..3fe25a85c 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -51,6 +51,37 @@ use core::core::amount_to_hr_string; use util::{init_logger, LoggingConfig, LOGGER}; use tui::ui; +// include build information +pub mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +pub fn info_strings() -> (String, String, String) { + ( + format!( + "This is Grin version {}{}, built for {} by {}.", + built_info::PKG_VERSION, + built_info::GIT_VERSION.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)), + built_info::TARGET, + built_info::RUSTC_VERSION + ).to_string(), + format!( + "Built with profile \"{}\", features \"{}\" on {}.", + built_info::PROFILE, + built_info::FEATURES_STR, + built_info::BUILT_TIME_UTC + ).to_string(), + format!("Dependencies:\n {}", built_info::DEPENDENCIES_STR).to_string(), + ) +} + +fn log_build_info() { + let (basic_info, detailed_info, deps) = info_strings(); + info!(LOGGER, "{}", basic_info); + debug!(LOGGER, "{}", detailed_info); + debug!(LOGGER, "{}", deps); +} + /// wrap below to allow UI to clean up on stop fn start_server(config: grin::ServerConfig) { start_server_tui(config); @@ -301,6 +332,8 @@ fn main() { init_logger(Some(LoggingConfig::default())); } + log_build_info(); + match args.subcommand() { // server commands and options ("server", Some(server_args)) => { diff --git a/src/bin/tui/constants.rs b/src/bin/tui/constants.rs index 124f45d9e..f65d26526 100644 --- a/src/bin/tui/constants.rs +++ b/src/bin/tui/constants.rs @@ -28,6 +28,9 @@ pub const SUBMENU_MINING_BUTTON: &str = "mining_submenu_button"; pub const TABLE_MINING_STATUS: &str = "mining_status_table"; pub const TABLE_MINING_DIFF_STATUS: &str = "mining_diff_status_table"; +// Mining View +pub const VIEW_VERSION: &str = "version_view"; + // Menu and root elements pub const MAIN_MENU: &str = "main_menu"; pub const ROOT_STACK: &str = "root_stack"; diff --git a/src/bin/tui/menu.rs b/src/bin/tui/menu.rs index 8c4bb3ca4..084f325db 100644 --- a/src/bin/tui/menu.rs +++ b/src/bin/tui/menu.rs @@ -33,6 +33,7 @@ pub fn create() -> Box { .get_mut() .add_item("Peers and Sync", VIEW_PEER_SYNC); main_menu.get_mut().add_item("Mining", VIEW_MINING); + main_menu.get_mut().add_item("Version Info", VIEW_VERSION); let change_view = |s: &mut Cursive, v: &&str| { if *v == "" { return; diff --git a/src/bin/tui/mod.rs b/src/bin/tui/mod.rs index 421407ccd..27ad011e5 100644 --- a/src/bin/tui/mod.rs +++ b/src/bin/tui/mod.rs @@ -23,4 +23,5 @@ mod constants; mod menu; mod status; mod mining; +mod version; mod types; diff --git a/src/bin/tui/ui.rs b/src/bin/tui/ui.rs index 4e3cdd76b..747ff1849 100644 --- a/src/bin/tui/ui.rs +++ b/src/bin/tui/ui.rs @@ -29,12 +29,13 @@ use cursive::direction::Orientation; use cursive::traits::*; use grin::Server; -//use util::LOGGER; -use tui::{menu, mining, peers, status}; +use tui::{menu, mining, peers, status, version}; use tui::types::*; use tui::constants::*; +use built_info; + pub struct UI { cursive: Cursive, ui_rx: mpsc::Receiver, @@ -69,10 +70,12 @@ impl UI { let status_view = status::TUIStatusView::create(); let mining_view = mining::TUIMiningView::create(); let peer_view = peers::TUIPeerView::create(); + let version_view = version::TUIVersionView::create(); let main_menu = menu::create(); let root_stack = StackView::new() + .layer(version_view) .layer(mining_view) .layer(peer_view) .layer(status_view) @@ -80,7 +83,7 @@ impl UI { let mut title_string = StyledString::new(); title_string.append(StyledString::styled( - "Grin Version 0.0.1", + format!("Grin Version {}", built_info::PKG_VERSION), Color::Dark(BaseColor::Green), )); @@ -123,6 +126,7 @@ impl UI { status::TUIStatusView::update(&mut self.cursive, &update); mining::TUIMiningView::update(&mut self.cursive, &update); peers::TUIPeerView::update(&mut self.cursive, &update); + version::TUIVersionView::update(&mut self.cursive, &update); } } } diff --git a/src/bin/tui/version.rs b/src/bin/tui/version.rs new file mode 100644 index 000000000..ee730173f --- /dev/null +++ b/src/bin/tui/version.rs @@ -0,0 +1,46 @@ +// Copyright 2018 The Grin Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Version and build info + +use cursive::Cursive; +use cursive::view::View; +use cursive::views::{BoxView, LinearLayout, TextView}; +use cursive::direction::Orientation; +use cursive::traits::*; + +use tui::constants::*; +use tui::types::*; + +use grin::ServerStats; +use info_strings; + +pub struct TUIVersionView; + +impl TUIStatusListener for TUIVersionView { + /// Create basic status view + fn create() -> Box { + let (basic_info, detailed_info, _) = info_strings(); + let basic_status_view = BoxView::with_full_screen( + LinearLayout::new(Orientation::Vertical) + .child(TextView::new(basic_info)) + .child(TextView::new(" ")) + .child(TextView::new(detailed_info)), + ); + Box::new(basic_status_view.with_id(VIEW_VERSION)) + } + + /// update + fn update(_c: &mut Cursive, _stats: &ServerStats) {} +} diff --git a/src/build/build.rs b/src/build/build.rs new file mode 100644 index 000000000..cfbbcb974 --- /dev/null +++ b/src/build/build.rs @@ -0,0 +1,29 @@ +// Copyright 2018 The Grin Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Build hooks to spit out version+build time info + +extern crate built; + +use std::env; + +fn main() { + let mut opts = built::Options::default(); + opts.set_dependencies(true); + built::write_built_file_with_opts( + &opts, + env!("CARGO_MANIFEST_DIR"), + format!("{}{}", env::var("OUT_DIR").unwrap(), "/built.rs"), + ).expect("Failed to acquire build-time information"); +}