From 45ace8218fb0cc93d1261d51319d0f6817a76993 Mon Sep 17 00:00:00 2001 From: Russel Waters Date: Tue, 30 Jul 2019 13:53:44 -0400 Subject: [PATCH] add git commit hash and compiler info to logging and version calls (#2170) * add build info to version calls * use Boost defines to gather Compiler info as well as bash version New build_info example ```Version 20.0 Build Info 3d66a9a9 "Clang version " "10.0.1 (clang-1001.0.46.4)" "BOOST 107000" BUILT "Jul 23 2019"``` * prevent multiple flushes --- CMakeLists.txt | 11 ++++++++++- nano/core_test/CMakeLists.txt | 1 + nano/lib/config.hpp | 3 +++ nano/nano_node/CMakeLists.txt | 1 + nano/nano_node/daemon.cpp | 5 +++-- nano/nano_node/entry.cpp | 1 + nano/nano_rpc/CMakeLists.txt | 3 ++- nano/nano_rpc/entry.cpp | 1 + nano/node/CMakeLists.txt | 3 ++- nano/node/json_handler.cpp | 1 + nano/node/node.cpp | 1 + nano/rpc_test/CMakeLists.txt | 3 ++- nano/rpc_test/rpc.cpp | 1 + 13 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4abda7ce..c87c4b45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,14 @@ cmake_minimum_required (VERSION 3.4) project (nano-node) +# Get the latest abbreviated commit hash of the working branch +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + set (CPACK_PACKAGE_VERSION_MAJOR "20") set (CPACK_PACKAGE_VERSION_MINOR "0") set (CPACK_PACKAGE_VERSION_PATCH "0") @@ -351,7 +359,8 @@ if (NANO_GUI OR RAIBLOCKS_GUI) PRIVATE -DNANO_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DNANO_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} - -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}) + -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH} + -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) if (WIN32) set (PLATFORM_GUI_TARGET_PROPERTIES WIN32) diff --git a/nano/core_test/CMakeLists.txt b/nano/core_test/CMakeLists.txt index f0eaf92c..c3cec9eb 100644 --- a/nano/core_test/CMakeLists.txt +++ b/nano/core_test/CMakeLists.txt @@ -39,5 +39,6 @@ target_compile_definitions(core_test -DNANO_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DNANO_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH} + -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH} -DBOOST_PROCESS_SUPPORTED=${BOOST_PROCESS_SUPPORTED}) target_link_libraries (core_test node secure gtest libminiupnpc-static Boost::boost ${rocksdb_libs}) diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index 7c5d6364..9fc23d93 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -17,6 +17,9 @@ */ static const char * NANO_MAJOR_MINOR_VERSION = xstr (NANO_VERSION_MAJOR) "." xstr (NANO_VERSION_MINOR); static const char * NANO_MAJOR_MINOR_RC_VERSION = xstr (NANO_VERSION_MAJOR) "." xstr (NANO_VERSION_MINOR) "RC" xstr (NANO_VERSION_PATCH); + +static const char * BUILD_INFO = xstr (GIT_COMMIT_HASH BOOST_COMPILER) " \"BOOST " xstr (BOOST_VERSION) "\" BUILT " xstr (__DATE__); + /** Is TSAN/ASAN test build */ #if defined(__has_feature) #if __has_feature(thread_sanitizer) || __has_feature(address_sanitizer) diff --git a/nano/nano_node/CMakeLists.txt b/nano/nano_node/CMakeLists.txt index 3d102947..9111e1e0 100644 --- a/nano/nano_node/CMakeLists.txt +++ b/nano/nano_node/CMakeLists.txt @@ -17,6 +17,7 @@ target_compile_definitions(nano_node -DNANO_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DNANO_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH} + -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH} -DBOOST_PROCESS_SUPPORTED=${BOOST_PROCESS_SUPPORTED}) set_target_properties (nano_node diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 12e5138c..7c1df1e1 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -62,8 +62,9 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano:: { auto network_label = node->network_params.network.get_current_network_as_string (); auto version = (NANO_VERSION_PATCH == 0) ? NANO_MAJOR_MINOR_VERSION : NANO_MAJOR_MINOR_RC_VERSION; - std::cout << "Network: " << network_label << ", version: " << version << std::endl - << "Path: " << node->application_path.string () << std::endl; + std::cout << "Network: " << network_label << ", version: " << version << "\n" + << "Path: " << node->application_path.string () << "\n" + << "Build Info: " << BUILD_INFO << std::endl; node->start (); nano::ipc::ipc_server ipc_server (*node, config.rpc); diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index c47942b5..fe74d3e8 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1064,6 +1064,7 @@ int main (int argc, char * const * argv) { std::cout << "Version " << NANO_MAJOR_MINOR_RC_VERSION << std::endl; } + std::cout << "Build Info " << BUILD_INFO << std::endl; } else { diff --git a/nano/nano_rpc/CMakeLists.txt b/nano/nano_rpc/CMakeLists.txt index ee222c63..7069d413 100644 --- a/nano/nano_rpc/CMakeLists.txt +++ b/nano/nano_rpc/CMakeLists.txt @@ -18,7 +18,8 @@ target_compile_definitions(nano_rpc PRIVATE -DNANO_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DNANO_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} - -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}) + -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH} + -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) if ((NANO_GUI OR RAIBLOCKS_GUI) AND NOT APPLE) install(TARGETS nano_rpc diff --git a/nano/nano_rpc/entry.cpp b/nano/nano_rpc/entry.cpp index 01ca5e4a..2b126804 100644 --- a/nano/nano_rpc/entry.cpp +++ b/nano/nano_rpc/entry.cpp @@ -148,6 +148,7 @@ int main (int argc, char * const * argv) { std::cout << "Version " << NANO_MAJOR_MINOR_RC_VERSION << std::endl; } + std::cout << "Build Info " << BUILD_INFO << std::endl; } else { diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 4883929b..cd378233 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -131,4 +131,5 @@ target_compile_definitions(node PRIVATE -DNANO_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DNANO_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} - -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}) + -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH} + -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 0c8c57d0..678723fa 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3771,6 +3771,7 @@ void nano::json_handler::version () { response_l.put ("node_vendor", boost::str (boost::format ("Nano %1%") % NANO_MAJOR_MINOR_RC_VERSION)); } + response_l.put ("build_info", BUILD_INFO); response_errors (); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 1581b03d..d9431cdc 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -367,6 +367,7 @@ startup_time (std::chrono::steady_clock::now ()) { logger.always_log ("Node starting, version: ", NANO_MAJOR_MINOR_RC_VERSION); } + logger.always_log ("Build information: ", BUILD_INFO); auto network_label = network_params.network.get_current_network_as_string (); logger.always_log ("Active network: ", network_label); diff --git a/nano/rpc_test/CMakeLists.txt b/nano/rpc_test/CMakeLists.txt index 3c99ffd8..a99849eb 100644 --- a/nano/rpc_test/CMakeLists.txt +++ b/nano/rpc_test/CMakeLists.txt @@ -10,4 +10,5 @@ target_compile_definitions(rpc_test PRIVATE -DNANO_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DNANO_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} - -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}) \ No newline at end of file + -DNANO_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH} + -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) \ No newline at end of file diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 9157c32e..811f2e98 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -2416,6 +2416,7 @@ TEST (rpc, version) { ASSERT_EQ (boost::str (boost::format ("Nano %1%") % NANO_MAJOR_MINOR_RC_VERSION), response1.json.get ("node_vendor")); } + ASSERT_EQ (BUILD_INFO, response1.json.get ("build_info")); auto headers (response1.resp.base ()); auto allow (headers.at ("Allow")); auto content_type (headers.at ("Content-Type"));