Files
semios-packages/lib/make.py
T
2026-06-23 15:27:46 +08:00

102 lines
2.4 KiB
Python

import typing
from lib import arch
from . import pkgcomposer, sources
_key_global = "@global"
_key_version = "version"
_key_description = "description"
_key_on_pack = "on_pack"
_key_arch_any = "arch_any"
_key_links = "links"
_key_dependencies = "dependencies"
_key_provides = "provides"
_current_pkgname: str = _key_global
_pkginfo: dict[str, dict[str, typing.Any]] = {
_key_global: {
_key_links: [],
_key_dependencies: [],
_key_provides: [],
},
}
_supported_arch: typing.Callable[[str], bool] = lambda x: True
_on_build: typing.Callable[[], None] | None = None
_blocked_hooks: list[str] = []
def package(s: str):
global _current_pkgname
_current_pkgname = s
_pkginfo[s] = _pkginfo[_key_global].copy()
_pkginfo[s][_key_links] = _pkginfo[s][_key_links].copy()
_pkginfo[s][_key_dependencies] = _pkginfo[s][_key_dependencies].copy()
_pkginfo[s][_key_provides] = _pkginfo[s][_key_provides].copy()
def version(s: str):
_pkginfo[_current_pkgname][_key_version] = s
def description(s: str):
_pkginfo[_current_pkgname][_key_description] = s
def arch_any():
_pkginfo[_current_pkgname][_key_arch_any] = True
def provide(s: str):
_pkginfo[_current_pkgname][_key_provides] += [
s.replace("@same-arch", f"@{arch.get_target()}")
]
def dep(s: str):
_pkginfo[_current_pkgname][_key_dependencies] += [
s.replace("(same)", "(same-version) @same-arch")
.replace("(same-version)", f"(={_pkginfo[_current_pkgname][_key_version]})")
.replace("@same-arch", f"@{arch.get_target()}")
]
def link(src: str, dst: str, default: bool = True):
_pkginfo[_current_pkgname][_key_links] += [
{
"from": src,
"to": dst,
"default": default,
}
]
def supported_arch(s: list[str] | typing.Callable[[str], bool]):
global _supported_arch
if isinstance(s, list):
_supported_arch = lambda arch: arch in s
else:
_supported_arch = s
def on_build(func: typing.Callable[[], None]):
global _on_build
_on_build = func
def on_pack(func: typing.Callable[[pkgcomposer.PkgComposer], None]):
_pkginfo[_current_pkgname][_key_on_pack] = func
def block_hook(hook: str):
_blocked_hooks.append(hook)
def source_url(url: str):
sources.source_url(url)
def source_git(url: str, branch: str | None = None):
sources.source_git(url, branch)