Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,43 @@ 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"
os.environ["VBUILD_DRIVER"] = "docker"
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"
Expand Down
1 change: 0 additions & 1 deletion tests/basedir/VELBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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
"
Expand Down
1 change: 0 additions & 1 deletion tests/basic/VELBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
1 change: 0 additions & 1 deletion tests/checksums/VELBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
1 change: 0 additions & 1 deletion tests/image/VELBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
1 change: 0 additions & 1 deletion tests/rmstream/VELBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/subpackages/VELBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 32 additions & 5 deletions vbuild/velbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,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
Expand All @@ -68,7 +64,7 @@ def text(self) -> str:
):
continue

if name in ("systemdunits", "image"):
if name in ("systemdunits", "image", "options"):
continue

if name in (
Expand Down Expand Up @@ -98,6 +94,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]

Expand Down Expand Up @@ -456,6 +455,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")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
options.sort()
return options

@image.setter
def image(self, value: str | None) -> None:
assert value is None or isinstance(value, str)
Expand Down