Integrate version metadata into build. Fixes #46.

This commit is contained in:
Roman Gershman 2022-05-30 08:49:16 +03:00
parent bb7b205bff
commit 4d276c7ef0
10 changed files with 109 additions and 34 deletions

View File

@ -16,27 +16,10 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/helio/cmake" ${CMAKE_MODULE_P
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
include(third_party)
message(STATUS "after thirdpary")
include(internal)
add_third_party(
lua
URL https://github.com/lua/lua/archive/refs/tags/v5.4.4.tar.gz
PATCH_COMMAND patch -p1 -i "${CMAKE_CURRENT_SOURCE_DIR}/patches/lua-v5.4.4.patch"
CONFIGURE_COMMAND echo
BUILD_IN_SOURCE 1
INSTALL_COMMAND cp <SOURCE_DIR>/liblua.a ${THIRD_PARTY_LIB_DIR}/lua/lib/
COMMAND cp <SOURCE_DIR>/lualib.h <SOURCE_DIR>/lua.h <SOURCE_DIR>/lauxlib.h
<SOURCE_DIR>/luaconf.h ${THIRD_PARTY_LIB_DIR}/lua/include
)
add_third_party(
dconv
URL https://github.com/google/double-conversion/archive/refs/tags/v3.2.0.tar.gz
LIB libdouble-conversion.a
)
Message(STATUS "THIRD_PARTY_LIB_DIR ${THIRD_PARTY_LIB_DIR}")
include_directories(src)
include_directories(helio)

1
src/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
server/version.cc

View File

@ -1,3 +1,47 @@
add_third_party(
lua
URL https://github.com/lua/lua/archive/refs/tags/v5.4.4.tar.gz
PATCH_COMMAND patch -p1 -i "${CMAKE_SOURCE_DIR}/patches/lua-v5.4.4.patch"
CONFIGURE_COMMAND echo
BUILD_IN_SOURCE 1
INSTALL_COMMAND cp <SOURCE_DIR>/liblua.a ${THIRD_PARTY_LIB_DIR}/lua/lib/
COMMAND cp <SOURCE_DIR>/lualib.h <SOURCE_DIR>/lua.h <SOURCE_DIR>/lauxlib.h
<SOURCE_DIR>/luaconf.h ${THIRD_PARTY_LIB_DIR}/lua/include
)
add_third_party(
dconv
URL https://github.com/google/double-conversion/archive/refs/tags/v3.2.0.tar.gz
LIB libdouble-conversion.a
)
Message(STATUS "THIRD_PARTY_LIB_DIR ${THIRD_PARTY_LIB_DIR}")
option(ENABLE_GIT_VERSION "Build with Git metadata" OFF)
if(ENABLE_GIT_VERSION)
MESSAGE(FATAL_ERROR "foobar")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
git_local_changes(GIT_CLEAN_DIRTY)
if("${GIT_CLEAN_DIRTY}" STREQUAL "DIRTY")
set(GIT_CLEAN_DIRTY "-dirty")
else()
set(GIT_CLEAN_DIRTY "")
endif()
git_describe(GIT_VER --always)
string(TIMESTAMP PRJ_BUILD_TIME "%Y-%m-%d %H:%M:%S" UTC)
else(ENABLE_GIT_VERSION)
set(GIT_VER "dev")
set(GIT_SHA1 "0000000")
set(GIT_CLEAN_DIRTY "-dev")
set(PRJ_BUILD_TIME "bigbang")
endif(ENABLE_GIT_VERSION)
# the output file resides in the build directory.
configure_file(server/version.cc.in "${CMAKE_CURRENT_SOURCE_DIR}/server/version.cc" @ONLY)
add_subdirectory(redis)
add_subdirectory(core)
add_subdirectory(facade)

View File

@ -8,7 +8,7 @@ add_library(dragonfly_lib blocking_controller.cc channel_slice.cc command_regist
list_family.cc main_service.cc rdb_load.cc rdb_save.cc replica.cc
snapshot.cc script_mgr.cc server_family.cc
set_family.cc string_family.cc table.cc tiered_storage.cc
transaction.cc zset_family.cc)
transaction.cc zset_family.cc version.cc)
cxx_link(dragonfly_lib dfly_core dfly_facade redis_lib strings_lib)

View File

@ -18,6 +18,7 @@
#include "facade/dragonfly_listener.h"
#include "io/proc_reader.h"
#include "server/main_service.h"
#include "server/version.h"
#include "strings/human_readable.h"
#include "util/accept_server.h"
#include "util/uring/uring_pool.h"
@ -133,12 +134,23 @@ bool RunEngine(ProactorPool* pool, AcceptServer* acceptor) {
extern "C" void _mi_options_init();
using namespace dfly;
int main(int argc, char* argv[]) {
absl::SetProgramUsageMessage("dragonfly [FLAGS]");
absl::SetProgramUsageMessage(
R"(a modern in-memory store.
Usage: dragonfly [FLAGS]
)");
absl::FlagsUsageConfig config;
config.contains_help_flags = dfly::HelpFlags;
config.contains_helpshort_flags = dfly::HelpshortFlags;
config.normalize_filename = dfly::NormalizePaths;
config.version_string = [] {
return StrCat("dragonfly ", ColoredStr(TermColor::kGreen, dfly::kGitTag),
"\nbuild time: ", dfly::kBuildTime, "\n");
};
absl::SetFlagsUsageConfig(config);

View File

@ -30,6 +30,7 @@ extern "C" {
#include "server/set_family.h"
#include "server/string_family.h"
#include "server/transaction.h"
#include "server/version.h"
#include "server/zset_family.h"
#include "util/metrics/metrics.h"
#include "util/uring/uring_fiber_algo.h"
@ -58,9 +59,10 @@ using base::VarzValue;
using ::boost::intrusive_ptr;
namespace fibers = ::boost::fibers;
namespace this_fiber = ::boost::this_fiber;
using absl::GetFlag;
using absl::StrCat;
using facade::MCReplyBuilder;
using facade::RedisReplyBuilder;
using absl::GetFlag;
namespace {
@ -382,7 +384,7 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx)
absl::Cleanup multi_error([dfly_cntx] { MultiSetError(dfly_cntx); });
if (cid == nullptr) {
(*cntx)->SendError(absl::StrCat("unknown command `", cmd_str, "`"), "unknown_cmd");
(*cntx)->SendError(StrCat("unknown command `", cmd_str, "`"), "unknown_cmd");
lock_guard lk(mu_);
if (unknown_cmds_.size() < 1024)
@ -391,7 +393,7 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx)
}
if (etl.gstate() == GlobalState::LOADING || etl.gstate() == GlobalState::SHUTTING_DOWN) {
string err = absl::StrCat("Can not execute during ", GlobalStateName(etl.gstate()));
string err = StrCat("Can not execute during ", GlobalStateName(etl.gstate()));
(*cntx)->SendError(err);
return;
}
@ -568,7 +570,7 @@ void Service::DispatchMC(const MemcacheParser::Command& cmd, std::string_view va
server_family_.StatsMC(cmd.key, cntx);
return;
case MemcacheParser::VERSION:
mc_builder->SendSimpleString(absl::StrCat("VERSION ", "TBD"));
mc_builder->SendSimpleString(StrCat("VERSION ", kGitTag));
return;
default:
mc_builder->SendClientError("bad command line format");
@ -812,7 +814,7 @@ void Service::EvalInternal(const EvalArgs& eval_args, Interpreter* interpreter,
cntx->transaction->UnlockMulti();
if (result == Interpreter::RUN_ERR) {
string resp = absl::StrCat("Error running script (call to ", eval_args.sha, "): ", error);
string resp = StrCat("Error running script (call to ", eval_args.sha, "): ", error);
return (*cntx)->SendError(resp, facade::kScriptErrType);
}
@ -967,7 +969,7 @@ void Service::Function(CmdArgList args, ConnectionContext* cntx) {
return (*cntx)->SendOk();
}
string err = absl::StrCat("Unknown subcommand '", sub_cmd, "'. Try FUNCTION HELP.");
string err = StrCat("Unknown subcommand '", sub_cmd, "'. Try FUNCTION HELP.");
return (*cntx)->SendError(err, kSyntaxErr);
}
@ -1037,7 +1039,7 @@ void Service::RegisterCommands() {
if (cid.last_key_pos() < 0)
key_len = "unlimited";
else
key_len = absl::StrCat(cid.last_key_pos() - cid.first_key_pos() + 1);
key_len = StrCat(cid.last_key_pos() - cid.first_key_pos() + 1);
LOG(INFO) << " " << key << ": with " << key_len << " keys";
}
});

View File

@ -33,6 +33,7 @@ extern "C" {
#include "server/replica.h"
#include "server/script_mgr.h"
#include "server/server_state.h"
#include "server/version.h"
#include "server/tiered_storage.h"
#include "server/transaction.h"
#include "strings/human_readable.h"
@ -290,7 +291,7 @@ void ServerFamily::StatsMC(std::string_view section, facade::ConnectionContext*
ADD_LINE(pid, getpid());
ADD_LINE(uptime, uptime);
ADD_LINE(time, now);
ADD_LINE(version, "1.6.12");
ADD_LINE(version, kGitTag);
ADD_LINE(libevent, "iouring");
ADD_LINE(pointer_size, sizeof(void*));
ADD_LINE(rusage_user, utime);

16
src/server/version.cc.in Normal file
View File

@ -0,0 +1,16 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#include "version.h"
namespace dfly {
// Do not edit - autogenerated file. Please see version.cc.in for details.
const char kGitTag[] = "@GIT_VER@";
const char kGitSha[] = "@GIT_SHA1@";
const char kGitClean[] = "@GIT_CLEAN_DIRTY@";
const char kBuildTime[] = "@PRJ_BUILD_TIME@";
} // namespace dfly

14
src/server/version.h Normal file
View File

@ -0,0 +1,14 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#pragma once
namespace dfly {
extern const char kGitTag[];
extern const char kGitSha[];
extern const char kGitClean[];
extern const char kBuildTime[];
} // namespace dfly

View File

@ -11,7 +11,9 @@ ARCH=`uname -m`
NAME="dragonfly-${ARCH}"
pwd
./helio/blaze.sh -release -DBoost_USE_STATIC_LIBS=ON -DOPENSSL_USE_STATIC_LIBS=ON
./helio/blaze.sh -release -DBoost_USE_STATIC_LIBS=ON -DOPENSSL_USE_STATIC_LIBS=ON \
-DENABLE_GIT_VERSION=ON -DWITH_UNWIND=OFF
cd build-opt
ninja dragonfly && ldd dragonfly
strip dragonfly