From 4b7f4f04e39779c3496855ea46fff565c360a4d5 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 02:14:11 +0100 Subject: Prepare a versioning mechanism for the tracker that works from tarballs --- Makefile | 5 +++-- ot_stats.c | 9 ++++++--- tests/integration/test_stats.py | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 92e911d..bf4883e 100644 --- a/Makefile +++ b/Makefile @@ -53,12 +53,13 @@ FEATURES+=-DWANT_FULLSCRAPE #FEATURES+=-D_DEBUG_HTTPERROR #FEATURES+=-D_DEBUG_RANDOMTORRENTS -GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse HEAD || echo _git_or_commit_not_found_'` +VERSION=1.0.0 +GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git describe --tags --match "v*" --always --dirty 2>/dev/null'` OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage OPTS_production=-O3 -CFLAGS+=-DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic +CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic LDFLAGS+=-pthread # Only the proxy, which has not been ported since the tracker went dual stack, diff --git a/ot_stats.c b/ot_stats.c index eb046a0..a9f12cc 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -547,9 +547,12 @@ static void stats_return_everything(char **reply, const char *reply_end) { } void stats_return_tracker_version(char **reply, const char *reply_end) { -#define QUOTE(name) #name -#define SQUOTE(name) QUOTE(name) - fmt_append(reply, reply_end, "https://erdgeist.org/gitweb/opentracker/commit/?id=" SQUOTE(GIT_VERSION) "\n"); + fmt_append(reply, reply_end, "opentracker %s", OT_VERSION); + /* Empty when the build had no git to ask, which is what a release tarball + looks like */ + if (*GIT_VERSION) + fmt_append(reply, reply_end, " (%s)", GIT_VERSION); + fmt_append(reply, reply_end, "\n"); } void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format) { diff --git a/tests/integration/test_stats.py b/tests/integration/test_stats.py index 46e9c64..7b778d3 100644 --- a/tests/integration/test_stats.py +++ b/tests/integration/test_stats.py @@ -55,9 +55,10 @@ class StatsShape(TrackerTestCase): self.assertIsNotNone(root.find("torrents/count_mutex")) self.assertIsNotNone(root.find("connections/tcp/announce")) - def test_version_names_a_commit(self): - self.assertIn(b"opentracker", self.tracker.stats("version").lower() + b"opentracker") - self.assertRegex(self.tracker.stats("version"), rb"https?://") + def test_version_names_the_release(self): + # A build from a checkout appends what git describe said, a build from + # a tarball has nothing to append, so the commit is optional here. + self.assertRegex(self.tracker.stats("version"), rb"^opentracker \d+\.\d+\.\d+( \(\S+\))?\n$") class StatsCount(TrackerTestCase): -- cgit v1.3