build: custom makepkg config for building

During the build create a temporary config file in makepkg.conf.d
which changes some defaults.

For starters this sets the zstd compression, and bumps it for source
builds.

This allows us to make the default zstd config faster, while compressing
with a higher level in autobuild.
This commit is contained in:
Christoph Reiter 2025-08-27 08:35:38 +02:00
parent 3687fa3a0b
commit dc632d9934

View File

@ -95,6 +95,27 @@ def temp_pacman_conf(msys2_root: PathLike) -> Generator[Path, None, None]:
pass
@contextmanager
def temp_makepkg_confd(msys2_root: PathLike, config_name: str) -> Generator[Path, None, None]:
"""Gives a path to a temporary $config_name.d file"""
conf_dir = get_python_path(msys2_root, f"/etc/{config_name}.d")
os.makedirs(conf_dir, exist_ok=True)
conf_file = conf_dir / "msys2_autobuild.conf"
try:
open(conf_file, "wb").close()
yield conf_file
finally:
try:
os.unlink(conf_file)
except OSError:
pass
try:
os.rmdir(conf_dir)
except OSError:
pass
def clean_environ(environ: dict[str, str]) -> dict[str, str]:
"""Returns an environment without any CI related variables.
@ -327,6 +348,10 @@ def build_package(build_type: BuildType, pkg: Package, msys2_root: PathLike, bui
# this makes makepkg use our custom pacman script
env['PACMAN'] = str(to_pure_posix_path(temp_pacman))
if build_type == Config.MINGW_SRC_BUILD_TYPE:
with temp_makepkg_confd(msys2_root, "makepkg_mingw.conf") as makepkg_conf:
with open(makepkg_conf, "w", encoding="utf-8") as h:
h.write("COMPRESSZST=(zstd -c -T0 --ultra -22 -)\n")
env['MINGW_ARCH'] = Config.MINGW_SRC_ARCH
run_cmd(msys2_root, [
'makepkg-mingw',
@ -335,6 +360,10 @@ def build_package(build_type: BuildType, pkg: Package, msys2_root: PathLike, bui
'--allsource'
], env=env, cwd=pkg_dir)
elif build_type == Config.MSYS_SRC_BUILD_TYPE:
with temp_makepkg_confd(msys2_root, "makepkg.conf") as makepkg_conf:
with open(makepkg_conf, "w", encoding="utf-8") as h:
h.write("COMPRESSZST=(zstd -c -T0 --ultra -22 -)\n")
run_cmd(msys2_root, [
'makepkg',
'--noconfirm',
@ -342,6 +371,10 @@ def build_package(build_type: BuildType, pkg: Package, msys2_root: PathLike, bui
'--allsource'
], env=env, cwd=pkg_dir)
elif build_type in Config.MINGW_ARCH_LIST:
with temp_makepkg_confd(msys2_root, "makepkg_mingw.conf") as makepkg_conf:
with open(makepkg_conf, "w", encoding="utf-8") as h:
h.write("COMPRESSZST=(zstd -c -T0 --ultra -20 -)\n")
env['MINGW_ARCH'] = build_type
run_cmd(msys2_root, [
'makepkg-mingw',
@ -353,6 +386,10 @@ def build_package(build_type: BuildType, pkg: Package, msys2_root: PathLike, bui
'--cleanbuild'
], env=env, cwd=pkg_dir)
elif build_type in Config.MSYS_ARCH_LIST:
with temp_makepkg_confd(msys2_root, "makepkg.conf") as makepkg_conf:
with open(makepkg_conf, "w", encoding="utf-8") as h:
h.write("COMPRESSZST=(zstd -c -T0 --ultra -20 -)\n")
run_cmd(msys2_root, [
'makepkg',
'--noconfirm',