Skip to content

Commit

Permalink
alternative approach
Browse files Browse the repository at this point in the history
  • Loading branch information
borg323 committed May 18, 2020
1 parent 2959920 commit dfe1fbc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
11 changes: 8 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ if git.found()
# Now let's check if the working directory is clean.
if run_command(git, 'diff-index', '--quiet', 'HEAD').returncode() == 0
short_rev = r.stdout().strip()
if run_command(git, 'describe', '--exact-match', '--tags').returncode() == 0
short_rev = ''
endif
else
short_rev = 'dirty'
warning('Cannot extract valid git short revision from dirty working directory.')
Expand All @@ -109,9 +112,11 @@ if git.found()
endif

# Construct build identifier.
build_identifier = 'git.' + short_rev
add_project_arguments('-DBUILD_IDENTIFIER="' + build_identifier + '"', language : 'cpp')
message('Using build identifier "' + build_identifier + '".')
if short_rev != ''
build_identifier = 'git.' + short_rev
add_project_arguments('-DBUILD_IDENTIFIER="' + build_identifier + '"', language : 'cpp')
message('Using build identifier "' + build_identifier + '".')
endif

#############################################################################
## Main files
Expand Down
2 changes: 1 addition & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, const char** argv) {
CERR << EscCodes::Bold() << EscCodes::Red() << " _";
CERR << "| _ | |";
CERR << "|_ |_ |_|" << EscCodes::Reset() << " v" << GetVersionStr()
<< '+' << BUILD_IDENTIFIER << " built " << __DATE__;
<< " built " << __DATE__;

try {
InitializeMagicBitboards();
Expand Down
2 changes: 1 addition & 1 deletion src/neural/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ WeightsFile ParseWeightsProto(const std::string& buffer) {

const auto min_version =
GetVersionStr(net.min_version().major(), net.min_version().minor(),
net.min_version().patch(), "");
net.min_version().patch(), "", "");
const auto lc0_ver = GetVersionInt();
const auto net_ver =
GetVersionInt(net.min_version().major(), net.min_version().minor(),
Expand Down
8 changes: 5 additions & 3 deletions src/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ std::uint32_t GetVersionInt(int major, int minor, int patch) {
}

std::string GetVersionStr(int major, int minor, int patch,
const std::string& postfix) {
const std::string& postfix,
const std::string& build_id) {
auto v = std::to_string(major) + "." + std::to_string(minor) + "." +
std::to_string(patch);
if (postfix.empty()) return v;
return v + "-" + postfix;
if (!postfix.empty()) v += "-" + postfix;
if (!build_id.empty()) v += "+" + build_id;
return v;
}
7 changes: 6 additions & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
#include <string>
#include "version.inc"

#ifndef BUILD_IDENTIFIER
#define BUILD_IDENTIFIER ""
#endif

std::uint32_t GetVersionInt(int major = LC0_VERSION_MAJOR,
int minor = LC0_VERSION_MINOR,
int patch = LC0_VERSION_PATCH);

std::string GetVersionStr(int major = LC0_VERSION_MAJOR,
int minor = LC0_VERSION_MINOR,
int patch = LC0_VERSION_PATCH,
const std::string& postfix = LC0_VERSION_POSTFIX);
const std::string& postfix = LC0_VERSION_POSTFIX,
const std::string& build_id = BUILD_IDENTIFIER);

0 comments on commit dfe1fbc

Please sign in to comment.