import typing from lib import arch from . import pkgcomposer, sources _key_global = "@global" _key_version = "version" _key_description = "description" _key_maintainers = "maintainers" _key_on_pack = "on_pack" _key_arch_any = "arch_any" _key_links = "links" _key_dependencies = "dependencies" _key_recommendations = "recommendations" _key_provides = "provides" _current_pkgname: str = _key_global _pkginfo: dict[str, dict[str, typing.Any]] = { _key_global: { _key_links: [], _key_dependencies: [], _key_maintainers: [], _key_provides: [], _key_recommendations: [], }, } _supported_arch: typing.Callable[[str], bool] = lambda x: True _on_build: typing.Callable[[], None] | None = None _in_atombuild = False _builddep: list[str] = [] _blocked_hooks: list[str] = [] def builddep(s: str): global _builddep if s == "shortcut/c": _builddep += ["semi-libc-dev", "clang", "llvm", "lld"] elif s == "shortcut/c++": builddep("shortcut/c") _builddep += ["libcxx-dev"] elif s == "shortcut/autotools": _builddep += ["gnu-make", "gnu-sed", "awk", "grep"] elif s == "shortcut/rust": builddep("shortcut/c") _builddep += ["cargo", "rustc"] elif s == "shortcut/cmake": _builddep += ["cmake", "ninja"] elif s == "shortcut/meson": _builddep += ["meson", "ninja"] else: _builddep += [s] 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 maintainer(s: str): _pkginfo[_current_pkgname][_key_maintainers] += [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 _translate_dep_spec(s: str) -> str: return ( s.replace("(same)", "(same-version) @same-arch") .replace("(same-version)", f"(={_pkginfo[_current_pkgname][_key_version]})") .replace("@same-arch", f"@{arch.get_target()}") ) def dep(s: str): _pkginfo[_current_pkgname][_key_dependencies] += [_translate_dep_spec(s)] def recommend(s: str): _pkginfo[_current_pkgname][_key_recommendations] += [_translate_dep_spec(s)] def link(src: str, dst: str, default: bool = True): _pkginfo[_current_pkgname][_key_links] += [ { "from": src, "to": dst, "default": default, } ] def get_prefix(pkgname: str) -> str: pkginfo = _pkginfo[pkgname] if pkginfo.get(_key_arch_any): pkgarch = "any" else: pkgarch = arch.get_target() return f"/pkg/{pkgname}={pkginfo[_key_version]}@{pkgarch}" 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): if not _in_atombuild: sources.source_url(url) def source_git(url: str, branch: str | None = None): if not _in_atombuild: sources.source_git(url, branch)