summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-02 02:14:11 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-02 02:14:11 +0100
commit4b7f4f04e39779c3496855ea46fff565c360a4d5 (patch)
tree1384de505a2a9f13480366aae553e3aa3a00a53c
parent451947b7bed5ba6c9c925ceb10df39c42a330614 (diff)
Prepare a versioning mechanism for the tracker that works from tarballs
-rw-r--r--Makefile5
-rw-r--r--ot_stats.c9
-rw-r--r--tests/integration/test_stats.py7
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
53#FEATURES+=-D_DEBUG_HTTPERROR 53#FEATURES+=-D_DEBUG_HTTPERROR
54#FEATURES+=-D_DEBUG_RANDOMTORRENTS 54#FEATURES+=-D_DEBUG_RANDOMTORRENTS
55 55
56GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse HEAD || echo _git_or_commit_not_found_'` 56VERSION=1.0.0
57GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git describe --tags --match "v*" --always --dirty 2>/dev/null'`
57 58
58OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage 59OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
59OPTS_production=-O3 60OPTS_production=-O3
60 61
61CFLAGS+=-DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic 62CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic
62LDFLAGS+=-pthread 63LDFLAGS+=-pthread
63 64
64# Only the proxy, which has not been ported since the tracker went dual stack, 65# 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) {
547} 547}
548 548
549void stats_return_tracker_version(char **reply, const char *reply_end) { 549void stats_return_tracker_version(char **reply, const char *reply_end) {
550#define QUOTE(name) #name 550 fmt_append(reply, reply_end, "opentracker %s", OT_VERSION);
551#define SQUOTE(name) QUOTE(name) 551 /* Empty when the build had no git to ask, which is what a release tarball
552 fmt_append(reply, reply_end, "https://erdgeist.org/gitweb/opentracker/commit/?id=" SQUOTE(GIT_VERSION) "\n"); 552 looks like */
553 if (*GIT_VERSION)
554 fmt_append(reply, reply_end, " (%s)", GIT_VERSION);
555 fmt_append(reply, reply_end, "\n");
553} 556}
554 557
555void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format) { 558void 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):
55 self.assertIsNotNone(root.find("torrents/count_mutex")) 55 self.assertIsNotNone(root.find("torrents/count_mutex"))
56 self.assertIsNotNone(root.find("connections/tcp/announce")) 56 self.assertIsNotNone(root.find("connections/tcp/announce"))
57 57
58 def test_version_names_a_commit(self): 58 def test_version_names_the_release(self):
59 self.assertIn(b"opentracker", self.tracker.stats("version").lower() + b"opentracker") 59 # A build from a checkout appends what git describe said, a build from
60 self.assertRegex(self.tracker.stats("version"), rb"https?://") 60 # a tarball has nothing to append, so the commit is optional here.
61 self.assertRegex(self.tracker.stats("version"), rb"^opentracker \d+\.\d+\.\d+( \(\S+\))?\n$")
61 62
62 63
63class StatsCount(TrackerTestCase): 64class StatsCount(TrackerTestCase):