diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c638cb2d41..a0b498b27e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,6 +432,23 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in ${CMAKE_BINARY_DIR}/include/mysql_version.h ) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in ${CMAKE_BINARY_DIR}/sql/sql_builtin.cc) + +FIND_PACKAGE(Git) +IF(GIT_EXECUTABLE) + EXECUTE_PROCESS( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE OUT RESULT_VARIABLE RES) + IF(RES EQUAL 0) + STRING(REGEX REPLACE "\n$" "" SOURCE_REVISION "${OUT}") + ENDIF() +ENDIF() +IF(SOURCE_REVISION OR + (NOT EXISTS ${PROJECT_SOURCE_DIR}/include/source_revision.h)) + CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/include/source_revision.h.in + ${PROJECT_BINARY_DIR}/include/source_revision.h ) +ENDIF() + CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/cmake/info_macros.cmake.in ${CMAKE_BINARY_DIR}/info_macros.cmake @ONLY) diff --git a/client/mysql.cc b/client/mysql.cc index f2e7b9150fa..10601e36f64 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -40,7 +40,7 @@ #include "my_readline.h" #include #include - +#include #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H) #include #endif @@ -1721,8 +1721,8 @@ static void usage(int version) my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE, readline, rl_library_version); #else - printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, VER, - MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); + printf("%s Ver %s Distrib %s, for %s (%s), source revision %s\n", my_progname, VER, + MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,SOURCE_REVISION); #endif if (version) diff --git a/cmake/make_dist.cmake.in b/cmake/make_dist.cmake.in index 3cc93d10fb8..6bd71cc7653 100644 --- a/cmake/make_dist.cmake.in +++ b/cmake/make_dist.cmake.in @@ -52,6 +52,9 @@ IF(GIT_EXECUTABLE) ENDIF() ENDIF() +CONFIGURE_FILE(${CMAKE_BINARY_DIR}/include/source_revision.h + ${PACKAGE_DIR}/include/source_revision.h COPYONLY) + IF(NOT GIT_EXECUTABLE) MESSAGE(STATUS "git not found or source dir is not a repo, use CPack") diff --git a/include/source_revision.h.in b/include/source_revision.h.in new file mode 100644 index 00000000000..5b657d0940e --- /dev/null +++ b/include/source_revision.h.in @@ -0,0 +1 @@ +#cmakedefine SOURCE_REVISION "@SOURCE_REVISION@" diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 8a800017c1e..c123d60ccb3 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3503,6 +3503,14 @@ static Sys_var_charptr Sys_version_compile_os( CMD_LINE_HELP_ONLY, IN_SYSTEM_CHARSET, DEFAULT(SYSTEM_TYPE)); +#include +static char *server_version_source_revision; +static Sys_var_charptr Sys_version_source_revision( + "version_source_revision", "´Revision of the MariaDB source code", + READ_ONLY GLOBAL_VAR(server_version_source_revision), + CMD_LINE_HELP_ONLY, + IN_SYSTEM_CHARSET, DEFAULT(SOURCE_REVISION)); + static char *guess_malloc_library() { if (strcmp(MALLOC_LIBRARY, "system") == 0)