diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 02:14:11 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 02:14:11 +0100 |
| commit | 4b7f4f04e39779c3496855ea46fff565c360a4d5 (patch) | |
| tree | 1384de505a2a9f13480366aae553e3aa3a00a53c | |
| parent | 451947b7bed5ba6c9c925ceb10df39c42a330614 (diff) | |
Prepare a versioning mechanism for the tracker that works from tarballs
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | ot_stats.c | 9 | ||||
| -rw-r--r-- | tests/integration/test_stats.py | 7 |
3 files changed, 13 insertions, 8 deletions
| @@ -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 | ||
| 56 | GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse HEAD || echo _git_or_commit_not_found_'` | 56 | VERSION=1.0.0 |
| 57 | GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git describe --tags --match "v*" --always --dirty 2>/dev/null'` | ||
| 57 | 58 | ||
| 58 | OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage | 59 | OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage |
| 59 | OPTS_production=-O3 | 60 | OPTS_production=-O3 |
| 60 | 61 | ||
| 61 | CFLAGS+=-DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic | 62 | CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic |
| 62 | LDFLAGS+=-pthread | 63 | LDFLAGS+=-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, |
| @@ -547,9 +547,12 @@ static void stats_return_everything(char **reply, const char *reply_end) { | |||
| 547 | } | 547 | } |
| 548 | 548 | ||
| 549 | void stats_return_tracker_version(char **reply, const char *reply_end) { | 549 | void 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 | ||
| 555 | void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format) { | 558 | 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): | |||
| 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 | ||
| 63 | class StatsCount(TrackerTestCase): | 64 | class StatsCount(TrackerTestCase): |
