Skip to content

Commit 0f37358

Browse files
committed
MDEV-12583 : Bake the git hash into the binaries.
Added version_source_revision server "variable", for the git revision. Also , mysql -V will show git revision. "make dist" will now pack source_revision.h into the source package.
1 parent f70865b commit 0f37358

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,23 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in
432432
${CMAKE_BINARY_DIR}/include/mysql_version.h )
433433
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in
434434
${CMAKE_BINARY_DIR}/sql/sql_builtin.cc)
435+
436+
FIND_PACKAGE(Git)
437+
IF(GIT_EXECUTABLE)
438+
EXECUTE_PROCESS(
439+
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
440+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
441+
OUTPUT_VARIABLE OUT RESULT_VARIABLE RES)
442+
IF(RES EQUAL 0)
443+
STRING(REGEX REPLACE "\n$" "" SOURCE_REVISION "${OUT}")
444+
ENDIF()
445+
ENDIF()
446+
IF(SOURCE_REVISION OR
447+
(NOT EXISTS ${PROJECT_SOURCE_DIR}/include/source_revision.h))
448+
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/include/source_revision.h.in
449+
${PROJECT_BINARY_DIR}/include/source_revision.h )
450+
ENDIF()
451+
435452
CONFIGURE_FILE(
436453
${CMAKE_SOURCE_DIR}/cmake/info_macros.cmake.in
437454
${CMAKE_BINARY_DIR}/info_macros.cmake @ONLY)

client/mysql.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "my_readline.h"
4141
#include <signal.h>
4242
#include <violite.h>
43-
43+
#include <source_revision.h>
4444
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
4545
#include <locale.h>
4646
#endif
@@ -1721,8 +1721,8 @@ static void usage(int version)
17211721
my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
17221722
readline, rl_library_version);
17231723
#else
1724-
printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, VER,
1725-
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
1724+
printf("%s Ver %s Distrib %s, for %s (%s), source revision %s\n", my_progname, VER,
1725+
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,SOURCE_REVISION);
17261726
#endif
17271727

17281728
if (version)

cmake/make_dist.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ IF(GIT_EXECUTABLE)
5252
ENDIF()
5353
ENDIF()
5454

55+
CONFIGURE_FILE(${CMAKE_BINARY_DIR}/include/source_revision.h
56+
${PACKAGE_DIR}/include/source_revision.h COPYONLY)
57+
5558
IF(NOT GIT_EXECUTABLE)
5659
MESSAGE(STATUS "git not found or source dir is not a repo, use CPack")
5760

include/source_revision.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#cmakedefine SOURCE_REVISION "@SOURCE_REVISION@"

sql/sys_vars.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,6 +3503,14 @@ static Sys_var_charptr Sys_version_compile_os(
35033503
CMD_LINE_HELP_ONLY,
35043504
IN_SYSTEM_CHARSET, DEFAULT(SYSTEM_TYPE));
35053505

3506+
#include <source_revision.h>
3507+
static char *server_version_source_revision;
3508+
static Sys_var_charptr Sys_version_source_revision(
3509+
"version_source_revision", "�Revision of the MariaDB source code",
3510+
READ_ONLY GLOBAL_VAR(server_version_source_revision),
3511+
CMD_LINE_HELP_ONLY,
3512+
IN_SYSTEM_CHARSET, DEFAULT(SOURCE_REVISION));
3513+
35063514
static char *guess_malloc_library()
35073515
{
35083516
if (strcmp(MALLOC_LIBRARY, "system") == 0)

0 commit comments

Comments
 (0)