mergerfs/tests/TEST_release_pkg_preservation

126 lines
4.4 KiB
Text
Raw Normal View History

build: make NDEBUG=1 and make release build the release profile - The RELEASE=1 profile replaced 2.42.0's NDEBUG=1 one, but the static archives and the container image still build with NDEBUG=1, which therefore selected the debug profile: -O0 -g3 with assertions on. Both Makefiles accept NDEBUG=1 again, as -O3 -DNDEBUG, and the debug profile defines DEBUG. The vendored libfuse follows the same profile as mergerfs. - make release first removes the objects, binaries and stamp under build/ and cleans vendored/libfuse, because make only compares timestamps: objects from an earlier debug build were otherwise linked into the release binary unchanged. Packages and build reports in build/pkgs are kept; TEST_release_pkg_preservation checks both. - make release also builds preload.so. It takes the release defines through its own PRELOAD_CPPFLAGS: the global CPPFLAGS add _FILE_OFFSET_BITS=64, which would hide its unsuffixed open/openat/fopen/creat interposers. - mergerfs.spec builds the release target, as debian/rules does. The distribution's CFLAGS, CXXFLAGS and LDFLAGS still apply. - The release driver mounts the repository with ":ro,z", not ":ro:z", which Podman read as an extra field instead of a mount option. TEST_release_metadata runs the driver against a fake podman and checks the volume argument and the build report. - Remove release-installer: build-release has no installer target. - make help printed a literal "\n" where /bin/sh is bash. Match the build.md transcript to its output and document the profiles. Performance: static archives and the container image go from -O0 with assertions back to optimized builds, now -O3 -DNDEBUG (2.42.0: -O2 -DNDEBUG). RPM packages keep the distribution's -O2 and no longer evaluate assertions. A plain make is unoptimized, as before.
2026-11-29 23:10:53 -05:00
#!/usr/bin/env python3
"""make release preserves packages and rebuilds the release profile.
Copies the repository Makefile over a minimal scratch fixture tree
(one tiny source, a stub vendored libfuse following the repo's
BUILDDIR conventions) and drives the real plain and release targets.
The fixture binary prints "debug" or "release" chosen by #ifdef
NDEBUG, so the profile flip is observed from the built executable;
packages staged like an earlier build leaves them (default build/pkgs,
a custom PKGDIR under build, one outside build) must survive
byte-for-byte.
"""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SENTINELS = (
"build/pkgs/mergerfs_1.0.0_amd64.deb",
"build/pkgs/build-report.txt",
"build/pkgs-custom/mergerfs_1.0.0_amd64.deb",
"pkgdir-elsewhere/mergerfs_1.0.0_amd64.deb",
)
FIXTURE_CPP = (
"#include <cstdio>\n"
"int\n"
"main()\n"
"{\n"
"#ifdef NDEBUG\n"
" std::puts(\"release\");\n"
"#else\n"
" std::puts(\"debug\");\n"
"#endif\n"
" return 0;\n"
"}\n"
)
LIBFUSE_MAKEFILE = (
"BUILDDIR := build\n"
"ARCHIVE := $(BUILDDIR)/libfuse.a\n"
".PHONY: all clean\n"
"all: $(ARCHIVE)\n"
"$(ARCHIVE):\n"
"\tmkdir -p $(BUILDDIR)\n"
"\tar rcs $@\n"
"clean:\n"
"\trm -rf $(BUILDDIR)\n"
)
class ReleasePkgPreservationTests(unittest.TestCase):
def setUp(self):
tmp = tempfile.mkdtemp(prefix="mergerfs-release-pkg-")
self.addCleanup(shutil.rmtree, tmp, ignore_errors=True)
self.fixture = Path(tmp) / "tree"
(self.fixture / "src").mkdir(parents=True)
(self.fixture / "vendored" / "libfuse").mkdir(parents=True)
(self.fixture / "tools").mkdir()
shutil.copy(ROOT / "Makefile", self.fixture / "Makefile")
self.write("src/version.hpp",
'#define MERGERFS_VERSION "0.0.0-fixture"\n')
self.write("src/fixture.cpp", FIXTURE_CPP)
self.write("tools/preload.c",
"void mergerfs_fixture_preload(void)\n{\n}\n")
self.write("vendored/libfuse/Makefile", LIBFUSE_MAKEFILE)
for rel in SENTINELS:
path = self.fixture / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes((rel + "\n").encode("ascii") * 8)
self.run_make()
def write(self, relpath, content):
path = self.fixture / relpath
path.write_text(content, encoding="ascii")
return path
def run_make(self, *args):
env = os.environ.copy()
for key in ("MAKEFLAGS", "MFLAGS", "CC", "CXX", "CFLAGS",
"CXXFLAGS", "CPPFLAGS", "LDFLAGS", "NDEBUG",
"RELEASE", "LTO", "STATIC", "SANITIZE", "PKGDIR"):
env.pop(key, None)
make = shutil.which("gmake") or "make"
proc = subprocess.run([make, "-C", str(self.fixture)] + list(args),
env=env, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, text=True, timeout=50)
self.assertEqual(proc.returncode, 0,
msg="make {} failed:\n{}".format(
" ".join(args) or "(default)", proc.stdout))
def run_binary(self, relpath):
proc = subprocess.run([str(self.fixture / relpath)],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True, timeout=10)
self.assertEqual(proc.returncode, 0, msg=proc.stdout)
return proc.stdout.strip()
def test_release_preserves_packages_and_flips_profile(self):
self.assertEqual(self.run_binary("build/mergerfs"), "debug")
sentinels = {rel: (self.fixture / rel).read_bytes()
for rel in SENTINELS}
self.run_make("release")
for rel in SENTINELS:
self.assertEqual((self.fixture / rel).read_bytes(),
sentinels[rel],
msg="make release changed {}".format(rel))
self.assertEqual(self.run_binary("build/mergerfs"), "release",
msg="make release did not rebuild with NDEBUG")
self.assertTrue((self.fixture / "build/preload.so").exists(),
"make release did not build preload.so")
if __name__ == "__main__":
unittest.main()