inject git info for clickhouse-client clickhouse-server

This commit is contained in:
taiyang-li 2021-12-22 11:19:21 +08:00
parent b84591d17a
commit 98c620cfac
4 changed files with 76 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include <base/find_symbols.h>
#include <Common/config_version.h>
#include <Common/git_info.h>
#include <Common/Exception.h>
#include <Common/formatReadable.h>
#include <Common/TerminalSize.h>
@ -76,6 +77,13 @@ namespace ErrorCodes
extern const int AUTHENTICATION_FAILED;
}
namespace GitInfo
{
extern const std::string GIT_SHA1;
extern const std::string GIT_BRANCH;
extern const std::string GIT_DATE;
extern const std::string GIT_COMMIT_SUBJECT;
}
void Client::processError(const String & query) const
{
@ -1143,6 +1151,14 @@ void Client::processOptions(const OptionsDescription & options_description,
global_context->getClientInfo().client_trace_context.tracestate = options["opentelemetry-tracestate"].as<std::string>();
}
static void showClientVersion()
{
std::cout << DBMS_NAME << " client version " << VERSION_STRING << VERSION_OFFICIAL << "." << std::endl;
std::cout << "GIT SHA1: " << GitInfo::GIT_SHA1 << std::endl;
std::cout << "GIT BRANCH: " << GitInfo::GIT_BRANCH << std::endl;
std::cout << "GIT DATE: " << GitInfo::GIT_DATE << std::endl;
std::cout << "GIT COMMIT SUBJECT: " << GitInfo::GIT_COMMIT_SUBJECT << std::endl;
}
void Client::processConfig()
{

View File

@ -84,6 +84,7 @@
#include "config_core.h"
#include "Common/config_version.h"
#include "Common/git_info.h"
#if defined(OS_LINUX)
# include <sys/mman.h>
@ -127,6 +128,14 @@ namespace CurrentMetrics
extern const Metric MaxPushedDDLEntryID;
}
namespace GitInfo
{
extern const std::string GIT_SHA1;
extern const std::string GIT_BRANCH;
extern const std::string GIT_DATE;
extern const std::string GIT_COMMIT_SUBJECT;
}
namespace fs = std::filesystem;
#if USE_JEMALLOC
@ -396,6 +405,10 @@ int Server::run()
if (config().hasOption("version"))
{
std::cout << DBMS_NAME << " server version " << VERSION_STRING << VERSION_OFFICIAL << "." << std::endl;
std::cout << "GIT SHA1: " << GitInfo::GIT_SHA1 << std::endl;
std::cout << "GIT BRANCH: " << GitInfo::GIT_BRANCH << std::endl;
std::cout << "GIT DATE: " << GitInfo::GIT_DATE << std::endl;
std::cout << "GIT COMMIT SUBJECT: " << GitInfo::GIT_COMMIT_SUBJECT << std::endl;
return 0;
}
return Application::run(); // NOLINT

View File

@ -20,6 +20,7 @@ include(../cmake/limit_jobs.cmake)
set (CONFIG_VERSION "${CMAKE_CURRENT_BINARY_DIR}/Common/config_version.h")
set (CONFIG_COMMON "${CMAKE_CURRENT_BINARY_DIR}/Common/config.h")
set (GIT_INFO "${CMAKE_CURRENT_BINARY_DIR}/Common/git_info.h")
include (../cmake/version.cmake)
message (STATUS "Will build ${VERSION_FULL} revision ${VERSION_REVISION} ${VERSION_OFFICIAL}")
@ -27,6 +28,33 @@ configure_file (Common/config.h.in ${CONFIG_COMMON})
configure_file (Common/config_version.h.in ${CONFIG_VERSION})
configure_file (Core/config_core.h.in "${CMAKE_CURRENT_BINARY_DIR}/Core/include/config_core.h")
set(GIT_EXECUTABLE /usr/bin/git)
# the commit's SHA1, and whether the building workspace was dirty or not
execute_process(COMMAND
"${GIT_EXECUTABLE}" rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# git branch name
execute_process(COMMAND
"${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# the date of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%ad --date=local
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# the subject of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%s
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_SUBJECT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
configure_file (Common/git_info.h.in ${GIT_INFO})
if (USE_DEBUG_HELPERS)
get_target_property(MAGIC_ENUM_INCLUDE_DIR magic_enum INTERFACE_INCLUDE_DIRECTORIES)
set (INCLUDE_DEBUG_HELPERS "-I\"${ClickHouse_SOURCE_DIR}/base\" -I\"${MAGIC_ENUM_INCLUDE_DIR}\" -include \"${ClickHouse_SOURCE_DIR}/src/Core/iostream_debug_helpers.h\"")

19
src/Common/git_info.h.in Normal file
View File

@ -0,0 +1,19 @@
#pragma once
// .h autogenerated by cmake!
#include <string>
namespace DB
{
namespace GitInfo
{
const std::string GIT_SHA1 = "@GIT_SHA1@";
const std::string GIT_BRANCH = "@GIT_BRANCH@";
const std::string GIT_DATE = "@GIT_DATE@";
const std::string GIT_COMMIT_SUBJECT = "@GIT_COMMIT_SUBJECT@";
}
}