diff --git a/CMakeLists.txt b/CMakeLists.txt index cb0dd1e3..a97a9c96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,15 @@ project(TON VERSION 0.5 LANGUAGES C CXX) set(CMAKE_POSITION_INDEPENDENT_CODE ON) #set(OPENSSL_USE_STATIC_LIBS TRUE) -ADD_DEFINITIONS( -DBUILD_VERSION=\"3.0.0\" ) +# Define the two required variables before including the source code for watching a git repository. +set(PRE_CONFIGURE_FILE "git.cc.in") +set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/git.cc") +include(git_watcher.cmake) + +# Create a library out of the compiled post-configure file. +add_library(git STATIC ${POST_CONFIGURE_FILE}) +target_include_directories(git PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +add_dependencies(git check_git) # Prevent in-source build get_filename_component(TON_REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) diff --git a/adnl/CMakeLists.txt b/adnl/CMakeLists.txt index 7bb3bdc5..954db27b 100644 --- a/adnl/CMakeLists.txt +++ b/adnl/CMakeLists.txt @@ -89,12 +89,12 @@ target_link_libraries(adnl PUBLIC tdactor ton_crypto tl_api tdnet tddb keys keyr add_executable(adnl-proxy ${ADNL_PROXY_SOURCE}) target_include_directories(adnl-proxy PUBLIC $) target_link_libraries(adnl-proxy PUBLIC tdactor ton_crypto tl_api tdnet common - tl-utils) + tl-utils git) add_executable(adnl-pong adnl-pong.cpp) target_include_directories(adnl-pong PUBLIC $) target_link_libraries(adnl-pong PUBLIC tdactor ton_crypto tl_api tdnet common - tl-utils adnl dht) + tl-utils adnl dht git) add_library(adnltest STATIC ${ADNL_TEST_SOURCE}) target_include_directories(adnltest PUBLIC $) @@ -105,4 +105,4 @@ endif() add_library(adnllite STATIC ${ADNL_LITE_SOURCE}) target_include_directories(adnllite PUBLIC $) -target_link_libraries(adnllite PUBLIC tdactor ton_crypto tl_lite_api tdnet keys ) +target_link_libraries(adnllite PUBLIC tdactor ton_crypto tl_lite_api tdnet keys) diff --git a/adnl/adnl-pong.cpp b/adnl/adnl-pong.cpp index d9e869df..434f0ef7 100644 --- a/adnl/adnl-pong.cpp +++ b/adnl/adnl-pong.cpp @@ -41,6 +41,7 @@ #include "auto/tl/ton_api_json.h" #include "adnl/adnl.h" #include +#include "git.h" #if TD_DARWIN || TD_LINUX #include @@ -97,8 +98,8 @@ int main(int argc, char *argv[]) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); }); - p.add_option('V', "version", "shows adnl-pong build version", [&]() { - std::cout << "adnl-pong build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows adnl-pong build information", [&]() { + std::cout << "adnl-pong build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints_help", [&]() { diff --git a/adnl/adnl-proxy.cpp b/adnl/adnl-proxy.cpp index e2d1129f..10171e0c 100644 --- a/adnl/adnl-proxy.cpp +++ b/adnl/adnl-proxy.cpp @@ -43,6 +43,7 @@ #include "adnl-proxy-types.h" #include "adnl-received-mask.h" #include +#include "git.h" #if TD_DARWIN || TD_LINUX #include @@ -303,8 +304,8 @@ int main(int argc, char *argv[]) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); }); - p.add_option('V', "version", "shows adnl-proxy build version", [&]() { - std::cout << "adnl-proxy build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows adnl-proxy build information", [&]() { + std::cout << "adnl-proxy build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints_help", [&]() { diff --git a/create-hardfork/CMakeLists.txt b/create-hardfork/CMakeLists.txt index 41606829..3d78c118 100644 --- a/create-hardfork/CMakeLists.txt +++ b/create-hardfork/CMakeLists.txt @@ -12,6 +12,6 @@ set(CREATE_HARDFORK_SOURCE add_executable(create-hardfork ${CREATE_HARDFORK_SOURCE}) target_link_libraries(create-hardfork overlay tdutils tdactor adnl tl_api dht rldp catchain validatorsession full-node validator-hardfork ton_validator - validator-hardfork fift-lib memprof ${JEMALLOC_LIBRARIES}) + validator-hardfork fift-lib memprof git ${JEMALLOC_LIBRARIES}) install(TARGETS create-hardfork RUNTIME DESTINATION bin) diff --git a/create-hardfork/create-hardfork.cpp b/create-hardfork/create-hardfork.cpp index e24c47af..a0f7b110 100644 --- a/create-hardfork/create-hardfork.cpp +++ b/create-hardfork/create-hardfork.cpp @@ -55,6 +55,7 @@ #endif #include #include +#include "git.h" int verbosity; @@ -263,8 +264,8 @@ int main(int argc, char *argv[]) { std::cout << sb.as_cslice().c_str(); std::exit(2); }); - p.add_option('V', "version", "shows create-hardfork build version", [&]() { - std::cout << "create-hardfork build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows create-hardfork build information", [&]() { + std::cout << "create-hardfork build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('D', "db", "root for dbs", diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 46a21024..79406ffc 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -284,7 +284,7 @@ target_link_libraries(fift-lib PUBLIC ton_crypto ton_db tdutils ton_block) set_target_properties(fift-lib PROPERTIES OUTPUT_NAME fift) add_executable(fift fift/fift-main.cpp) -target_link_libraries(fift PUBLIC fift-lib) +target_link_libraries(fift PUBLIC fift-lib git) if (WINGETOPT_FOUND) target_link_libraries_system(fift wingetopt) endif() @@ -295,7 +295,7 @@ target_link_libraries(src_parser PUBLIC ton_crypto) add_executable(func func/func.cpp ${FUNC_LIB_SOURCE}) target_include_directories(func PUBLIC $) -target_link_libraries(func PUBLIC ton_crypto src_parser) +target_link_libraries(func PUBLIC ton_crypto src_parser git) if (WINGETOPT_FOUND) target_link_libraries_system(func wingetopt) endif() @@ -312,10 +312,11 @@ target_include_directories(pow-miner-lib PUBLIC $ $) if (INTERNAL_COMPILE) - target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib) + target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib git) else() if (TONLIB_COMPILE) - target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib) + target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib git) else() - target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block) + target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block git) endif() endif() if (WINGETOPT_FOUND) @@ -419,7 +420,7 @@ endif() add_executable(dump-block block/dump-block.cpp) target_include_directories(dump-block PUBLIC $ $) -target_link_libraries(dump-block PUBLIC ton_crypto fift-lib ton_block) +target_link_libraries(dump-block PUBLIC ton_crypto fift-lib ton_block git) if (WINGETOPT_FOUND) target_link_libraries_system(dump-block wingetopt) endif() @@ -427,15 +428,16 @@ endif() add_executable(adjust-block block/adjust-block.cpp) target_include_directories(adjust-block PUBLIC $ $) -target_link_libraries(adjust-block PUBLIC ton_crypto fift-lib ton_block) +target_link_libraries(adjust-block PUBLIC ton_crypto fift-lib ton_block git) if (WINGETOPT_FOUND) target_link_libraries_system(dump-block wingetopt) + target_link_libraries_system(adjust-block wingetopt) endif() add_executable(test-weight-distr block/test-weight-distr.cpp) target_include_directories(test-weight-distr PUBLIC $ $) -target_link_libraries(test-weight-distr PUBLIC ton_crypto fift-lib ton_block) +target_link_libraries(test-weight-distr PUBLIC ton_crypto fift-lib ton_block git) if (WINGETOPT_FOUND) target_link_libraries_system(test-weight-distr wingetopt) endif() diff --git a/crypto/block/adjust-block.cpp b/crypto/block/adjust-block.cpp index 755d4218..16c77691 100644 --- a/crypto/block/adjust-block.cpp +++ b/crypto/block/adjust-block.cpp @@ -34,6 +34,7 @@ #include "vm/cp0.h" #include "td/utils/crypto.h" #include +#include "git.h" using td::Ref; using namespace std::literals::string_literals; @@ -144,7 +145,7 @@ int main(int argc, char* const argv[]) { int i, vseqno_incr = 1; int new_verbosity_level = VERBOSITY_NAME(INFO); std::string in_fname, out_fname; - while ((i = getopt(argc, argv, "hi:v:")) != -1) { + while ((i = getopt(argc, argv, "hi:v:V")) != -1) { switch (i) { case 'h': usage(); @@ -156,6 +157,10 @@ int main(int argc, char* const argv[]) { case 'v': new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer(td::Slice(optarg))); break; + case 'V': + std::cout << "adjust-block build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; + std::exit(0); + break; default: usage(); break; diff --git a/crypto/block/create-state.cpp b/crypto/block/create-state.cpp index aee67600..7a734c3a 100644 --- a/crypto/block/create-state.cpp +++ b/crypto/block/create-state.cpp @@ -59,6 +59,7 @@ #include "block-parse.h" #include "block-auto.h" #include "mc-config.h" +#include "git.h" #if defined(_INTERNAL_COMPILE) || defined(_TONLIB_COMPILE) #define WITH_TONLIB @@ -805,7 +806,7 @@ void usage(const char* progname) { "$FIFTPATH is used instead.\n" "\t-L\tPre-loads a library source file\n" "\t-v\tSet verbosity level\n" - "\t-V\tShow create-state build version\n"; + "\t-V\tShow create-state build information\n"; std::exit(2); } @@ -865,8 +866,8 @@ int main(int argc, char* const argv[]) { case 'v': new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer(td::Slice(optarg))); break; - case 'V': - std::cout << "create-state build version: [" << BUILD_VERSION << "]\n"; + case 'V': + std::cout << "create-state build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); break; case 'h': diff --git a/crypto/block/dump-block.cpp b/crypto/block/dump-block.cpp index 4a17c129..e7a19677 100644 --- a/crypto/block/dump-block.cpp +++ b/crypto/block/dump-block.cpp @@ -34,6 +34,7 @@ #include "mc-config.h" #include "vm/cp0.h" #include +#include "git.h" using td::Ref; using namespace std::literals::string_literals; @@ -247,7 +248,7 @@ void usage() { std::cout << "usage: dump-block [-t][-S][]\n\tor dump-block -h\n\tDumps specified blockchain " "block or state " "from , or runs some tests\n\t-S\tDump a blockchain state instead of a block\n" - "\t-V\tShow fift build version\n"; + "\t-V\tShow fift build information\n"; std::exit(2); } @@ -282,7 +283,7 @@ int main(int argc, char* const argv[]) { dump = 0; break; case 'V': - std::cout << "dump-block build version: [" << BUILD_VERSION << "]\n"; + std::cout << "dump-block build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); break; case 'h': diff --git a/crypto/fift/fift-main.cpp b/crypto/fift/fift-main.cpp index 6952b4b7..ef833f43 100644 --- a/crypto/fift/fift-main.cpp +++ b/crypto/fift/fift-main.cpp @@ -53,6 +53,8 @@ #include "td/utils/Parser.h" #include "td/utils/port/path.h" +#include "git.h" + void usage(const char* progname) { std::cerr << "A simple Fift interpreter. Type `bye` to quit, or `words` to get a list of all commands\n"; std::cerr @@ -66,7 +68,7 @@ void usage(const char* progname) { "\t-d\tUse a ton database\n" "\t-s\tScript mode: use first argument as a fift source file and import remaining arguments as $n)\n" "\t-v\tSet verbosity level\n" - "\t-V\tShow fift build version\n"; + "\t-V\tShow fift build information\n"; std::exit(2); } @@ -118,7 +120,7 @@ int main(int argc, char* const argv[]) { new_verbosity_level = VERBOSITY_NAME(FATAL) + td::to_integer(td::Slice(optarg)); break; case 'V': - std::cout << "Fift build version: [" << BUILD_VERSION << "]\n"; + std::cout << "Fift build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); break; diff --git a/crypto/func/func.cpp b/crypto/func/func.cpp index 6abd8755..e8e09961 100644 --- a/crypto/func/func.cpp +++ b/crypto/func/func.cpp @@ -31,6 +31,7 @@ #include "parser/symtable.h" #include #include +#include "git.h" namespace funC { @@ -172,7 +173,7 @@ void usage(const char* progname) { "-R\tInclude operation rewrite comments in the output code\n" "-W\tInclude Fift code to serialize and save generated code into specified BoC file. Enables " "-A and -P.\n" - "\t-V\tShow func build version\n"; + "\t-V\tShow func build information\n"; std::exit(2); } @@ -215,7 +216,7 @@ int main(int argc, char* const argv[]) { funC::asm_preamble = funC::program_envelope = true; break; case 'V': - std::cout << "Func build version: [" << BUILD_VERSION << "]\n"; + std::cout << "Func build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); break; case 'h': diff --git a/crypto/util/pow-miner.cpp b/crypto/util/pow-miner.cpp index ca01f525..7d4462cf 100644 --- a/crypto/util/pow-miner.cpp +++ b/crypto/util/pow-miner.cpp @@ -37,7 +37,7 @@ #include #include #include - +#include "git.h" #include "Miner.h" const char* progname; @@ -46,7 +46,7 @@ int usage() { std::cerr << "usage: " << progname << " [-v][-B][-w] [-t] [ " - "]\n" + "] [-V]\n" "Outputs a valid value for proof-of-work testgiver after computing at most hashes " "or terminates with non-zero exit code\n"; std::exit(2); @@ -156,7 +156,7 @@ int main(int argc, char* const argv[]) { progname = argv[0]; int i, threads = 0; bool bounce = false, benchmark = false; - while ((i = getopt(argc, argv, "bnvw:t:Bh")) != -1) { + while ((i = getopt(argc, argv, "bnvw:t:Bh:V")) != -1) { switch (i) { case 'v': ++verbosity; @@ -180,6 +180,10 @@ int main(int argc, char* const argv[]) { case 'n': bounce = false; break; + case 'V': + std::cout << "pow-miner build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; + std::exit(0); + break; case 'h': return usage(); default: diff --git a/dht-server/CMakeLists.txt b/dht-server/CMakeLists.txt index a9866921..889b3f30 100644 --- a/dht-server/CMakeLists.txt +++ b/dht-server/CMakeLists.txt @@ -11,6 +11,6 @@ set (DHT_SERVER_SOURCE ) add_executable (dht-server ${DHT_SERVER_SOURCE}) -target_link_libraries(dht-server tdutils tdactor adnl tl_api dht memprof ${JEMALLOC_LIBRARIES}) +target_link_libraries(dht-server tdutils tdactor adnl tl_api dht memprof git ${JEMALLOC_LIBRARIES}) install(TARGETS dht-server RUNTIME DESTINATION bin) diff --git a/dht-server/dht-server.cpp b/dht-server/dht-server.cpp index 827ddff5..212a6fae 100644 --- a/dht-server/dht-server.cpp +++ b/dht-server/dht-server.cpp @@ -48,6 +48,7 @@ #include #include #include +#include "git.h" Config::Config() { out_port = 3278; @@ -1182,8 +1183,8 @@ int main(int argc, char *argv[]) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); }); - p.add_option('V', "version", "shows dht-server build version", [&]() { - std::cout << "dht-server build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows dht-server build information", [&]() { + std::cout << "dht-server build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints_help", [&]() { diff --git a/git.cc.in b/git.cc.in new file mode 100644 index 00000000..9c9c8c56 --- /dev/null +++ b/git.cc.in @@ -0,0 +1,29 @@ +#include "git.h" + +bool GitMetadata::Populated() { + return @GIT_RETRIEVED_STATE@; +} +bool GitMetadata::AnyUncommittedChanges() { + return @GIT_IS_DIRTY@; +} +std::string GitMetadata::AuthorName() { + return "@GIT_AUTHOR_NAME@"; +} +std::string GitMetadata::AuthorEmail() { + return "@GIT_AUTHOR_EMAIL@"; +} +std::string GitMetadata::CommitSHA1() { + return "@GIT_HEAD_SHA1@"; +} +std::string GitMetadata::CommitDate() { + return "@GIT_COMMIT_DATE_ISO8601@"; +} +std::string GitMetadata::CommitSubject() { + return "@GIT_COMMIT_SUBJECT@"; +} +std::string GitMetadata::CommitBody() { + return @GIT_COMMIT_BODY@; +} +std::string GitMetadata::Describe() { + return "@GIT_DESCRIBE@"; +} diff --git a/git.h b/git.h new file mode 100644 index 00000000..b79c8bce --- /dev/null +++ b/git.h @@ -0,0 +1,29 @@ +#pragma once +#include + +class GitMetadata { +public: + // Is the metadata populated? We may not have metadata if + // there wasn't a .git directory (e.g. downloaded source + // code without revision history). + static bool Populated(); + + // Were there any uncommitted changes that won't be reflected + // in the CommitID? + static bool AnyUncommittedChanges(); + + // The commit author's name. + static std::string AuthorName(); + // The commit author's email. + static std::string AuthorEmail(); + // The commit SHA1. + static std::string CommitSHA1(); + // The ISO8601 commit date. + static std::string CommitDate(); + // The commit subject. + static std::string CommitSubject(); + // The commit body. + static std::string CommitBody(); + // The commit describe. + static std::string Describe(); +}; diff --git a/git_watcher.cmake b/git_watcher.cmake new file mode 100644 index 00000000..ab135e80 --- /dev/null +++ b/git_watcher.cmake @@ -0,0 +1,314 @@ +# git_watcher.cmake +# https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/git_watcher.cmake +# +# Released under the MIT License. +# https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/LICENSE + + +# This file defines a target that monitors the state of a git repo. +# If the state changes (e.g. a commit is made), then a file gets reconfigured. +# Here are the primary variables that control script behavior: +# +# PRE_CONFIGURE_FILE (REQUIRED) +# -- The path to the file that'll be configured. +# +# POST_CONFIGURE_FILE (REQUIRED) +# -- The path to the configured PRE_CONFIGURE_FILE. +# +# GIT_STATE_FILE (OPTIONAL) +# -- The path to the file used to store the previous build's git state. +# Defaults to the current binary directory. +# +# GIT_WORKING_DIR (OPTIONAL) +# -- The directory from which git commands will be run. +# Defaults to the directory with the top level CMakeLists.txt. +# +# GIT_EXECUTABLE (OPTIONAL) +# -- The path to the git executable. It'll automatically be set if the +# user doesn't supply a path. +# +# DESIGN +# - This script was designed similar to a Python application +# with a Main() function. I wanted to keep it compact to +# simplify "copy + paste" usage. +# +# - This script is invoked under two CMake contexts: +# 1. Configure time (when build files are created). +# 2. Build time (called via CMake -P). +# The first invocation is what registers the script to +# be executed at build time. +# +# MODIFICATIONS +# You may wish to track other git properties like when the last +# commit was made. There are two sections you need to modify, +# and they're tagged with a ">>>" header. + +# Short hand for converting paths to absolute. +macro(PATH_TO_ABSOLUTE var_name) + get_filename_component(${var_name} "${${var_name}}" ABSOLUTE) +endmacro() + +# Check that a required variable is set. +macro(CHECK_REQUIRED_VARIABLE var_name) + if(NOT DEFINED ${var_name}) + message(FATAL_ERROR "The \"${var_name}\" variable must be defined.") + endif() + PATH_TO_ABSOLUTE(${var_name}) +endmacro() + +# Check that an optional variable is set, or, set it to a default value. +macro(CHECK_OPTIONAL_VARIABLE var_name default_value) + if(NOT DEFINED ${var_name}) + set(${var_name} ${default_value}) + endif() + PATH_TO_ABSOLUTE(${var_name}) +endmacro() + +CHECK_REQUIRED_VARIABLE(PRE_CONFIGURE_FILE) +CHECK_REQUIRED_VARIABLE(POST_CONFIGURE_FILE) +CHECK_OPTIONAL_VARIABLE(GIT_STATE_FILE "${CMAKE_BINARY_DIR}/git-state-hash") +CHECK_OPTIONAL_VARIABLE(GIT_WORKING_DIR "${CMAKE_SOURCE_DIR}") + +# Check the optional git variable. +# If it's not set, we'll try to find it using the CMake packaging system. +if(NOT DEFINED GIT_EXECUTABLE) + find_package(Git QUIET REQUIRED) +endif() +CHECK_REQUIRED_VARIABLE(GIT_EXECUTABLE) + + +set(_state_variable_names + GIT_RETRIEVED_STATE + GIT_HEAD_SHA1 + GIT_IS_DIRTY + GIT_AUTHOR_NAME + GIT_AUTHOR_EMAIL + GIT_COMMIT_DATE_ISO8601 + GIT_COMMIT_SUBJECT + GIT_COMMIT_BODY + GIT_DESCRIBE + # >>> + # 1. Add the name of the additional git variable you're interested in monitoring + # to this list. +) + + + +# Macro: RunGitCommand +# Description: short-hand macro for calling a git function. Outputs are the +# "exit_code" and "output" variables. +macro(RunGitCommand) + execute_process(COMMAND + "${GIT_EXECUTABLE}" ${ARGV} + WORKING_DIRECTORY "${_working_dir}" + RESULT_VARIABLE exit_code + OUTPUT_VARIABLE output + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT exit_code EQUAL 0) + set(ENV{GIT_RETRIEVED_STATE} "false") + endif() +endmacro() + + + +# Function: GetGitState +# Description: gets the current state of the git repo. +# Args: +# _working_dir (in) string; the directory from which git commands will be executed. +function(GetGitState _working_dir) + + # This is an error code that'll be set to FALSE if the + # RunGitCommand ever returns a non-zero exit code. + set(ENV{GIT_RETRIEVED_STATE} "true") + + # Get whether or not the working tree is dirty. + RunGitCommand(status --porcelain) + if(NOT exit_code EQUAL 0) + set(ENV{GIT_IS_DIRTY} "false") + else() + if(NOT "${output}" STREQUAL "") + set(ENV{GIT_IS_DIRTY} "true") + else() + set(ENV{GIT_IS_DIRTY} "false") + endif() + endif() + + # There's a long list of attributes grabbed from git show. + set(object HEAD) + RunGitCommand(show -s "--format=%H" ${object}) + if(exit_code EQUAL 0) + set(ENV{GIT_HEAD_SHA1} ${output}) + endif() + + RunGitCommand(show -s "--format=%an" ${object}) + if(exit_code EQUAL 0) + set(ENV{GIT_AUTHOR_NAME} "${output}") + endif() + + RunGitCommand(show -s "--format=%ae" ${object}) + if(exit_code EQUAL 0) + set(ENV{GIT_AUTHOR_EMAIL} "${output}") + endif() + + RunGitCommand(show -s "--format=%ci" ${object}) + if(exit_code EQUAL 0) + set(ENV{GIT_COMMIT_DATE_ISO8601} "${output}") + endif() + + RunGitCommand(show -s "--format=%s" ${object}) + if(exit_code EQUAL 0) + # Escape quotes + string(REPLACE "\"" "\\\"" output "${output}") + set(ENV{GIT_COMMIT_SUBJECT} "${output}") + endif() + + RunGitCommand(show -s "--format=%b" ${object}) + if(exit_code EQUAL 0) + if(output) + # Escape quotes + string(REPLACE "\"" "\\\"" output "${output}") + # Escape line breaks in the commit message. + string(REPLACE "\r\n" "\\r\\n\\\r\n" safe "${output}") + if(safe STREQUAL output) + # Didn't have windows lines - try unix lines. + string(REPLACE "\n" "\\n\\\n" safe "${output}") + endif() + else() + # There was no commit body - set the safe string to empty. + set(safe "") + endif() + set(ENV{GIT_COMMIT_BODY} "\"${safe}\"") + else() + set(ENV{GIT_COMMIT_BODY} "\"\"") # empty string. + endif() + + # Get output of git describe + RunGitCommand(describe --always ${object}) + if(NOT exit_code EQUAL 0) + set(ENV{GIT_DESCRIBE} "unknown") + else() + set(ENV{GIT_DESCRIBE} "${output}") + endif() + + # >>> + # 2. Additional git properties can be added here via the + # "execute_process()" command. Be sure to set them in + # the environment using the same variable name you added + # to the "_state_variable_names" list. + +endfunction() + + + +# Function: GitStateChangedAction +# Description: this function is executed when the state of the git +# repository changes (e.g. a commit is made). +function(GitStateChangedAction) + foreach(var_name ${_state_variable_names}) + set(${var_name} $ENV{${var_name}}) + endforeach() + configure_file("${PRE_CONFIGURE_FILE}" "${POST_CONFIGURE_FILE}" @ONLY) +endfunction() + + + +# Function: HashGitState +# Description: loop through the git state variables and compute a unique hash. +# Args: +# _state (out) string; a hash computed from the current git state. +function(HashGitState _state) + set(ans "") + foreach(var_name ${_state_variable_names}) + string(SHA256 ans "${ans}$ENV{${var_name}}") + endforeach() + set(${_state} ${ans} PARENT_SCOPE) +endfunction() + + + +# Function: CheckGit +# Description: check if the git repo has changed. If so, update the state file. +# Args: +# _working_dir (in) string; the directory from which git commands will be ran. +# _state_changed (out) bool; whether or no the state of the repo has changed. +function(CheckGit _working_dir _state_changed) + + # Get the current state of the repo. + GetGitState("${_working_dir}") + + # Convert that state into a hash that we can compare against + # the hash stored on-disk. + HashGitState(state) + + # Issue 14: post-configure file isn't being regenerated. + # + # Update the state to include the SHA256 for the pre-configure file. + # This forces the post-configure file to be regenerated if the + # pre-configure file has changed. + file(SHA256 ${PRE_CONFIGURE_FILE} preconfig_hash) + string(SHA256 state "${preconfig_hash}${state}") + + # Check if the state has changed compared to the backup on disk. + if(EXISTS "${GIT_STATE_FILE}") + file(READ "${GIT_STATE_FILE}" OLD_HEAD_CONTENTS) + if(OLD_HEAD_CONTENTS STREQUAL "${state}") + # State didn't change. + set(${_state_changed} "false" PARENT_SCOPE) + return() + endif() + endif() + + # The state has changed. + # We need to update the state file on disk. + # Future builds will compare their state to this file. + file(WRITE "${GIT_STATE_FILE}" "${state}") + set(${_state_changed} "true" PARENT_SCOPE) +endfunction() + + + +# Function: SetupGitMonitoring +# Description: this function sets up custom commands that make the build system +# check the state of git before every build. If the state has +# changed, then a file is configured. +function(SetupGitMonitoring) + add_custom_target(check_git + ALL + DEPENDS ${PRE_CONFIGURE_FILE} + BYPRODUCTS + ${POST_CONFIGURE_FILE} + ${GIT_STATE_FILE} + COMMENT "Checking the git repository for changes..." + COMMAND + ${CMAKE_COMMAND} + -D_BUILD_TIME_CHECK_GIT=TRUE + -DGIT_WORKING_DIR=${GIT_WORKING_DIR} + -DGIT_EXECUTABLE=${GIT_EXECUTABLE} + -DGIT_STATE_FILE=${GIT_STATE_FILE} + -DPRE_CONFIGURE_FILE=${PRE_CONFIGURE_FILE} + -DPOST_CONFIGURE_FILE=${POST_CONFIGURE_FILE} + -P "${CMAKE_CURRENT_LIST_FILE}") +endfunction() + + + +# Function: Main +# Description: primary entry-point to the script. Functions are selected based +# on whether it's configure or build time. +function(Main) + if(_BUILD_TIME_CHECK_GIT) + # Check if the repo has changed. + # If so, run the change action. + CheckGit("${GIT_WORKING_DIR}" changed) + if(changed OR NOT EXISTS "${POST_CONFIGURE_FILE}") + GitStateChangedAction() + endif() + else() + # >> Executes at configure time. + SetupGitMonitoring() + endif() +endfunction() + +# And off we go... +Main() diff --git a/http/CMakeLists.txt b/http/CMakeLists.txt index 5badeaa1..9437f244 100644 --- a/http/CMakeLists.txt +++ b/http/CMakeLists.txt @@ -22,4 +22,4 @@ target_link_libraries(tonhttp PUBLIC tdactor ton_crypto tl_api tdnet ) add_executable(http-proxy http-proxy.cpp) target_include_directories(http-proxy PUBLIC $) -target_link_libraries(http-proxy PRIVATE tonhttp) +target_link_libraries(http-proxy PRIVATE tonhttp git) diff --git a/http/http-proxy.cpp b/http/http-proxy.cpp index 6b2f24eb..2e027f9f 100644 --- a/http/http-proxy.cpp +++ b/http/http-proxy.cpp @@ -34,6 +34,7 @@ #include #include +#include "git.h" #if TD_DARWIN || TD_LINUX #include @@ -265,7 +266,7 @@ int main(int argc, char *argv[]) { SET_VERBOSITY_LEVEL(v); }); p.add_option('V', "version", "shows http-proxy build version", [&]() { - std::cout << "http-proxy build version: [" << BUILD_VERSION << "]\n"; + std::cout << "http-proxy build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints_help", [&]() { diff --git a/lite-client/CMakeLists.txt b/lite-client/CMakeLists.txt index 78bd96b5..b8449516 100644 --- a/lite-client/CMakeLists.txt +++ b/lite-client/CMakeLists.txt @@ -5,6 +5,6 @@ target_link_libraries(lite-client-common PUBLIC tdutils tdactor adnllite tl_api add_executable(lite-client lite-client.cpp lite-client.h) target_link_libraries(lite-client tdutils tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto ton_block - terminal lite-client-common) + terminal lite-client-common git) install(TARGETS lite-client RUNTIME DESTINATION bin) diff --git a/lite-client/lite-client.cpp b/lite-client/lite-client.cpp index 592c34cc..3571bafb 100644 --- a/lite-client/lite-client.cpp +++ b/lite-client/lite-client.cpp @@ -69,6 +69,7 @@ #endif #include #include +#include "git.h" using namespace std::literals::string_literals; using td::Ref; @@ -4200,8 +4201,9 @@ int main(int argc, char* argv[]) { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + verbosity); return (verbosity >= 0 && verbosity <= 9) ? td::Status::OK() : td::Status::Error("verbosity must be 0..9"); }); - p.add_option('V', "version", "shows lite-client build version", [&]() { - std::cout << "lite-client build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows lite-client build information", [&]() { + std::cout << "lite-client build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; + std::exit(0); }); p.add_option('i', "idx", "set liteserver idx", [&](td::Slice arg) { diff --git a/rldp-http-proxy/CMakeLists.txt b/rldp-http-proxy/CMakeLists.txt index 3013ee81..8fa4ac55 100644 --- a/rldp-http-proxy/CMakeLists.txt +++ b/rldp-http-proxy/CMakeLists.txt @@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) add_executable(rldp-http-proxy rldp-http-proxy.cpp) target_include_directories(rldp-http-proxy PUBLIC $) -target_link_libraries(rldp-http-proxy PRIVATE tonhttp rldp dht tonlib) +target_link_libraries(rldp-http-proxy PRIVATE tonhttp rldp dht tonlib git) diff --git a/rldp-http-proxy/rldp-http-proxy.cpp b/rldp-http-proxy/rldp-http-proxy.cpp index 010de93b..59533c50 100644 --- a/rldp-http-proxy/rldp-http-proxy.cpp +++ b/rldp-http-proxy/rldp-http-proxy.cpp @@ -51,6 +51,7 @@ #include #include #include +#include "git.h" #if TD_DARWIN || TD_LINUX #include @@ -1133,8 +1134,8 @@ int main(int argc, char *argv[]) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); }); - p.add_option('V', "version", "shows rldp-http-proxy build version", [&]() { - std::cout << "rldp-http-proxy build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows rldp-http-proxy build information", [&]() { + std::cout << "rldp-http-proxy build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints a help message", [&]() { diff --git a/rldp2/RldpConnection.cpp b/rldp2/RldpConnection.cpp index 02c91662..e6ba2cfd 100644 --- a/rldp2/RldpConnection.cpp +++ b/rldp2/RldpConnection.cpp @@ -278,7 +278,7 @@ void RldpConnection::receive_raw_obj(ton::ton_api::rldp2_messagePart &part) { return; } - auto r_total_size = td::narrow_cast_safe(part.total_size_); + auto r_total_size = td::narrow_cast_safe(part.total_size_); if (r_total_size.is_error()) { return; } diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt index fca96765..0e5cf085 100644 --- a/storage/CMakeLists.txt +++ b/storage/CMakeLists.txt @@ -45,7 +45,7 @@ target_include_directories(storage PUBLIC add_executable(storage-cli ${STORAGE_CLI_SOURCE}) target_link_libraries(storage-cli storage overlay tdutils tdactor adnl tl_api dht rldp rldp2 catchain validatorsession full-node validator ton_validator validator - fift-lib memprof terminal ${JEMALLOC_LIBRARIES}) + fift-lib memprof terminal git ${JEMALLOC_LIBRARIES}) set(STORAGE_TEST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/test/storage.cpp diff --git a/storage/LoadSpeed.cpp b/storage/LoadSpeed.cpp index a2708055..c2fcfcd4 100644 --- a/storage/LoadSpeed.cpp +++ b/storage/LoadSpeed.cpp @@ -22,7 +22,7 @@ #include "td/utils/format.h" namespace ton { -void LoadSpeed::add(td::size_t size, td::Timestamp now) { +void LoadSpeed::add(std::size_t size, td::Timestamp now) { total_size_ += size; events_.push(Event{size, now}); update(now); diff --git a/storage/LoadSpeed.h b/storage/LoadSpeed.h index c2902e61..d936f541 100644 --- a/storage/LoadSpeed.h +++ b/storage/LoadSpeed.h @@ -26,17 +26,17 @@ namespace ton { class LoadSpeed { public: - void add(td::size_t size, td::Timestamp now); + void add(std::size_t size, td::Timestamp now); double speed(td::Timestamp now = td::Timestamp::now()) const; friend td::StringBuilder &operator<<(td::StringBuilder &sb, const LoadSpeed &speed); private: struct Event { - td::size_t size; + std::size_t size; td::Timestamp at; }; mutable td::VectorQueue events_; - mutable td::size_t total_size_{0}; + mutable std::size_t total_size_{0}; double duration() const; void update(td::Timestamp now) const; diff --git a/storage/MerkleTree.cpp b/storage/MerkleTree.cpp index ff88ee44..d35a1f39 100644 --- a/storage/MerkleTree.cpp +++ b/storage/MerkleTree.cpp @@ -138,7 +138,7 @@ void MerkleTree::init_finish() { CHECK(root_hash_); } -void MerkleTree::remove_chunk(td::size_t index) { +void MerkleTree::remove_chunk(std::size_t index) { CHECK(index < n_); index += n_; while (proof_[index].not_null()) { @@ -147,13 +147,13 @@ void MerkleTree::remove_chunk(td::size_t index) { } } -bool MerkleTree::has_chunk(td::size_t index) const { +bool MerkleTree::has_chunk(std::size_t index) const { CHECK(index < n_); index += n_; return proof_[index].not_null(); } -void MerkleTree::add_chunk(td::size_t index, td::Slice hash) { +void MerkleTree::add_chunk(std::size_t index, td::Slice hash) { CHECK(hash.size() == 32); CHECK(index < n_); index += n_; diff --git a/storage/MerkleTree.h b/storage/MerkleTree.h index 551eddc3..6f7be17d 100644 --- a/storage/MerkleTree.h +++ b/storage/MerkleTree.h @@ -39,7 +39,7 @@ class MerkleTree { MerkleTree(size_t chunks_count, td::Ref root_proof); struct Chunk { - td::size_t index{0}; + std::size_t index{0}; td::Bits256 hash; }; @@ -47,7 +47,7 @@ class MerkleTree { MerkleTree() = default; void init_begin(size_t chunks_count); - void init_add_chunk(td::size_t index, td::Slice hash); + void init_add_chunk(std::size_t index, td::Slice hash); void init_finish(); // merge external proof with an existing proof @@ -70,20 +70,20 @@ class MerkleTree { private: td::uint64 total_blocks_; - td::size_t n_; // n = 2^log_n + std::size_t n_; // n = 2^log_n td::uint32 log_n_; - td::size_t mark_id_{0}; - std::vector mark_; // n_ * 2 + std::size_t mark_id_{0}; + std::vector mark_; // n_ * 2 std::vector> proof_; // n_ * 2 td::optional root_hash_; td::Ref root_proof_; td::Status validate_proof(td::Ref new_root); - bool has_chunk(td::size_t index) const; - void remove_chunk(td::size_t index); + bool has_chunk(std::size_t index) const; + void remove_chunk(std::size_t index); - void add_chunk(td::size_t index, td::Slice hash); + void add_chunk(std::size_t index, td::Slice hash); void init_proof(); td::Ref merge(td::Ref root, size_t index); diff --git a/storage/storage-cli.cpp b/storage/storage-cli.cpp index d2cc96e3..fcbbc55f 100644 --- a/storage/storage-cli.cpp +++ b/storage/storage-cli.cpp @@ -51,6 +51,7 @@ #include #include #include +#include "git.h" namespace ton_rldp = ton::rldp2; @@ -749,7 +750,7 @@ class StorageCli : public td::actor::Actor { auto file_id_str = parser.read_word(); size_t file_id = std::numeric_limits::max(); if (file_id_str != "*") { - TRY_RESULT_PROMISE_ASSIGN(promise, file_id, td::to_integer_safe(file_id_str)); + TRY_RESULT_PROMISE_ASSIGN(promise, file_id, td::to_integer_safe(file_id_str)); } TRY_RESULT_PROMISE(promise, priority, td::to_integer_safe(parser.read_word())); if (priority == 255) { @@ -837,6 +838,10 @@ int main(int argc, char *argv[]) { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + verbosity); return (verbosity >= 0 && verbosity <= 20) ? td::Status::OK() : td::Status::Error("verbosity must be 0..20"); }); + p.add_option('V', "version", "shows storage-cli build information", [&]() { + std::cout << "storage-cli build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; + std::exit(0); + }); p.add_option('C', "config", "set ton config", [&](td::Slice arg) { options.config = arg.str(); }); p.add_option('D', "db", "root for dbs", [&](td::Slice fname) { options.db_root = fname.str(); }); p.add_checked_option('I', "ip", "set ip:port", [&](td::Slice arg) { diff --git a/tonlib/CMakeLists.txt b/tonlib/CMakeLists.txt index 1a0f7267..5b6530a6 100644 --- a/tonlib/CMakeLists.txt +++ b/tonlib/CMakeLists.txt @@ -69,7 +69,7 @@ if (TONLIB_ENABLE_JNI AND NOT ANDROID) # jni is available by default on Android endif() add_executable(tonlib-cli tonlib/tonlib-cli.cpp) -target_link_libraries(tonlib-cli tonlib tdactor tdutils terminal pow-miner-lib) +target_link_libraries(tonlib-cli tonlib tdactor tdutils terminal pow-miner-lib git) if (NOT CMAKE_CROSSCOMPILING) if (TONLIB_ENABLE_JNI) diff --git a/tonlib/tonlib/tonlib-cli.cpp b/tonlib/tonlib/tonlib-cli.cpp index f39f1afc..e90cbbab 100644 --- a/tonlib/tonlib/tonlib-cli.cpp +++ b/tonlib/tonlib/tonlib-cli.cpp @@ -61,6 +61,7 @@ #include #include #include +#include "git.h" using tonlib_api::make_object; @@ -2308,8 +2309,8 @@ int main(int argc, char* argv[]) { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + verbosity); return (verbosity >= 0 && verbosity <= 20) ? td::Status::OK() : td::Status::Error("verbosity must be 0..20"); }); - p.add_option('V', "version", "show tonlib-cli build version", [&]() { - std::cout << "Fift build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "show tonlib-cli build information", [&]() { + std::cout << "tonlib-cli build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_checked_option('C', "config-force", "set lite server config, drop config related blockchain cache", diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 8f2211a6..25df5729 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -5,18 +5,18 @@ if (NOT OPENSSL_FOUND) endif() add_executable(generate-random-id generate-random-id.cpp ) -target_link_libraries(generate-random-id tl_api ton_crypto keys adnl) +target_link_libraries(generate-random-id tl_api ton_crypto keys adnl git) target_include_directories(generate-random-id PUBLIC $/..) add_executable(json2tlo json2tlo.cpp ) -target_link_libraries(json2tlo tl_api ton_crypto keys ) +target_link_libraries(json2tlo tl_api ton_crypto keys git) target_include_directories(json2tlo PUBLIC $/..) add_executable(pack-viewer pack-viewer.cpp ) -target_link_libraries(pack-viewer tl_api ton_crypto keys validator tddb ) +target_link_libraries(pack-viewer tl_api ton_crypto keys validator tddb) target_include_directories(pack-viewer PUBLIC $/..) diff --git a/utils/generate-random-id.cpp b/utils/generate-random-id.cpp index af0cb3e0..3727f291 100644 --- a/utils/generate-random-id.cpp +++ b/utils/generate-random-id.cpp @@ -39,6 +39,7 @@ #include "td/utils/filesystem.h" #include "keys/encryptor.h" #include "keys/keys.hpp" +#include "git.h" int main(int argc, char *argv[]) { ton::PrivateKey pk; @@ -59,8 +60,8 @@ int main(int argc, char *argv[]) { std::cout << sb.as_cslice().c_str(); std::exit(2); }); - p.add_option('V', "version", "shows generate-random-id build version", [&]() { - std::cout << "generate-random-id build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows generate-random-id build information", [&]() { + std::cout << "generate-random-id build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('n', "name", "path to save private keys to", [&](td::Slice arg) { name = arg.str(); }); diff --git a/utils/json2tlo.cpp b/utils/json2tlo.cpp index c1767454..f4c4fdbf 100644 --- a/utils/json2tlo.cpp +++ b/utils/json2tlo.cpp @@ -39,6 +39,7 @@ #include "tl/tl_json.h" #include "auto/tl/ton_api.h" #include "auto/tl/ton_api_json.h" +#include "git.h" int main(int argc, char *argv[]) { std::string in_f; @@ -51,8 +52,8 @@ int main(int argc, char *argv[]) { p.add_option('i', "in", "input", [&](td::Slice key) { in_f = key.str(); }); p.add_option('o', "out", "output", [&](td::Slice key) { out_f = key.str(); }); p.add_option('r', "reverse", "read tlo, print json", [&]() { reverse_ = !reverse_; }); - p.add_option('V', "version", "shows json2tlo build version", [&]() { - std::cout << "json2tlo build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows json2tlo build information", [&]() { + std::cout << "json2tlo build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints_help", [&]() { diff --git a/validator-engine-console/CMakeLists.txt b/validator-engine-console/CMakeLists.txt index 42d60afb..48716960 100644 --- a/validator-engine-console/CMakeLists.txt +++ b/validator-engine-console/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) add_executable (validator-engine-console validator-engine-console.cpp validator-engine-console.h validator-engine-console-query.cpp validator-engine-console-query.h ) -target_link_libraries(validator-engine-console tdutils tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto ton_block terminal) +target_link_libraries(validator-engine-console tdutils tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto ton_block terminal git) install(TARGETS validator-engine-console RUNTIME DESTINATION bin) diff --git a/validator-engine-console/validator-engine-console.cpp b/validator-engine-console/validator-engine-console.cpp index 7f881560..43a02dc6 100644 --- a/validator-engine-console/validator-engine-console.cpp +++ b/validator-engine-console/validator-engine-console.cpp @@ -59,6 +59,7 @@ #endif #include #include +#include "git.h" int verbosity; @@ -256,8 +257,8 @@ int main(int argc, char* argv[]) { std::cout << sb.as_cslice().c_str(); std::exit(2); }); - p.add_option('V', "version", "shows validator-engine-console build version", [&]() { - std::cout << "validator-engine-console build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows validator-engine-console build information", [&]() { + std::cout << "validator-engine-console build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_checked_option('a', "address", "server address", [&](td::Slice arg) { diff --git a/validator-engine/CMakeLists.txt b/validator-engine/CMakeLists.txt index 02040d5f..6c1ea7e2 100644 --- a/validator-engine/CMakeLists.txt +++ b/validator-engine/CMakeLists.txt @@ -13,6 +13,6 @@ set(VALIDATOR_ENGINE_SOURCE add_executable(validator-engine ${VALIDATOR_ENGINE_SOURCE}) target_link_libraries(validator-engine overlay tdutils tdactor adnl tl_api dht rldp catchain validatorsession full-node validator ton_validator validator - fift-lib memprof ${JEMALLOC_LIBRARIES}) + fift-lib memprof git ${JEMALLOC_LIBRARIES}) install(TARGETS validator-engine RUNTIME DESTINATION bin) diff --git a/validator-engine/validator-engine.cpp b/validator-engine/validator-engine.cpp index fa921db1..4205c53b 100644 --- a/validator-engine/validator-engine.cpp +++ b/validator-engine/validator-engine.cpp @@ -62,6 +62,7 @@ #include #include #include +#include "git.h" Config::Config() { out_port = 3278; @@ -3286,8 +3287,8 @@ int main(int argc, char *argv[]) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); }); - p.add_option('V', "version", "shows validator-engine build version", [&]() { - std::cout << "validator-engine build version: [" << BUILD_VERSION << "]\n"; + p.add_option('V', "version", "shows validator-engine build information", [&]() { + std::cout << "validator-engine build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n"; std::exit(0); }); p.add_option('h', "help", "prints_help", [&]() {