Skip to content

Commit

Permalink
Automatically integrates git build information into executables.
Browse files Browse the repository at this point in the history
Usage:
func.exe -V
adnl-pong -V
validator-engine -V
and so on.
Result will be shown in the following format:
Func build information: [ Commit: d8b751d, Date: 2021-02-27 14:34:41 +0200]
  • Loading branch information
neodix42 authored and main committed Feb 27, 2021
1 parent 41a3418 commit bab4c16
Show file tree
Hide file tree
Showing 40 changed files with 492 additions and 78 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions adnl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
Expand All @@ -105,4 +105,4 @@ endif()
add_library(adnllite STATIC ${ADNL_LITE_SOURCE})

target_include_directories(adnllite PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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)
5 changes: 3 additions & 2 deletions adnl/adnl-pong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "auto/tl/ton_api_json.h"
#include "adnl/adnl.h"
#include <map>
#include "git.h"

#if TD_DARWIN || TD_LINUX
#include <unistd.h>
Expand Down Expand Up @@ -97,8 +98,8 @@ int main(int argc, char *argv[]) {
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(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", [&]() {
Expand Down
5 changes: 3 additions & 2 deletions adnl/adnl-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "adnl-proxy-types.h"
#include "adnl-received-mask.h"
#include <map>
#include "git.h"

#if TD_DARWIN || TD_LINUX
#include <unistd.h>
Expand Down Expand Up @@ -303,8 +304,8 @@ int main(int argc, char *argv[]) {
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(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", [&]() {
Expand Down
2 changes: 1 addition & 1 deletion create-hardfork/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions create-hardfork/create-hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#endif
#include <iostream>
#include <sstream>
#include "git.h"

int verbosity;

Expand Down Expand Up @@ -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",
Expand Down
20 changes: 11 additions & 9 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
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()
Expand All @@ -312,10 +312,11 @@ target_include_directories(pow-miner-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURREN
target_link_libraries(pow-miner-lib PUBLIC ton_crypto ton_block)

add_executable(pow-miner util/pow-miner.cpp)
target_link_libraries(pow-miner PRIVATE ton_crypto ton_block pow-miner-lib)
target_link_libraries(pow-miner PRIVATE ton_crypto ton_block pow-miner-lib git)

if (WINGETOPT_FOUND)
target_link_libraries_system(fift wingetopt)
target_link_libraries_system(pow-miner wingetopt)
endif()

add_library(ton_block ${BLOCK_SOURCE})
Expand Down Expand Up @@ -404,12 +405,12 @@ add_executable(create-state block/create-state.cpp)
target_include_directories(create-state PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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)
Expand All @@ -419,23 +420,24 @@ endif()
add_executable(dump-block block/dump-block.cpp)
target_include_directories(dump-block PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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()

add_executable(adjust-block block/adjust-block.cpp)
target_include_directories(adjust-block PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
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()
Expand Down
7 changes: 6 additions & 1 deletion crypto/block/adjust-block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "vm/cp0.h"
#include "td/utils/crypto.h"
#include <getopt.h>
#include "git.h"

using td::Ref;
using namespace std::literals::string_literals;
Expand Down Expand Up @@ -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();
Expand All @@ -156,6 +157,10 @@ int main(int argc, char* const argv[]) {
case 'v':
new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer<int>(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;
Expand Down
7 changes: 4 additions & 3 deletions crypto/block/create-state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -805,7 +806,7 @@ void usage(const char* progname) {
"$FIFTPATH is used instead.\n"
"\t-L<library-fif-file>\tPre-loads a library source file\n"
"\t-v<verbosity-level>\tSet verbosity level\n"
"\t-V<version>\tShow create-state build version\n";
"\t-V<version>\tShow create-state build information\n";
std::exit(2);
}

Expand Down Expand Up @@ -865,8 +866,8 @@ int main(int argc, char* const argv[]) {
case 'v':
new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer<int>(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':
Expand Down
5 changes: 3 additions & 2 deletions crypto/block/dump-block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "mc-config.h"
#include "vm/cp0.h"
#include <getopt.h>
#include "git.h"

using td::Ref;
using namespace std::literals::string_literals;
Expand Down Expand Up @@ -247,7 +248,7 @@ void usage() {
std::cout << "usage: dump-block [-t<typename>][-S][<boc-file>]\n\tor dump-block -h\n\tDumps specified blockchain "
"block or state "
"from <boc-file>, or runs some tests\n\t-S\tDump a blockchain state instead of a block\n"
"\t-V<version>\tShow fift build version\n";
"\t-V<version>\tShow fift build information\n";
std::exit(2);
}

Expand Down Expand Up @@ -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':
Expand Down
6 changes: 4 additions & 2 deletions crypto/fift/fift-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -66,7 +68,7 @@ void usage(const char* progname) {
"\t-d<ton-db-path>\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<verbosity-level>\tSet verbosity level\n"
"\t-V<version>\tShow fift build version\n";
"\t-V<version>\tShow fift build information\n";
std::exit(2);
}

Expand Down Expand Up @@ -118,7 +120,7 @@ int main(int argc, char* const argv[]) {
new_verbosity_level = VERBOSITY_NAME(FATAL) + td::to_integer<int>(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;

Expand Down
5 changes: 3 additions & 2 deletions crypto/func/func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "parser/symtable.h"
#include <getopt.h>
#include <fstream>
#include "git.h"

namespace funC {

Expand Down Expand Up @@ -172,7 +173,7 @@ void usage(const char* progname) {
"-R\tInclude operation rewrite comments in the output code\n"
"-W<output-boc-file>\tInclude Fift code to serialize and save generated code into specified BoC file. Enables "
"-A and -P.\n"
"\t-V<version>\tShow func build version\n";
"\t-V<version>\tShow func build information\n";
std::exit(2);
}

Expand Down Expand Up @@ -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':
Expand Down
10 changes: 7 additions & 3 deletions crypto/util/pow-miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <thread>
#include <cstdlib>
#include <getopt.h>

#include "git.h"
#include "Miner.h"

const char* progname;
Expand All @@ -46,7 +46,7 @@ int usage() {
std::cerr
<< "usage: " << progname
<< " [-v][-B][-w<threads>] [-t<timeout>] <my-address> <pow-seed> <pow-complexity> <iterations> [<miner-addr> "
"<output-ext-msg-boc>]\n"
"<output-ext-msg-boc>] [-V]\n"
"Outputs a valid <rdata> value for proof-of-work testgiver after computing at most <iterations> hashes "
"or terminates with non-zero exit code\n";
std::exit(2);
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dht-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions dht-server/dht-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <sstream>
#include <cstdlib>
#include <set>
#include "git.h"

Config::Config() {
out_port = 3278;
Expand Down Expand Up @@ -1182,8 +1183,8 @@ int main(int argc, char *argv[]) {
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(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", [&]() {
Expand Down
Loading

0 comments on commit bab4c16

Please sign in to comment.