Commit 4352d9ac authored by Greg Williams's avatar Greg Williams
Browse files

Added generation of version info for lib, protocol and commit hash which gets...

Added generation of version info for lib, protocol and commit hash which gets prepended to log output. An accessor could be added to query programmatically.
parent 8ff2a7d7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ tmp/
RemoteSystemsTempFiles/

# Other local files to ignore
src/lib/kinetic_version_info.h
.tags*
*.sublime-workspace
.DS_Store
+6 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ PROJECT = kinetic-c-client
PREFIX ?= /usr/local
LIBDIR ?= /lib
LIB_DIR = ./src/lib
VERSION_INFO = $(LIB_DIR)/kinetic_version_info.h
VENDOR = ./vendor
PROTOBUFC = $(VENDOR)/protobuf-c
SOCKET99 = $(VENDOR)/socket99
@@ -101,7 +102,7 @@ LIB_OBJS = \
	$(OUT_DIR)/util.o \
	$(OUT_DIR)/yacht.o \

KINETIC_LIB_OTHER_DEPS = Makefile Rakefile $(VERSION_FILE)
KINETIC_LIB_OTHER_DEPS = Makefile Rakefile $(VERSION_FILE) $(VERSION_INFO)


default: makedirs $(KINETIC_LIB)
@@ -122,6 +123,9 @@ clean: makedirs
	cd ${LIB_DIR}/bus && make clean
	if [ -f ${JSONC}/Makefile ]; then cd ${JSONC} && make clean; fi;

$(VERSION_INFO): $(VERSION_FILE)
	@ruby scripts/generate_version_info.rb

config: makedirs update_git_submodules

update_git_submodules:
@@ -255,7 +259,7 @@ ${OUT_DIR}/libthreadpool.a: ${LIB_DIR}/threadpool/*.[ch]
KINETIC_SO_DEV = $(BIN_DIR)/lib$(KINETIC_LIB_NAME).so
KINETIC_SO_RELEASE = $(PREFIX)/lib$(KINETIC_LIB_NAME).so

$(KINETIC_LIB): $(LIB_OBJS) $(KINETIC_LIB_OTHER_DEPS) $(JSONC_LIB)
$(KINETIC_LIB): $(KINETIC_LIB_OTHER_DEPS) $(LIB_OBJS) $(JSONC_LIB)
	@echo
	@echo --------------------------------------------------------------------------------
	@echo Building static library: $(KINETIC_LIB)
+37 −0
Original line number Diff line number Diff line

kinetic_c_version = `cat config/VERSION`.strip
commit_hash = `git rev-parse HEAD`.strip
protocol_version = nil
File.readlines('src/lib/kinetic_proto.c').each do |l|
    m = l.match /^char KineticProto_local_protocol_version_default_value\[\]\s+=\s+\"(.*)\"/
    if m
        protocol_version = m[1].strip
        break
    end
end

info_header_file = "src/lib/kinetic_version_info.h"

header_contents = []
header_contents << "#ifndef _KINETIC_VERSION_INFO_H\n"
header_contents << "#define _KINETIC_VERSION_INFO_H\n"
header_contents << "#define KINETIC_C_VERSION \"#{kinetic_c_version}\"\n"
header_contents << "#define KINETIC_C_PROTOCOL_VERSION \"#{protocol_version}\"\n"
header_contents << "#define KINETIC_C_REPO_HASH \"#{commit_hash}\"\n"
header_contents << "#endif"

current_contents = File.readlines(info_header_file)

if (current_contents != header_contents)
  File.open(info_header_file, "w+") do |f|
      f.write(header_contents.join(""))
  end
  puts "Generated version info for kinetic-c"
  puts "------------------------------------"
  puts "header file:       #{info_header_file}"
  puts "kinetic-c version: #{kinetic_c_version}"
  puts "protocol version:  #{protocol_version}"
  puts "commit_hash:       #{commit_hash}"
else
  puts "Generated version info for kinetic-c is up to date!"
end
+0 −1
Original line number Diff line number Diff line
@@ -102,7 +102,6 @@ KineticStatus KineticClient_CreateSession(KineticSessionConfig* const config,
    status = KineticSession_Connect(s);
    if (status != KINETIC_STATUS_SUCCESS) {
        LOGF0("Failed creating connection to %s:%d", config->host, config->port);
        KineticSession_Destroy(s);
        KineticAllocator_FreeSession(s);
        return status;
    }
+9 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
*/

#include "kinetic_logger.h"
#include "kinetic_version_info.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@@ -47,7 +48,7 @@ static void flush_buffer(void);
static inline char* get_buffer(void);
static inline void finish_buffer(void);
static void log_protobuf_message(int log_level, const ProtobufCMessage *msg, char* indent);

static void log_version_info(void);

//------------------------------------------------------------------------------
// Public Method Definitions
@@ -78,6 +79,7 @@ void KineticLogger_Init(const char* log_file, int log_level)
            KineticLoggerHandle = fopen(log_file, "a+");
            KINETIC_ASSERT(KineticLoggerHandle != NULL);
        }
        log_version_info();
    }
}

@@ -118,6 +120,12 @@ void KineticLogger_LogPrintf(int log_level, const char* format, ...)
    finish_buffer();
}

static void log_version_info(void)
{
    KineticLogger_LogPrintf(1, "kinetic-c version: v%s (protocol: v%s, commit: %s)",
        KINETIC_C_VERSION, KINETIC_C_PROTOCOL_VERSION, KINETIC_C_REPO_HASH);
}

void KineticLogger_LogLocation(const char* filename, int line, const char* message)
{
    if (filename == NULL || message == NULL) {
Loading