diff --git a/CMakeLists.txt b/CMakeLists.txt index 98af024fdaa..3dfde07d5dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,6 +153,9 @@ execute_process(COMMAND sh -c "cat src/VERSION.txt" execute_process(COMMAND git rev-parse --short HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE GIT_SHA) string(STRIP "${GIT_SHA}" GIT_SHA) +if ((PROJECT_VERSION STREQUAL "unstable") AND (GIT_SHA STREQUAL "")) + message(WARNING "It is highly recommended to build the unstable branch in a Git repo") +endif () configure_file(src/version.h.in ${PROJECT_BINARY_DIR}/version.h) if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) diff --git a/src/VERSION.txt b/src/VERSION.txt index 71e0f70dec9..76cff7f1f82 100644 --- a/src/VERSION.txt +++ b/src/VERSION.txt @@ -1 +1 @@ -999.999.999 \ No newline at end of file +unstable \ No newline at end of file diff --git a/src/main.cc b/src/main.cc index a0d657ca41f..9ae9db1e42b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -62,11 +62,26 @@ extern "C" void signalHandler(int sig) { } } +std::ostream &printVersion(std::ostream &os) { + os << "kvrocks "; + + if (VERSION != "unstable") { + os << "version "; + } + + os << VERSION; + + if (!GIT_COMMIT.empty()) { + os << " (commit " << GIT_COMMIT << ")"; + } + + return os; +} + extern "C" void segvHandler(int sig, siginfo_t *info, void *secret) { void *trace[100]; - LOG(ERROR) << "======= Ooops! kvrocks " << VERSION << " @" << GIT_COMMIT << " got signal: " << strsignal(sig) << " (" - << sig << ") ======="; + LOG(ERROR) << "======= Ooops! " << printVersion << " got signal: " << strsignal(sig) << " (" << sig << ") ======="; int trace_size = backtrace(trace, sizeof(trace) / sizeof(void *)); char **messages = backtrace_symbols(trace, trace_size); @@ -138,8 +153,6 @@ static void printUsage(const char *program) { << "overwrite specific config option to " << std::endl; } -static void printVersion(std::ostream &os) { os << "kvrocks version " << VERSION << " @" << GIT_COMMIT << std::endl; } - static CLIOptions parseCommandLineOptions(int argc, char **argv) { using namespace std::string_view_literals; CLIOptions opts; @@ -148,7 +161,7 @@ static CLIOptions parseCommandLineOptions(int argc, char **argv) { if ((argv[i] == "-c"sv || argv[i] == "--config"sv) && i + 1 < argc) { opts.conf_file = argv[++i]; } else if (argv[i] == "-v"sv || argv[i] == "--version"sv) { - printVersion(std::cout); + std::cout << printVersion << std::endl; std::exit(0); } else if (argv[i] == "-h"sv || argv[i] == "--help"sv) { printUsage(*argv); @@ -311,7 +324,7 @@ int main(int argc, char *argv[]) { } initGoogleLog(&config); - printVersion(LOG(INFO)); + LOG(INFO) << printVersion; // Tricky: We don't expect that different instances running on the same port, // but the server use REUSE_PORT to support the multi listeners. So we connect // the listen port to check if the port has already listened or not. diff --git a/src/version.h.in b/src/version.h.in index ffc9f34c36a..56f6cba16d7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -20,5 +20,7 @@ #pragma once -#define VERSION "@PROJECT_VERSION@" -#define GIT_COMMIT "@GIT_SHA@" +#include + +inline constexpr std::string_view VERSION = "@PROJECT_VERSION@"; +inline constexpr std::string_view GIT_COMMIT = "@GIT_SHA@";