From da973a32fa9b3cbda63a371beabd85ad53ce03f4 Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Wed, 20 May 2026 00:16:19 -0600 Subject: [PATCH] Enforce default options --- test.py | 26 ++++++++++++++++++-------- tests/basedir/VELBUILD | 1 - tests/basic/VELBUILD | 1 - tests/checksums/VELBUILD | 1 - tests/image/VELBUILD | 1 - tests/rmstream/VELBUILD | 1 - tests/subpackages/VELBUILD | 1 - vbuild/velbuild.py | 37 ++++++++++++++++++++++++++++++++----- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/test.py b/test.py index a1fc582..ef5edf9 100644 --- a/test.py +++ b/test.py @@ -139,16 +139,30 @@ def _isinstance(source: str, cls: type, debug: Callable[[], Any] | None = None) apkbuild.arch = ["test", "test2"] _assert('apkbuild.arch == ["test", "test2"]') _assert("apkbuild.text.strip() == \"maintainer='test'\\narch='\\ntest\\ntest2\\n'\"") - -# Test VELBUILD image property _isinstance("VELBUILD.image", property) velbuild = VELBUILD({}, {}) _assert("velbuild.image is None") velbuild.image = "my-custom-image:latest" _assert("\"'my-custom-image:latest'\" in velbuild.image", lambda: velbuild.image) _raises('setattr(velbuild, "image", 1)', AssertionError) - -# Test that image does NOT appear in generated APKBUILD text +_assert( + 'set(velbuild.options) == {"!check", "!fhs", "!strip", "!tracedeps"}', + lambda: set(velbuild.options), # pyright: ignore[reportAny] +) +velbuild.variables["options"] = "check" +_assert( + 'set(velbuild.options) == {"!fhs", "!strip", "!tracedeps"}', + lambda: set(velbuild.options), # pyright: ignore[reportAny] +) +velbuild.variables["options"] += "\nfhs" +_assert( + 'set(velbuild.options) == {"!strip", "!tracedeps"}', + lambda: set(velbuild.options), # pyright: ignore[reportAny] +) +velbuild.variables["options"] += "\nstrip" +_assert('set(velbuild.options) == {"!tracedeps"}', lambda: set(velbuild.options)) # pyright: ignore[reportAny] +velbuild.variables["options"] += "\ntracedeps" +_assert("not velbuild.options", lambda: set(velbuild.options)) # pyright: ignore[reportAny] velbuild.pkgname = "test-pkg" velbuild.pkgver = "1.0" velbuild.pkgrel = "0" @@ -156,16 +170,12 @@ def _isinstance(source: str, cls: type, debug: Callable[[], Any] | None = None) text = velbuild.text _assert("'image=' not in text", lambda: text) _assert("'my-custom-image' not in text", lambda: text) - -# Test that build() function gets wrapped when image is set velbuild.functions["build"] = "echo 'building...'" os.environ["VBUILD_DRIVER"] = "podman" text = velbuild.text _assert("'VBUILD_BUILD_SCRIPT' in text", lambda: text) _assert("'my-custom-image:latest' in text", lambda: text) _assert("'podman' in text and 'run' in text", lambda: text) - -# Test that build() function is NOT wrapped when image is not set velbuild2 = VELBUILD({}, {}) velbuild2.pkgname = "test-pkg2" velbuild2.pkgver = "1.0" diff --git a/tests/basedir/VELBUILD b/tests/basedir/VELBUILD index 13da141..0ca2538 100644 --- a/tests/basedir/VELBUILD +++ b/tests/basedir/VELBUILD @@ -10,7 +10,6 @@ url="https://github.com/asivery/rm-hacks-qmd" arch="noarch" license="MIT" depends="qt-resource-rebuilder>=17 remarkable-os>=3.24 remarkable-os<3.25" -options="!check !fhs" source=" rm-hacks-qmd-$_commit.tar.gz::https://github.com/asivery/rm-hacks-qmd/archive/$_commit.tar.gz " diff --git a/tests/basic/VELBUILD b/tests/basic/VELBUILD index d71c01e..ffffed0 100644 --- a/tests/basic/VELBUILD +++ b/tests/basic/VELBUILD @@ -9,7 +9,6 @@ url="https://toltec-dev.org/" arch="noarch" license="MIT" depends="entware" -options="!check !fhs !strip !tracedeps" install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-deinstall" _commit="c4ffc32a58765b27f49952640b616c2f48adb83b" source=" diff --git a/tests/checksums/VELBUILD b/tests/checksums/VELBUILD index 3d37329..5fe6474 100644 --- a/tests/checksums/VELBUILD +++ b/tests/checksums/VELBUILD @@ -14,7 +14,6 @@ source=" floating.qmd::https://raw.githubusercontent.com/FouzR/xovi-extensions/$_commit/3.25/floating.qmd LICENSE::https://raw.githubusercontent.com/FouzR/xovi-extensions/$_commit/LICENSE " -options="!check !fhs" package() { install -Dm644 "$srcdir/floating.qmd" \ diff --git a/tests/image/VELBUILD b/tests/image/VELBUILD index a8d3616..bc43b80 100644 --- a/tests/image/VELBUILD +++ b/tests/image/VELBUILD @@ -9,7 +9,6 @@ url="https://toltec-dev.org/" arch="noarch" license="MIT" depends="entware" -options="!check !fhs !strip !tracedeps" install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-deinstall" _commit="c4ffc32a58765b27f49952640b616c2f48adb83b" source=" diff --git a/tests/rmstream/VELBUILD b/tests/rmstream/VELBUILD index d502ae2..89d57dc 100644 --- a/tests/rmstream/VELBUILD +++ b/tests/rmstream/VELBUILD @@ -9,7 +9,6 @@ url="https://github.com/asivery/appload-rmstream" arch="aarch64 armv7" license="GPL-3.0" depends="appload framebuffer-spy" -options="!check !fhs !strip !tracedeps" source=" https://github.com/$upstream_author/appload-rmstream/releases/download/v$pkgver/rmstream-aarch64.zip diff --git a/tests/subpackages/VELBUILD b/tests/subpackages/VELBUILD index a19ce8d..8350fa3 100644 --- a/tests/subpackages/VELBUILD +++ b/tests/subpackages/VELBUILD @@ -9,7 +9,6 @@ url="https://github.com/asivery/rm-xovi-extensions" arch="aarch64 armv7" license="GPL-3.0" depends="xovi remarkable-os>=3.20 remarkable-os<3.26" -options="!check !fhs !strip !tracedeps" subpackages=" qt-resource-rebuilder:qt_resource_rebuilder diff --git a/vbuild/velbuild.py b/vbuild/velbuild.py index afffea9..ec72553 100644 --- a/vbuild/velbuild.py +++ b/vbuild/velbuild.py @@ -45,10 +45,6 @@ class VELBUILD(APKBUILD): def text(self) -> str: lines: list[str] = [] variables = self.variables.copy() - - if self.systemdunits and (self.options is None or "!fhs" not in self.options): # pyright: ignore[reportAny] - variables["options"] = f"\n{'\n'.join([*(self.options or []), '!fhs'])}\n" - for name, value in variables.items(): if ( value is None @@ -63,7 +59,7 @@ def text(self) -> str: ): continue - if name in ("systemdunits", "image"): + if name in ("systemdunits", "image", "options"): continue if name in ( @@ -93,6 +89,9 @@ def text(self) -> str: lines.append(")") + lines.append( + f"options={quoted_string(f'\n{"\n".join(cast(list[str], self.options))}\n')}" + ) if self.install.strip(): # pyright: ignore[reportAny] lines.append(f"install={quoted_string(self.install)}") # pyright: ignore[reportAny] @@ -445,6 +444,34 @@ def image(self) -> str | None: return None + @APKBUILD.options.getter + def options(self) -> list[str]: + options = list( + set( + [ + *cast(list[str], super().options or []), + *{"!check", "!fhs", "!strip", "!tracedeps"}, + ] + ) + ) + + def handle_option(option: str) -> None: + nonlocal options + if option not in options: + return + + options.remove(option) + option = f"!{option}" + if option in options: + options.remove(option) + + handle_option("check") + handle_option("fhs") + handle_option("strip") + handle_option("tracedeps") + options.sort() + return options + @image.setter def image(self, value: str | None) -> None: assert value is None or isinstance(value, str)