Skip to content
Permalink
Browse files

Add git commit to output of --version (#1951)

* Sort source/header includes in vw_core.vcxproj
* Move version code out of global_data
* Move implementation details to version.cc
* Add git commit to "--version" output
  • Loading branch information...
lokitoth committed Jun 27, 2019
1 parent cff214d commit 0e2cb41b00a6ca787939f02a778cdd7bd76c421f
@@ -21,6 +21,24 @@ file(READ version.txt PACKAGE_VERSION)
string(STRIP ${PACKAGE_VERSION} PACKAGE_VERSION)
message(STATUS "VowpalWabbit Version: ${PACKAGE_VERSION}")

# Grab git commitish into variable
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
FIND_PACKAGE(Git)
IF(GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE "vw_GIT_COMMIT"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
MESSAGE( STATUS "Git Version: ${vw_GIT_COMMIT}" )
ELSE(GIT_FOUND)
SET(vw_GIT_COMMIT "")
ENDIF(GIT_FOUND)
ELSE(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
SET(vw_GIT_COMMIT "")
ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)

include(ProcessorCount)
ProcessorCount(NumProcessors)
message(STATUS "Number of processors: ${NumProcessors}")
@@ -17,7 +17,7 @@ set(vw_install_headers
crossplat_compat.h parse_example.h floatbits.h global_data.h io_buf.h learner.h loss_functions.h
parse_primitives.h parser.h simple_label.h v_array.h vw.h vwdll.h label_parser.h multiclass.h
cost_sensitive.h cb.h v_hashmap.h memory.h vw_exception.h vw_validate.h multilabel.h constant.h
ezexample.h
ezexample.h version.h
)

set(vw_all_headers
@@ -49,7 +49,7 @@ set(vw_all_sources
active_cover.cc cs_active.cc kernel_svm.cc best_constant.cc ftrl.cc svrg.cc lrqfa.cc interact.cc
comp_io.cc interactions.cc vw_validate.cc audit_regressor.cc gen_cs_example.cc cb_explore.cc
action_score.cc cb_explore_adf.cc OjaNewton.cc baseline.cc classweight.cc
vw_exception.cc no_label.cc shared_feature_merger.cc
vw_exception.cc no_label.cc shared_feature_merger.cc version.cc
)

set(explore_all_headers
@@ -1 +1,2 @@
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
#define COMMIT_VERSION "@vw_GIT_COMMIT@"
@@ -42,112 +42,7 @@ license as described in the file LICENSE.
#include "error_reporting.h"

#include "options.h"

struct version_struct
{
int32_t major;
int32_t minor;
int32_t rev;
version_struct(int maj = 0, int min = 0, int rv = 0)
{
major = maj;
minor = min;
rev = rv;
}
version_struct(const char* v_str) { from_string(v_str); }
void operator=(version_struct v)
{
major = v.major;
minor = v.minor;
rev = v.rev;
}
version_struct(const version_struct& v)
{
major = v.major;
minor = v.minor;
rev = v.rev;
}
void operator=(const char* v_str) { from_string(v_str); }
bool operator==(version_struct v) { return (major == v.major && minor == v.minor && rev == v.rev); }
bool operator==(const char* v_str)
{
version_struct v_tmp(v_str);
return (*this == v_tmp);
}
bool operator!=(version_struct v) { return !(*this == v); }
bool operator!=(const char* v_str)
{
version_struct v_tmp(v_str);
return (*this != v_tmp);
}
bool operator>=(version_struct v)
{
if (major < v.major)
return false;
if (major > v.major)
return true;
if (minor < v.minor)
return false;
if (minor > v.minor)
return true;
if (rev >= v.rev)
return true;
return false;
}
bool operator>=(const char* v_str)
{
version_struct v_tmp(v_str);
return (*this >= v_tmp);
}
bool operator>(version_struct v)
{
if (major < v.major)
return false;
if (major > v.major)
return true;
if (minor < v.minor)
return false;
if (minor > v.minor)
return true;
if (rev > v.rev)
return true;
return false;
}
bool operator>(const char* v_str)
{
version_struct v_tmp(v_str);
return (*this > v_tmp);
}
bool operator<=(version_struct v) { return !(*this > v); }
bool operator<=(const char* v_str)
{
version_struct v_tmp(v_str);
return (*this <= v_tmp);
}
bool operator<(version_struct v) { return !(*this >= v); }
bool operator<(const char* v_str)
{
version_struct v_tmp(v_str);
return (*this < v_tmp);
}
std::string to_string() const
{
char v_str[128];
sprintf_s(v_str, sizeof(v_str), "%d.%d.%d", major, minor, rev);
std::string s = v_str;
return s;
}
void from_string(const char* str)
{
#ifdef _WIN32
sscanf_s(str, "%d.%d.%d", &major, &minor, &rev);
#else
std::sscanf(str, "%d.%d.%d", &major, &minor, &rev);
#endif
}
};

const version_struct version(PACKAGE_VERSION);
#include "version.h"

typedef float weight;

@@ -498,7 +393,7 @@ struct vw
bool preserve_performance_counters;
std::string id;

version_struct model_file_ver;
VW::version_struct model_file_ver;
double normalized_sum_norm_x;
bool vw_is_main = false; // true if vw is executable; false in library mode

@@ -368,7 +368,7 @@ void parse_diagnostics(options_i& options, vw& all)
// Upon direct query for version -- spit it out to stdout
if (version_arg)
{
cout << version.to_string() << "\n";
cout << VW::version.to_string() << " (git commit: " << VW::git_commit << ")\n";
exit(0);
}

@@ -196,10 +196,10 @@ void save_load_header(
{
size_t bytes_read_write = 0;

uint32_t v_length = (uint32_t)version.to_string().length() + 1;
uint32_t v_length = (uint32_t)VW::version.to_string().length() + 1;
stringstream msg;
msg << "Version " << version.to_string() << "\n";
memcpy(buff2, version.to_string().c_str(), min(v_length, buf2_size));
msg << "Version " << VW::version.to_string() << "\n";
memcpy(buff2, VW::version.to_string().c_str(), min(v_length, buf2_size));
if (read)
{
v_length = (uint32_t)buf2_size;
@@ -101,8 +101,8 @@ uint32_t cache_numbits(io_buf* buf, int filepointer)

std::vector<char> t(v_length);
buf->read_file(filepointer, t.data(), v_length);
version_struct v_tmp(t.data());
if (v_tmp != version)
VW::version_struct v_tmp(t.data());
if (v_tmp != VW::version)
{
// cout << "cache has possibly incompatible version, rebuilding" << endl;
return 0;
@@ -248,10 +248,10 @@ void make_write_cache(vw& all, string& newname, bool quiet)
return;
}

size_t v_length = (uint64_t)version.to_string().length() + 1;
size_t v_length = (uint64_t)VW::version.to_string().length() + 1;

output->write_file(f, &v_length, sizeof(v_length));
output->write_file(f, version.to_string().c_str(), v_length);
output->write_file(f, VW::version.to_string().c_str(), v_length);
output->write_file(f, "c", 1);
output->write_file(f, &all.num_bits, sizeof(all.num_bits));

@@ -0,0 +1,139 @@
#include "version.h"

#include <cstdio>

namespace VW {
version_struct::version_struct(int maj, int min, int rv)
{
major = maj;
minor = min;
rev = rv;
}

version_struct::version_struct(const char* v_str)
{
from_string(v_str);
}

version_struct::version_struct(const version_struct& v)
{
major = v.major;
minor = v.minor;
rev = v.rev;
}

void version_struct::operator=(const version_struct& v)
{
major = v.major;
minor = v.minor;
rev = v.rev;
}

void version_struct::operator=(const char* v_str)
{
from_string(v_str);
}

bool version_struct::operator==(const version_struct& v) const
{
return (major == v.major && minor == v.minor && rev == v.rev);
}

bool version_struct::operator==(const char* v_str) const
{
version_struct v_tmp(v_str);
return (*this == v_tmp);
}

bool version_struct::operator!=(const version_struct& v) const
{
return !(*this == v);
}

bool version_struct::operator!=(const char* v_str) const
{
return !(*this == v_str);
}

bool version_struct::operator>=(const version_struct& v) const
{
if (major < v.major)
return false;
if (major > v.major)
return true;
if (minor < v.minor)
return false;
if (minor > v.minor)
return true;
if (rev >= v.rev)
return true;
return false;
}

bool version_struct::operator>=(const char* v_str) const
{
version_struct v_tmp(v_str);
return (*this >= v_tmp);
}

bool version_struct::operator>(const version_struct& v) const
{
if (major < v.major)
return false;
if (major > v.major)
return true;
if (minor < v.minor)
return false;
if (minor > v.minor)
return true;
if (rev > v.rev)
return true;
return false;
}

bool version_struct::operator>(const char* v_str) const
{
version_struct v_tmp(v_str);
return (*this > v_tmp);
}

bool version_struct::operator<=(const version_struct& v) const
{
return !(*this > v);
}

bool version_struct::operator<=(const char* v_str) const
{
return !(*this > v_str);
}

bool version_struct::operator<(const version_struct& v) const
{
return !(*this >= v);
}

bool version_struct::operator<(const char* v_str) const
{
return !(*this >= v_str);
}

std::string version_struct::to_string() const
{
// int32_t has up to 10 digits, base-10.
// 3 * 30 + 2 = 92 => 128
char v_str[128];

std::snprintf(v_str, sizeof(v_str), "%d.%d.%d", major, minor, rev);
std::string s = v_str;
return s;
}

void version_struct::from_string(const char* str)
{
#ifdef _WIN32
sscanf_s(str, "%d.%d.%d", &major, &minor, &rev);
#else
std::sscanf(str, "%d.%d.%d", &major, &minor, &rev);
#endif
}
}

0 comments on commit 0e2cb41

Please sign in to comment.
You can’t perform that action at this time.