57 lines
2.7 KiB
Python
57 lines
2.7 KiB
Python
"""Check build identity refresh and source-archive handling without running Wine."""
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
|
|
projectDir = Path(__file__).resolve().parents[1]
|
|
with tempfile.TemporaryDirectory(prefix="wine-access-version-") as temporary:
|
|
sourceDir = Path(temporary) / "source"
|
|
sourceDir.mkdir()
|
|
shutil.copytree(projectDir / "cmake", sourceDir / "cmake")
|
|
(sourceDir / "VERSION").write_text("2026.10.15\n")
|
|
outputFile = Path(temporary) / "version.h"
|
|
|
|
def generate_version():
|
|
subprocess.run(["cmake", f"-DSOURCE_DIR={sourceDir}",
|
|
f"-DOUTPUT_FILE={outputFile}", "-P",
|
|
str(sourceDir / "cmake/GenerateVersion.cmake")], check=True)
|
|
return outputFile.read_text()
|
|
|
|
def git(*arguments):
|
|
return subprocess.check_output(["git", "-C", str(sourceDir), *arguments],
|
|
text=True, stderr=subprocess.PIPE).strip()
|
|
|
|
assert 'WINE_ACCESS_REVISION "unavailable"' in generate_version()
|
|
git("init", "--quiet")
|
|
git("config", "user.name", "Fixture Author")
|
|
git("config", "user.email", "author@example.invalid")
|
|
git("add", ".")
|
|
git("-c", "commit.gpgsign=false", "commit", "--quiet", "-m", "Initial fixture")
|
|
firstRevision = git("rev-parse", "--short=12", "HEAD")
|
|
cleanHeader = generate_version()
|
|
assert firstRevision in cleanHeader and 'WINE_ACCESS_MODIFIED "false"' in cleanHeader
|
|
unchangedTime = outputFile.stat().st_mtime_ns
|
|
assert generate_version() == cleanHeader
|
|
assert outputFile.stat().st_mtime_ns == unchangedTime, "unchanged build rewrote version header"
|
|
(sourceDir / "VERSION").write_text("2026.10.16\n")
|
|
dirtyHeader = generate_version()
|
|
assert 'WINE_ACCESS_VERSION "2026.10.16"' in dirtyHeader
|
|
assert 'WINE_ACCESS_MODIFIED "true"' in dirtyHeader and ", modified)" in dirtyHeader
|
|
git("add", "VERSION")
|
|
git("-c", "commit.gpgsign=false", "commit", "--quiet", "-m", "Updated fixture")
|
|
secondRevision = git("rev-parse", "--short=12", "HEAD")
|
|
assert secondRevision != firstRevision
|
|
assert secondRevision in generate_version(), "incremental identity retained previous commit"
|
|
(sourceDir / "untracked.txt").write_text("fixture\n")
|
|
assert 'WINE_ACCESS_MODIFIED "true"' in generate_version()
|
|
# An archive nested inside another repository must not borrow its identity.
|
|
archiveDir = sourceDir / "archive"
|
|
archiveDir.mkdir()
|
|
shutil.copytree(projectDir / "cmake", archiveDir / "cmake")
|
|
(archiveDir / "VERSION").write_text("2026.10.15\n")
|
|
sourceDir = archiveDir
|
|
assert 'WINE_ACCESS_REVISION "unavailable"' in generate_version()
|
|
print("PASS: clean, modified, incremental, unchanged and archive build identities")
|