Skip to content

Commit bab4c16

Browse files
neodix42main
authored and
main
committed
Automatically integrates git build information into executables.
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]
1 parent 41a3418 commit bab4c16

40 files changed

+492
-78
lines changed

CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ project(TON VERSION 0.5 LANGUAGES C CXX)
44
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
55
#set(OPENSSL_USE_STATIC_LIBS TRUE)
66

7-
ADD_DEFINITIONS( -DBUILD_VERSION=\"3.0.0\" )
7+
# Define the two required variables before including the source code for watching a git repository.
8+
set(PRE_CONFIGURE_FILE "git.cc.in")
9+
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/git.cc")
10+
include(git_watcher.cmake)
11+
12+
# Create a library out of the compiled post-configure file.
13+
add_library(git STATIC ${POST_CONFIGURE_FILE})
14+
target_include_directories(git PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
15+
add_dependencies(git check_git)
816

917
# Prevent in-source build
1018
get_filename_component(TON_REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)

adnl/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ target_link_libraries(adnl PUBLIC tdactor ton_crypto tl_api tdnet tddb keys keyr
8989
add_executable(adnl-proxy ${ADNL_PROXY_SOURCE})
9090
target_include_directories(adnl-proxy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
9191
target_link_libraries(adnl-proxy PUBLIC tdactor ton_crypto tl_api tdnet common
92-
tl-utils)
92+
tl-utils git)
9393

9494
add_executable(adnl-pong adnl-pong.cpp)
9595
target_include_directories(adnl-pong PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
9696
target_link_libraries(adnl-pong PUBLIC tdactor ton_crypto tl_api tdnet common
97-
tl-utils adnl dht)
97+
tl-utils adnl dht git)
9898

9999
add_library(adnltest STATIC ${ADNL_TEST_SOURCE})
100100
target_include_directories(adnltest PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
@@ -105,4 +105,4 @@ endif()
105105
add_library(adnllite STATIC ${ADNL_LITE_SOURCE})
106106

107107
target_include_directories(adnllite PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
108-
target_link_libraries(adnllite PUBLIC tdactor ton_crypto tl_lite_api tdnet keys )
108+
target_link_libraries(adnllite PUBLIC tdactor ton_crypto tl_lite_api tdnet keys)

adnl/adnl-pong.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "auto/tl/ton_api_json.h"
4242
#include "adnl/adnl.h"
4343
#include <map>
44+
#include "git.h"
4445

4546
#if TD_DARWIN || TD_LINUX
4647
#include <unistd.h>
@@ -97,8 +98,8 @@ int main(int argc, char *argv[]) {
9798
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(arg));
9899
SET_VERBOSITY_LEVEL(v);
99100
});
100-
p.add_option('V', "version", "shows adnl-pong build version", [&]() {
101-
std::cout << "adnl-pong build version: [" << BUILD_VERSION << "]\n";
101+
p.add_option('V', "version", "shows adnl-pong build information", [&]() {
102+
std::cout << "adnl-pong build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
102103
std::exit(0);
103104
});
104105
p.add_option('h', "help", "prints_help", [&]() {

adnl/adnl-proxy.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "adnl-proxy-types.h"
4444
#include "adnl-received-mask.h"
4545
#include <map>
46+
#include "git.h"
4647

4748
#if TD_DARWIN || TD_LINUX
4849
#include <unistd.h>
@@ -303,8 +304,8 @@ int main(int argc, char *argv[]) {
303304
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(arg));
304305
SET_VERBOSITY_LEVEL(v);
305306
});
306-
p.add_option('V', "version", "shows adnl-proxy build version", [&]() {
307-
std::cout << "adnl-proxy build version: [" << BUILD_VERSION << "]\n";
307+
p.add_option('V', "version", "shows adnl-proxy build information", [&]() {
308+
std::cout << "adnl-proxy build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
308309
std::exit(0);
309310
});
310311
p.add_option('h', "help", "prints_help", [&]() {

create-hardfork/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ set(CREATE_HARDFORK_SOURCE
1212
add_executable(create-hardfork ${CREATE_HARDFORK_SOURCE})
1313
target_link_libraries(create-hardfork overlay tdutils tdactor adnl tl_api dht
1414
rldp catchain validatorsession full-node validator-hardfork ton_validator
15-
validator-hardfork fift-lib memprof ${JEMALLOC_LIBRARIES})
15+
validator-hardfork fift-lib memprof git ${JEMALLOC_LIBRARIES})
1616

1717
install(TARGETS create-hardfork RUNTIME DESTINATION bin)

create-hardfork/create-hardfork.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#endif
5656
#include <iostream>
5757
#include <sstream>
58+
#include "git.h"
5859

5960
int verbosity;
6061

@@ -263,8 +264,8 @@ int main(int argc, char *argv[]) {
263264
std::cout << sb.as_cslice().c_str();
264265
std::exit(2);
265266
});
266-
p.add_option('V', "version", "shows create-hardfork build version", [&]() {
267-
std::cout << "create-hardfork build version: [" << BUILD_VERSION << "]\n";
267+
p.add_option('V', "version", "shows create-hardfork build information", [&]() {
268+
std::cout << "create-hardfork build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
268269
std::exit(0);
269270
});
270271
p.add_option('D', "db", "root for dbs",

crypto/CMakeLists.txt

+11-9
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ target_link_libraries(fift-lib PUBLIC ton_crypto ton_db tdutils ton_block)
284284
set_target_properties(fift-lib PROPERTIES OUTPUT_NAME fift)
285285

286286
add_executable(fift fift/fift-main.cpp)
287-
target_link_libraries(fift PUBLIC fift-lib)
287+
target_link_libraries(fift PUBLIC fift-lib git)
288288
if (WINGETOPT_FOUND)
289289
target_link_libraries_system(fift wingetopt)
290290
endif()
@@ -295,7 +295,7 @@ target_link_libraries(src_parser PUBLIC ton_crypto)
295295

296296
add_executable(func func/func.cpp ${FUNC_LIB_SOURCE})
297297
target_include_directories(func PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
298-
target_link_libraries(func PUBLIC ton_crypto src_parser)
298+
target_link_libraries(func PUBLIC ton_crypto src_parser git)
299299
if (WINGETOPT_FOUND)
300300
target_link_libraries_system(func wingetopt)
301301
endif()
@@ -312,10 +312,11 @@ target_include_directories(pow-miner-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURREN
312312
target_link_libraries(pow-miner-lib PUBLIC ton_crypto ton_block)
313313

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

317317
if (WINGETOPT_FOUND)
318318
target_link_libraries_system(fift wingetopt)
319+
target_link_libraries_system(pow-miner wingetopt)
319320
endif()
320321

321322
add_library(ton_block ${BLOCK_SOURCE})
@@ -404,12 +405,12 @@ add_executable(create-state block/create-state.cpp)
404405
target_include_directories(create-state PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
405406
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
406407
if (INTERNAL_COMPILE)
407-
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib)
408+
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib git)
408409
else()
409410
if (TONLIB_COMPILE)
410-
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib)
411+
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib git)
411412
else()
412-
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block)
413+
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block git)
413414
endif()
414415
endif()
415416
if (WINGETOPT_FOUND)
@@ -419,23 +420,24 @@ endif()
419420
add_executable(dump-block block/dump-block.cpp)
420421
target_include_directories(dump-block PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
421422
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
422-
target_link_libraries(dump-block PUBLIC ton_crypto fift-lib ton_block)
423+
target_link_libraries(dump-block PUBLIC ton_crypto fift-lib ton_block git)
423424
if (WINGETOPT_FOUND)
424425
target_link_libraries_system(dump-block wingetopt)
425426
endif()
426427

427428
add_executable(adjust-block block/adjust-block.cpp)
428429
target_include_directories(adjust-block PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
429430
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
430-
target_link_libraries(adjust-block PUBLIC ton_crypto fift-lib ton_block)
431+
target_link_libraries(adjust-block PUBLIC ton_crypto fift-lib ton_block git)
431432
if (WINGETOPT_FOUND)
432433
target_link_libraries_system(dump-block wingetopt)
434+
target_link_libraries_system(adjust-block wingetopt)
433435
endif()
434436

435437
add_executable(test-weight-distr block/test-weight-distr.cpp)
436438
target_include_directories(test-weight-distr PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
437439
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
438-
target_link_libraries(test-weight-distr PUBLIC ton_crypto fift-lib ton_block)
440+
target_link_libraries(test-weight-distr PUBLIC ton_crypto fift-lib ton_block git)
439441
if (WINGETOPT_FOUND)
440442
target_link_libraries_system(test-weight-distr wingetopt)
441443
endif()

crypto/block/adjust-block.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "vm/cp0.h"
3535
#include "td/utils/crypto.h"
3636
#include <getopt.h>
37+
#include "git.h"
3738

3839
using td::Ref;
3940
using namespace std::literals::string_literals;
@@ -144,7 +145,7 @@ int main(int argc, char* const argv[]) {
144145
int i, vseqno_incr = 1;
145146
int new_verbosity_level = VERBOSITY_NAME(INFO);
146147
std::string in_fname, out_fname;
147-
while ((i = getopt(argc, argv, "hi:v:")) != -1) {
148+
while ((i = getopt(argc, argv, "hi:v:V")) != -1) {
148149
switch (i) {
149150
case 'h':
150151
usage();
@@ -156,6 +157,10 @@ int main(int argc, char* const argv[]) {
156157
case 'v':
157158
new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer<int>(td::Slice(optarg)));
158159
break;
160+
case 'V':
161+
std::cout << "adjust-block build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
162+
std::exit(0);
163+
break;
159164
default:
160165
usage();
161166
break;

crypto/block/create-state.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "block-parse.h"
6060
#include "block-auto.h"
6161
#include "mc-config.h"
62+
#include "git.h"
6263

6364
#if defined(_INTERNAL_COMPILE) || defined(_TONLIB_COMPILE)
6465
#define WITH_TONLIB
@@ -805,7 +806,7 @@ void usage(const char* progname) {
805806
"$FIFTPATH is used instead.\n"
806807
"\t-L<library-fif-file>\tPre-loads a library source file\n"
807808
"\t-v<verbosity-level>\tSet verbosity level\n"
808-
"\t-V<version>\tShow create-state build version\n";
809+
"\t-V<version>\tShow create-state build information\n";
809810
std::exit(2);
810811
}
811812

@@ -865,8 +866,8 @@ int main(int argc, char* const argv[]) {
865866
case 'v':
866867
new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer<int>(td::Slice(optarg)));
867868
break;
868-
case 'V':
869-
std::cout << "create-state build version: [" << BUILD_VERSION << "]\n";
869+
case 'V':
870+
std::cout << "create-state build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
870871
std::exit(0);
871872
break;
872873
case 'h':

crypto/block/dump-block.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "mc-config.h"
3535
#include "vm/cp0.h"
3636
#include <getopt.h>
37+
#include "git.h"
3738

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

@@ -282,7 +283,7 @@ int main(int argc, char* const argv[]) {
282283
dump = 0;
283284
break;
284285
case 'V':
285-
std::cout << "dump-block build version: [" << BUILD_VERSION << "]\n";
286+
std::cout << "dump-block build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
286287
std::exit(0);
287288
break;
288289
case 'h':

crypto/fift/fift-main.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include "td/utils/Parser.h"
5454
#include "td/utils/port/path.h"
5555

56+
#include "git.h"
57+
5658
void usage(const char* progname) {
5759
std::cerr << "A simple Fift interpreter. Type `bye` to quit, or `words` to get a list of all commands\n";
5860
std::cerr
@@ -66,7 +68,7 @@ void usage(const char* progname) {
6668
"\t-d<ton-db-path>\tUse a ton database\n"
6769
"\t-s\tScript mode: use first argument as a fift source file and import remaining arguments as $n)\n"
6870
"\t-v<verbosity-level>\tSet verbosity level\n"
69-
"\t-V<version>\tShow fift build version\n";
71+
"\t-V<version>\tShow fift build information\n";
7072
std::exit(2);
7173
}
7274

@@ -118,7 +120,7 @@ int main(int argc, char* const argv[]) {
118120
new_verbosity_level = VERBOSITY_NAME(FATAL) + td::to_integer<int>(td::Slice(optarg));
119121
break;
120122
case 'V':
121-
std::cout << "Fift build version: [" << BUILD_VERSION << "]\n";
123+
std::cout << "Fift build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
122124
std::exit(0);
123125
break;
124126

crypto/func/func.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "parser/symtable.h"
3232
#include <getopt.h>
3333
#include <fstream>
34+
#include "git.h"
3435

3536
namespace funC {
3637

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

@@ -215,7 +216,7 @@ int main(int argc, char* const argv[]) {
215216
funC::asm_preamble = funC::program_envelope = true;
216217
break;
217218
case 'V':
218-
std::cout << "Func build version: [" << BUILD_VERSION << "]\n";
219+
std::cout << "Func build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
219220
std::exit(0);
220221
break;
221222
case 'h':

crypto/util/pow-miner.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <thread>
3838
#include <cstdlib>
3939
#include <getopt.h>
40-
40+
#include "git.h"
4141
#include "Miner.h"
4242

4343
const char* progname;
@@ -46,7 +46,7 @@ int usage() {
4646
std::cerr
4747
<< "usage: " << progname
4848
<< " [-v][-B][-w<threads>] [-t<timeout>] <my-address> <pow-seed> <pow-complexity> <iterations> [<miner-addr> "
49-
"<output-ext-msg-boc>]\n"
49+
"<output-ext-msg-boc>] [-V]\n"
5050
"Outputs a valid <rdata> value for proof-of-work testgiver after computing at most <iterations> hashes "
5151
"or terminates with non-zero exit code\n";
5252
std::exit(2);
@@ -156,7 +156,7 @@ int main(int argc, char* const argv[]) {
156156
progname = argv[0];
157157
int i, threads = 0;
158158
bool bounce = false, benchmark = false;
159-
while ((i = getopt(argc, argv, "bnvw:t:Bh")) != -1) {
159+
while ((i = getopt(argc, argv, "bnvw:t:Bh:V")) != -1) {
160160
switch (i) {
161161
case 'v':
162162
++verbosity;
@@ -180,6 +180,10 @@ int main(int argc, char* const argv[]) {
180180
case 'n':
181181
bounce = false;
182182
break;
183+
case 'V':
184+
std::cout << "pow-miner build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
185+
std::exit(0);
186+
break;
183187
case 'h':
184188
return usage();
185189
default:

dht-server/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ set (DHT_SERVER_SOURCE
1111
)
1212

1313
add_executable (dht-server ${DHT_SERVER_SOURCE})
14-
target_link_libraries(dht-server tdutils tdactor adnl tl_api dht memprof ${JEMALLOC_LIBRARIES})
14+
target_link_libraries(dht-server tdutils tdactor adnl tl_api dht memprof git ${JEMALLOC_LIBRARIES})
1515

1616
install(TARGETS dht-server RUNTIME DESTINATION bin)

dht-server/dht-server.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <sstream>
4949
#include <cstdlib>
5050
#include <set>
51+
#include "git.h"
5152

5253
Config::Config() {
5354
out_port = 3278;
@@ -1182,8 +1183,8 @@ int main(int argc, char *argv[]) {
11821183
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(arg));
11831184
SET_VERBOSITY_LEVEL(v);
11841185
});
1185-
p.add_option('V', "version", "shows dht-server build version", [&]() {
1186-
std::cout << "dht-server build version: [" << BUILD_VERSION << "]\n";
1186+
p.add_option('V', "version", "shows dht-server build information", [&]() {
1187+
std::cout << "dht-server build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
11871188
std::exit(0);
11881189
});
11891190
p.add_option('h', "help", "prints_help", [&]() {

0 commit comments

Comments
 (0)