diff --git a/meson.build b/meson.build index 9d4343203c..3129de54df 100644 --- a/meson.build +++ b/meson.build @@ -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.') @@ -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 diff --git a/src/main.cc b/src/main.cc index 7140ce50a1..319e275bd7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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(); diff --git a/src/neural/loader.cc b/src/neural/loader.cc index 955f90033b..0d81164e34 100644 --- a/src/neural/loader.cc +++ b/src/neural/loader.cc @@ -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(), diff --git a/src/version.cc b/src/version.cc index 9c4e2d0138..d6b5a0540b 100644 --- a/src/version.cc +++ b/src/version.cc @@ -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; } diff --git a/src/version.h b/src/version.h index ee07ebb406..e713bb3c82 100644 --- a/src/version.h +++ b/src/version.h @@ -32,6 +32,10 @@ #include #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); @@ -39,4 +43,5 @@ std::uint32_t GetVersionInt(int major = LC0_VERSION_MAJOR, 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);