From ecfb615f9732942e5309ddee3d3a33c331371dba Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Tue, 20 Feb 2024 14:47:58 +0200 Subject: [PATCH] feat: add ability to disable debug packages distribution The feature is implemented as supplying !debug option to makepkg when generating package list. In this case debug packages still will be built, however, they will not be added to the repository --- docs/configuration.rst | 1 + package/share/ahriman/settings/ahriman.ini | 4 + src/ahriman/core/build_tools/task.py | 8 +- src/ahriman/core/configuration/schema.py | 4 + tests/ahriman/core/build_tools/test_task.py | 81 ++++++++++++++++++++- 5 files changed, 94 insertions(+), 4 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index b8029da5..5f5d1d16 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -81,6 +81,7 @@ Build related configuration. Group name can refer to architecture, e.g. ``build: * ``archbuild_flags`` - additional flags passed to ``archbuild`` command, space separated list of strings, optional. * ``build_command`` - default build command, string, required. * ``ignore_packages`` - list packages to ignore during a regular update (manual update will still work), space separated list of strings, optional. +* ``include_debug_packages`` - distribute debug packages, boolean, optional, default ``yes``. * ``makepkg_flags`` - additional flags passed to ``makepkg`` command, space separated list of strings, optional. * ``makechrootpkg_flags`` - additional flags passed to ``makechrootpkg`` command, space separated list of strings, optional. * ``triggers`` - list of ``ahriman.core.triggers.Trigger`` class implementation (e.g. ``ahriman.core.report.ReportTrigger ahriman.core.upload.UploadTrigger``) which will be loaded and run at the end of processing, space separated list of strings, optional. You can also specify triggers by their paths, e.g. ``/usr/lib/python3.10/site-packages/ahriman/core/report/report.py.ReportTrigger``. Triggers are run in the order of definition. diff --git a/package/share/ahriman/settings/ahriman.ini b/package/share/ahriman/settings/ahriman.ini index 09ba107f..494ddc33 100644 --- a/package/share/ahriman/settings/ahriman.ini +++ b/package/share/ahriman/settings/ahriman.ini @@ -46,8 +46,12 @@ allow_read_only = yes [build] ; List of additional flags passed to archbuild command. ;archbuild_flags = +; Path to build command +;build_command = ; List of packages to be ignored during automatic updates. ;ignore_packages = +; Include debug packages +;include_debug_packages = yes ; List of additional flags passed to makechrootpkg command. ;makechrootpkg_flags = ; List of additional flags passed to makepkg command. diff --git a/src/ahriman/core/build_tools/task.py b/src/ahriman/core/build_tools/task.py index a57c185b..ea5f05bf 100644 --- a/src/ahriman/core/build_tools/task.py +++ b/src/ahriman/core/build_tools/task.py @@ -38,6 +38,7 @@ class Task(LazyLogging): archbuild_flags(list[str]): command flags for archbuild command architecture(str): repository architecture build_command(str): build command + include_debug_packages(bool): whether to include debug packages or not makechrootpkg_flags(list[str]): command flags for makechrootpkg command makepkg_flags(list[str]): command flags for makepkg command package(Package): package definitions @@ -63,6 +64,7 @@ class Task(LazyLogging): self.archbuild_flags = configuration.getlist("build", "archbuild_flags", fallback=[]) self.build_command = configuration.get("build", "build_command") + self.include_debug_packages = configuration.getboolean("build", "include_debug_packages", fallback=True) self.makepkg_flags = configuration.getlist("build", "makepkg_flags", fallback=[]) self.makechrootpkg_flags = configuration.getlist("build", "makechrootpkg_flags", fallback=[]) @@ -99,9 +101,11 @@ class Task(LazyLogging): environment=environment, ) - # well it is not actually correct, but we can deal with it + package_list_command = ["makepkg", "--packagelist"] + if not self.include_debug_packages: + package_list_command.append("OPTIONS=(!debug)") # disable debug flag manually packages = check_output( - "makepkg", "--packagelist", + *package_list_command, exception=BuildError.from_process(self.package.base), cwd=sources_dir, logger=self.logger, diff --git a/src/ahriman/core/configuration/schema.py b/src/ahriman/core/configuration/schema.py index 618b87fc..0ce10901 100644 --- a/src/ahriman/core/configuration/schema.py +++ b/src/ahriman/core/configuration/schema.py @@ -176,6 +176,10 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = { "empty": False, }, }, + "include_debug_packages": { + "type": "boolean", + "coerce": "boolean", + }, "makepkg_flags": { "type": "list", "coerce": "list", diff --git a/tests/ahriman/core/build_tools/test_task.py b/tests/ahriman/core/build_tools/test_task.py index 4add6a70..893b113d 100644 --- a/tests/ahriman/core/build_tools/test_task.py +++ b/tests/ahriman/core/build_tools/test_task.py @@ -1,5 +1,8 @@ +import pytest + from pathlib import Path from pytest_mock import MockerFixture +from unittest.mock import call as MockCall from ahriman.core.build_tools.task import Task from ahriman.core.database import SQLite @@ -9,9 +12,83 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None: """ must build package """ + local = Path("local") check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output") - task_ahriman.build(Path("ahriman")) - check_output_mock.assert_called() + + task_ahriman.build(local) + check_output_mock.assert_has_calls([ + MockCall( + "extra-x86_64-build", "-r", str(task_ahriman.paths.chroot), "--", "--", "--skippgpcheck", + exception=pytest.helpers.anyvar(int), + cwd=local, + logger=task_ahriman.logger, + user=task_ahriman.uid, + environment={}, + ), + MockCall( + "makepkg", "--packagelist", + exception=pytest.helpers.anyvar(int), + cwd=local, + logger=task_ahriman.logger, + environment={}, + ), + ]) + + +def test_build_environment(task_ahriman: Task, mocker: MockerFixture) -> None: + """ + must build package with environment variables set + """ + local = Path("local") + check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output") + environment = {"variable": "value"} + + task_ahriman.build(local, **environment, empty=None) + check_output_mock.assert_has_calls([ + MockCall( + "extra-x86_64-build", "-r", str(task_ahriman.paths.chroot), "--", "--", "--skippgpcheck", + exception=pytest.helpers.anyvar(int), + cwd=local, + logger=task_ahriman.logger, + user=task_ahriman.uid, + environment=environment, + ), + MockCall( + "makepkg", "--packagelist", + exception=pytest.helpers.anyvar(int), + cwd=local, + logger=task_ahriman.logger, + environment=environment, + ), + ]) + + +def test_build_no_debug(task_ahriman: Task, mocker: MockerFixture) -> None: + """ + must filter debug packages from result + """ + local = Path("local") + check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output") + task_ahriman.include_debug_packages = False + + task_ahriman.build(local) + check_output_mock.assert_has_calls([ + MockCall( + "extra-x86_64-build", "-r", str(task_ahriman.paths.chroot), "--", "--", "--skippgpcheck", + exception=pytest.helpers.anyvar(int), + cwd=local, + logger=task_ahriman.logger, + user=task_ahriman.uid, + environment={}, + ), + MockCall( + "makepkg", "--packagelist", "OPTIONS=(!debug)", + exception=pytest.helpers.anyvar(int), + cwd=local, + logger=task_ahriman.logger, + environment={}, + ), + ]) def test_init(task_ahriman: Task, database: SQLite, mocker: MockerFixture) -> None: