setup: a four-part hotfix version cannot break the version code

Versions are read as their first three numbers everywhere; the one place that was not (the version compiled
into an engine binary, `engine=0.1.40.1`) now accepts an optional fourth number. A test pins that a hotfix
tag keeps finding the engine zips: the checkout's v<project version> release first, the latest release second.
This commit is contained in:
Niko1221 committed 2026-10-06 10:03:35 +02:00
1 parent 57a69eb48f
commit 511b646783
2 files changed
+48 -1

No files matched your search

+1 -1
View File
@@ -3319,7 +3319,7 @@ def engine_version(exe: Path) -> tuple:
v = str(meta.get("version") or "")
if not v: # the version compiled into the binary: 0.1.13 and newer
try: # carry it, so a binary without it is older
m = re.search(rb"engine=(\d+\.\d+\.\d+)\n", Path(exe).read_bytes())
m = re.search(rb"engine=(\d+\.\d+\.\d+)(?:\.\d+)?\n", Path(exe).read_bytes())
v = m.group(1).decode() if m else "0.1.12"
except OSError:
v = "0"
+47
View File
@@ -0,0 +1,47 @@
"""A four-part hotfix version (0.1.40.1) cannot break setup: versions are read as their first three numbers, the
engine zips are looked for under the checkout's own v<project version> tag first and the latest release second, and
a binary that says `engine=0.1.40.1` is read as 0.1.40.
python -m unittest tools.test_setup_hotfix_tag
"""
from __future__ import annotations
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "tools"))
import setup # noqa: E402
class HotfixTag(unittest.TestCase):
def test_a_four_part_version_is_read_as_its_first_three_numbers(self):
ver = tuple(int(x) for x in "0.1.40.1".split(".")[:3] if x.isdigit())
self.assertEqual(ver, (0, 1, 40))
self.assertGreaterEqual(ver, setup.MIN_ENGINE)
def test_the_engine_zips_are_found_for_a_hotfix_tag(self):
# a hotfix that keeps CMakeLists.txt at the engine's version: the v0.1.40 release still holds the zips
bases = setup.prebuilt_bases(setup.PREBUILT_URL)
self.assertEqual(bases[0], setup.PREBUILT_TAG_URL.format(version=setup.source_version()))
self.assertEqual(bases[-1], setup.PREBUILT_URL)
# and if a four-part project version ever exists, its tag is tried first, the latest release is the fallback
with mock.patch.object(setup, "source_version", return_value="0.1.40.1"):
self.assertEqual(setup.prebuilt_bases(setup.PREBUILT_URL),
["https://github.com/Niko1221/Strata/releases/download/v0.1.40.1/", setup.PREBUILT_URL])
def test_an_engine_that_says_four_parts_is_read_as_three(self):
with tempfile.TemporaryDirectory() as d:
exe = Path(d) / "strata.exe"
exe.write_bytes(b"MZ\x00engine=0.1.40.1\n\x00")
self.assertEqual(setup.engine_version(exe), (0, 1, 40))
exe.write_bytes(b"MZ\x00engine=0.1.40\n\x00")
self.assertEqual(setup.engine_version(exe), (0, 1, 40))
if __name__ == "__main__":
unittest.main()