+31
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
|
||||
from . import packie
|
||||
|
||||
all: dict[str, dict[str, str]] = {
|
||||
"aarch64-semios-linux": {
|
||||
"CC": "clang -target aarch64-unknown-linux-musl",
|
||||
"CXX": "clang++ -target aarch64-unknown-linux-musl",
|
||||
},
|
||||
"x86_64-semios-linux": {
|
||||
"CC": "clang -target x86_64-unknown-linux-musl",
|
||||
"CXX": "clang++ -target x86_64-unknown-linux-musl",
|
||||
},
|
||||
"riscv64-semios-linux": {
|
||||
"CC": "clang -target riscv64-unknown-linux-musl",
|
||||
"CXX": "clang++ -target riscv64-unknown-linux-musl",
|
||||
},
|
||||
}
|
||||
_target: str = packie.host_arch()
|
||||
|
||||
|
||||
def get_target():
|
||||
return _target
|
||||
|
||||
|
||||
def set_target(arch: str):
|
||||
global _target
|
||||
_target = arch
|
||||
for key in all[_target].keys():
|
||||
if not os.environ.get(key):
|
||||
os.environ[key] = all[_target][key]
|
||||
@@ -0,0 +1,144 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from . import packie
|
||||
|
||||
BASE_REQUIREMENTS = [
|
||||
# Basic packages for running shell scripts
|
||||
"mksh",
|
||||
"coreutils",
|
||||
"findutils",
|
||||
"diffutils",
|
||||
# Packages for running `semios-packages` scripts
|
||||
"python",
|
||||
"packie",
|
||||
"zstd",
|
||||
"libarchive-tools",
|
||||
# Packages for building packages that require patching
|
||||
"patch",
|
||||
# Packages for downloading various formats of tarballs
|
||||
"curl",
|
||||
"libz-ng",
|
||||
"liblzma",
|
||||
"libbzip2",
|
||||
# Basic libraries
|
||||
"sqlite",
|
||||
"libgcc-compat",
|
||||
"libcxx",
|
||||
"semi-libc",
|
||||
# Networking
|
||||
"ca-certificates",
|
||||
"certutil",
|
||||
"aws-lc-libssl",
|
||||
"aws-lc-tools",
|
||||
]
|
||||
|
||||
|
||||
def _prepare_build_env_base_files(root: str):
|
||||
# Create root directory
|
||||
os.makedirs(root, exist_ok=True)
|
||||
|
||||
# Create var, run and tmp
|
||||
os.mkdir(f"{root}/var")
|
||||
os.mkdir(f"{root}/var/tmp")
|
||||
os.mkdir(f"{root}/var/run")
|
||||
os.mkdir(f"{root}/tmp")
|
||||
os.mkdir(f"{root}/run")
|
||||
|
||||
# Copy repository config files
|
||||
os.makedirs(f"{root}/var/db/packie")
|
||||
shutil.copytree("/var/config/packie/repos.d", f"{root}/var/config/packie/repos.d")
|
||||
|
||||
# Create directories for kernel pseudo filesystems
|
||||
os.mkdir(f"{root}/dev")
|
||||
os.mkdir(f"{root}/sys")
|
||||
os.mkdir(f"{root}/proc")
|
||||
|
||||
# Create home directory of root (some scripts may require it)
|
||||
os.makedirs(f"{root}/home/root")
|
||||
|
||||
# Copy DNS config
|
||||
os.makedirs(f"{root}/etc", exist_ok=True)
|
||||
shutil.copy2("/etc/resolv.conf", f"{root}/etc/resolv.conf")
|
||||
|
||||
# For atom build environments, we simply use a link to be usr-shebang-compatible to avoid problems
|
||||
os.mkdir(f"{root}/usr")
|
||||
os.symlink("/bin", f"{root}/usr/bin")
|
||||
|
||||
|
||||
def prepare_build_env(root: str, extreq: list[str] = []):
|
||||
# Skip if the environment is already initialized
|
||||
if os.path.exists(f"{root}/.INIT"):
|
||||
return
|
||||
try:
|
||||
shutil.rmtree(root)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Prepare basic filesystem hierarchy
|
||||
_prepare_build_env_base_files(root)
|
||||
|
||||
# Install packages
|
||||
packie.chroot_update(root)
|
||||
packie.chroot_install(root, BASE_REQUIREMENTS + extreq)
|
||||
|
||||
# Refresh certificates
|
||||
enter_build_env(root, ["certutil", "refresh"])
|
||||
|
||||
# Create initialized tag
|
||||
with open(f"{root}/.INIT", "wt+") as file:
|
||||
file.write("OK")
|
||||
|
||||
|
||||
def enter_build_env(root: str, cmd: list[str], chdir: str = "/"):
|
||||
reserve_env = ["https_proxy", "http_proxy", "all_proxy"]
|
||||
reserve_env_args = []
|
||||
for i in reserve_env:
|
||||
if os.environ.get(i):
|
||||
reserve_env_args += ["--setenv", i, os.environ[i]]
|
||||
subprocess.run(
|
||||
[
|
||||
"bwrap",
|
||||
"--bind", root, "/",
|
||||
"--unshare-pid",
|
||||
"--unshare-user",
|
||||
"--uid", "0",
|
||||
"--gid", "0",
|
||||
"--dev", "/dev",
|
||||
"--bind", "/sys", "/sys",
|
||||
"--proc", "/proc",
|
||||
"--clearenv",
|
||||
"--setenv", "HOME", "/home/root",
|
||||
"--setenv", "PATH", "/bin",
|
||||
"--setenv", "SEMIOS_PKGBUILD_IN_ATOMIC", "1",
|
||||
"--setenv", "USER", "root",
|
||||
"--setenv", "LOGNAME", "root",
|
||||
"--chdir",
|
||||
chdir,
|
||||
]
|
||||
+ reserve_env_args
|
||||
+ cmd,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def copy_pkgbuild_tree(repo_root: str, pkgname: str, build_env_root: str):
|
||||
build_dir = f"{build_env_root}/Atom"
|
||||
if os.path.exists(build_dir):
|
||||
return
|
||||
os.mkdir(build_dir)
|
||||
shutil.copytree(f"{repo_root}/hooks", f"{build_dir}/hooks")
|
||||
shutil.copytree(f"{repo_root}/lib", f"{build_dir}/lib")
|
||||
shutil.copy2(f"{repo_root}/x", f"{build_dir}/x")
|
||||
shutil.copy2(f"{repo_root}/x.py", f"{build_dir}/x.py")
|
||||
os.makedirs(f"{build_dir}/packages/{pkgname}")
|
||||
for i in os.listdir(f"{repo_root}/packages/{pkgname}"):
|
||||
srcpath = f"{repo_root}/packages/{pkgname}/{i}"
|
||||
dstpath = f"{build_dir}/packages/{pkgname}/{i}"
|
||||
if i in ["target", "__pycache__"]:
|
||||
continue
|
||||
if os.path.isdir(srcpath):
|
||||
shutil.copytree(srcpath, dstpath)
|
||||
elif os.path.isfile(srcpath):
|
||||
shutil.copy2(srcpath, dstpath)
|
||||
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
import types
|
||||
|
||||
|
||||
def _wrap_treedir_entry(ent, prefix=""):
|
||||
wrapped = types.SimpleNamespace()
|
||||
wrapped.name = f"{prefix}/{ent.name}" if prefix else ent.name
|
||||
wrapped.path = ent.path
|
||||
wrapped.is_dir = ent.is_dir
|
||||
wrapped.is_file = ent.is_file
|
||||
wrapped.is_symlink = ent.is_symlink
|
||||
return wrapped
|
||||
|
||||
|
||||
def treedir(root: str, prefix: str = ""):
|
||||
with os.scandir(root) as entries:
|
||||
for ent in entries:
|
||||
wrapped = _wrap_treedir_entry(ent, prefix)
|
||||
yield wrapped
|
||||
if wrapped.is_dir(follow_symlinks=False):
|
||||
yield from treedir(ent.path, wrapped.name)
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from lib.common import treedir
|
||||
|
||||
from . import make as libmake
|
||||
from . import pkgcomposer
|
||||
|
||||
|
||||
def configure(rem: list[str] = []):
|
||||
subprocess.run(["./configure"] + rem, check=True)
|
||||
|
||||
|
||||
def cmake(rem: list[str] = []):
|
||||
source_dir = os.getcwd()
|
||||
os.makedirs("../cmake_build", exist_ok=True)
|
||||
os.chdir("../cmake_build")
|
||||
subprocess.run(
|
||||
[
|
||||
"cmake",
|
||||
"-GNinja",
|
||||
"-DCMAKE_BUILD_TYPE=Release",
|
||||
"-DCMAKE_INSTALL_PREFIX=/",
|
||||
source_dir,
|
||||
]
|
||||
+ rem,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def _move_install():
|
||||
subprocess.run(["sh", "-c", "cp -r ./pkg/*/* . 2>/dev/null || true"], check=False)
|
||||
subprocess.run(
|
||||
["sh", "-c", "cp -r ./usr/local/* . 2>/dev/null || true"], check=False
|
||||
)
|
||||
subprocess.run(["sh", "-c", "cp -r ./usr/* . 2>/dev/null || true"], check=False)
|
||||
subprocess.run(["rm", "-rf", "./pkg", "./usr"], check=False)
|
||||
|
||||
|
||||
def make(rem: list[str] = []):
|
||||
subprocess.run(["make", f"-j{os.cpu_count()}"] + rem, check=True)
|
||||
|
||||
|
||||
def make_install(rem: list[str] | None = None, chdir: bool = True, move: bool = True):
|
||||
default_rem = ["DESTDIR=" + os.getcwd() + "/../cpp_install"]
|
||||
if rem is None:
|
||||
try:
|
||||
shutil.rmtree("../cpp_install")
|
||||
except:
|
||||
pass
|
||||
subprocess.run(["make", "install"] + (rem or default_rem), check=True)
|
||||
if chdir:
|
||||
os.chdir("../cpp_install")
|
||||
if chdir and move:
|
||||
_move_install()
|
||||
|
||||
|
||||
def ninja(rem: list[str] = []):
|
||||
subprocess.run(["ninja"] + rem, check=True)
|
||||
|
||||
|
||||
def ninja_install(rem: list[str] = [], chdir: bool = True, move: bool = True):
|
||||
if chdir:
|
||||
os.environ["DESTDIR"] = os.getcwd() + "/../cpp_install"
|
||||
subprocess.run(["ninja", "install"] + rem, check=True)
|
||||
if chdir:
|
||||
os.chdir(os.environ["DESTDIR"])
|
||||
if chdir and move:
|
||||
_move_install()
|
||||
|
||||
|
||||
def meson_setup(rem: list[str] = []):
|
||||
subprocess.run(["meson", "setup", "_meson_build"] + rem, check=True)
|
||||
|
||||
|
||||
def meson_compile(rem: list[str] = []):
|
||||
subprocess.run(["meson", "compile", "-C", "_meson_build"] + rem, check=True)
|
||||
|
||||
|
||||
def meson_install(rem: list[str] | None = None, chdir: bool = True, move: bool = True):
|
||||
default_rem = ["--destdir", f"{os.getcwd()}/../cpp_install"]
|
||||
if not rem:
|
||||
os.makedirs("../cpp_install", exist_ok=True)
|
||||
subprocess.run(
|
||||
["meson", "install", "-C", "_meson_build"] + (rem or default_rem), check=True
|
||||
)
|
||||
if chdir:
|
||||
os.chdir("../cpp_install")
|
||||
if chdir and move:
|
||||
_move_install()
|
||||
|
||||
|
||||
def _do_auto_pack(pc: pkgcomposer.PkgComposer, srcdir: str, dstdir: str, filter):
|
||||
if not os.path.exists(srcdir):
|
||||
return
|
||||
try:
|
||||
pc.makedir(dstdir)
|
||||
except Exception:
|
||||
pass
|
||||
for ent in treedir(srcdir):
|
||||
if filter(ent):
|
||||
if ent.is_file(follow_symlinks=False):
|
||||
pc.makedirs(os.path.dirname(f"{dstdir}/{ent.name}"))
|
||||
pc.addfile(ent.path, f"{dstdir}/{ent.name}")
|
||||
elif ent.is_symlink() and not os.path.isabs(os.readlink(ent.path)):
|
||||
try:
|
||||
pc.addfile(ent.path, f"{dstdir}/{ent.name}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _is_dev_file(ent) -> bool:
|
||||
return (
|
||||
ent.name.endswith(".o")
|
||||
or ent.name.endswith(".a")
|
||||
or ent.name.endswith(".la")
|
||||
or ent.name.endswith(".pc")
|
||||
or ent.name.endswith(".h")
|
||||
or ent.name.endswith(".hpp")
|
||||
or ent.name.endswith(".cmake")
|
||||
or ent.name.endswith(".inc")
|
||||
or ("Makefile" in ent.name)
|
||||
)
|
||||
|
||||
|
||||
def _autopack_filter_lib(ent) -> bool:
|
||||
return not _is_dev_file(ent)
|
||||
|
||||
|
||||
def _autopack_filter_bin(ent) -> bool:
|
||||
return os.access(ent.path, os.X_OK) and ent.is_file(follow_symlinks=False)
|
||||
|
||||
|
||||
def _autopack_filter_dev(ent):
|
||||
return _is_dev_file(ent)
|
||||
|
||||
|
||||
def _auto_pack(profiles: list[str], pc: pkgcomposer.PkgComposer):
|
||||
if "lib" in profiles:
|
||||
_do_auto_pack(pc, "lib", "lib", _autopack_filter_lib)
|
||||
if "bin" in profiles:
|
||||
_do_auto_pack(pc, "bin", "bin", _autopack_filter_bin)
|
||||
_do_auto_pack(pc, "sbin", "bin", _autopack_filter_bin)
|
||||
if "dev" in profiles:
|
||||
_do_auto_pack(pc, "lib", "lib", _autopack_filter_dev)
|
||||
_do_auto_pack(pc, "include", "include", _autopack_filter_dev)
|
||||
|
||||
|
||||
def use_auto_pack(profiles: list[str]):
|
||||
libmake.on_pack(lambda pc: _auto_pack(profiles, pc))
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
import typing
|
||||
import hashlib
|
||||
|
||||
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.replace("@target", f"@{arch.get_target()}")]
|
||||
|
||||
|
||||
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()
|
||||
pkgident = f"{pkgname}={pkginfo[_key_version]}@{pkgarch}"
|
||||
hasher = hashlib.sha3_224()
|
||||
hasher.update(pkgident.encode("utf-8"))
|
||||
return "/pkg/" + pkgname + "-" + hasher.hexdigest()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def in_atomic():
|
||||
return os.environ.get("SEMIOS_PKGBUILD_IN_ATOMIC", "0") == "1"
|
||||
@@ -0,0 +1,46 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
PACKIE_EXEC = os.getenv("PACKIE", "packie")
|
||||
|
||||
|
||||
def host_arch() -> str:
|
||||
result = subprocess.run(
|
||||
[PACKIE_EXEC, "print", "profile.host_arch"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
return result.stdout.decode().strip()
|
||||
|
||||
|
||||
def chroot_update(root: str):
|
||||
subprocess.run([PACKIE_EXEC, "--chroot", root, "update"], check=True)
|
||||
|
||||
|
||||
def chroot_install(root: str, requirements: list[str]):
|
||||
subprocess.run(
|
||||
[PACKIE_EXEC, "--chroot", root, "install", "--yes"] + requirements, check=True
|
||||
)
|
||||
|
||||
|
||||
def update():
|
||||
subprocess.run([PACKIE_EXEC, "update"], check=True)
|
||||
|
||||
|
||||
def install(requirements: list[str]):
|
||||
subprocess.run([PACKIE_EXEC, "install", "--yes"] + requirements, check=True)
|
||||
|
||||
|
||||
def repo_add(repo: str, pkgfile: str):
|
||||
subprocess.run(
|
||||
[PACKIE_EXEC, "repo-admin", repo, "--add-package", pkgfile], check=True
|
||||
)
|
||||
|
||||
|
||||
def prefix_of(pkgident: str):
|
||||
result = subprocess.run(
|
||||
[PACKIE_EXEC, "print", f"package.prefix.{pkgident}"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
return result.stdout.decode().strip()
|
||||
@@ -0,0 +1,67 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
class PkgComposer:
|
||||
def __init__(self, pkgfile: str):
|
||||
self.pkgfile = os.path.abspath(pkgfile)
|
||||
|
||||
def setworkdir(self, workdir: str):
|
||||
self.workdir = workdir
|
||||
shutil.rmtree(workdir, ignore_errors=True)
|
||||
os.mkdir(workdir)
|
||||
os.mkdir(f"{workdir}/bundle")
|
||||
|
||||
def write_manifest(self, manifest: dict):
|
||||
with open(self.workdir + "/PkgManifest.json", "w") as f:
|
||||
json.dump(manifest, f)
|
||||
|
||||
def write_links(self, links: list[dict]):
|
||||
with open(self.workdir + "/_links", "w") as f:
|
||||
for link in links:
|
||||
json.dump(link, f)
|
||||
f.write("\n")
|
||||
|
||||
def compose(self):
|
||||
subprocess.run(
|
||||
[
|
||||
"tar", "cpf", f"{self.pkgfile}.tar",
|
||||
"-C", self.workdir,
|
||||
"--numeric-owner",
|
||||
".",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(["zstd", "--rm", "-f", f"{self.pkgfile}.tar", "-o", self.pkgfile], check=True)
|
||||
|
||||
def makedir(self, name: str):
|
||||
os.mkdir(f"{self.workdir}/bundle/{name}")
|
||||
|
||||
def makedirs(self, name: str):
|
||||
os.makedirs(f"{self.workdir}/bundle/{name}", exist_ok=True)
|
||||
|
||||
def addfile(self, src: str, dst: str | None = None):
|
||||
if dst is None:
|
||||
dst = src
|
||||
shutil.copy2(src, f"{self.workdir}/bundle/{dst}", follow_symlinks=False)
|
||||
|
||||
def add_dir(self, src: str, dst: str | None = None, merge: bool = False):
|
||||
if dst is None:
|
||||
dst = src
|
||||
target = f"{self.workdir}/bundle/{dst}"
|
||||
if not os.path.exists(src):
|
||||
raise FileNotFoundError(f"Source directory not found: {src}")
|
||||
os.makedirs(os.path.dirname(target), exist_ok=True)
|
||||
if merge and os.path.exists(target) and os.path.isdir(target):
|
||||
cmd = ["cp", "-a", f"{src}/.", target]
|
||||
else:
|
||||
cmd = ["cp", "-a", src, target]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"cp command failed: {result.stderr}")
|
||||
|
||||
def link_external(self, src: str, dst: str):
|
||||
os.symlink(src, f"{self.workdir}/bundle/{dst}")
|
||||
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from . import make, arch
|
||||
|
||||
|
||||
PY3_VERSION = "3.14"
|
||||
|
||||
|
||||
def build():
|
||||
subprocess.run(["python3", "-m", "build", "."], check=True)
|
||||
|
||||
def install():
|
||||
if os.path.exists("../pyinstall"):
|
||||
shutil.rmtree("../pyinstall")
|
||||
for i in os.listdir("dist"):
|
||||
if not i.endswith(".whl"):
|
||||
continue
|
||||
subprocess.run(["python3", "-m", "installer", f"--destdir=../pyinstall", f"dist/{i}"], check=True)
|
||||
os.chdir("../pyinstall")
|
||||
while len(os.listdir(".")) == 1:
|
||||
os.chdir(os.listdir(".")[0])
|
||||
|
||||
def version(s: str):
|
||||
make.version(f"{s}+python{PY3_VERSION}")
|
||||
|
||||
def _depcommon(s: str):
|
||||
if s == "python":
|
||||
return f"python (~{PY3_VERSION}.0) @{arch.get_target()}"
|
||||
elif ".py" in s:
|
||||
if ")" in s:
|
||||
return s.replace(")", f", +python{PY3_VERSION})")
|
||||
else:
|
||||
return s.replace(".py", f".py (+python{PY3_VERSION})")
|
||||
else:
|
||||
return None
|
||||
|
||||
def builddep(s: str):
|
||||
if s == "$shortcut":
|
||||
builddep("python")
|
||||
builddep("build.py")
|
||||
builddep("installer.py")
|
||||
elif _depcommon(s):
|
||||
make.builddep(_depcommon(s))
|
||||
else:
|
||||
raise RuntimeError("unrecognized python dep")
|
||||
|
||||
def dep(s: str):
|
||||
if _depcommon(s):
|
||||
make.dep(_depcommon(s))
|
||||
else:
|
||||
raise RuntimeError("unrecognized python dep")
|
||||
|
||||
def _auto_pack(composer):
|
||||
base = f"lib/python{PY3_VERSION}/site-packages"
|
||||
composer.makedirs(base)
|
||||
for i in os.listdir("."):
|
||||
composer.add_dir(i, f"{base}/{i}")
|
||||
|
||||
def use_auto_pack():
|
||||
make.on_pack(_auto_pack)
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from . import arch, make, pkgcomposer
|
||||
|
||||
|
||||
def _rust_triple(semios: str) -> str:
|
||||
return semios.replace("-semios-linux", "-unknown-linux-musl")
|
||||
|
||||
|
||||
def build(rem: list[str] = []):
|
||||
cmdline = [
|
||||
"cargo",
|
||||
"build",
|
||||
"--release",
|
||||
"--target",
|
||||
_rust_triple(arch.get_target()),
|
||||
] + rem
|
||||
os.environ["RUSTFLAGS"] = (
|
||||
os.environ.get("RUSTFLAGS", "") + " -C target-feature=-crt-static"
|
||||
)
|
||||
subprocess.run(cmdline)
|
||||
|
||||
|
||||
def artifacts_dir():
|
||||
return f"target/{_rust_triple(arch.get_target())}/release"
|
||||
|
||||
|
||||
def _do_auto_pack(pc: pkgcomposer.PkgComposer, srcdir: str, dstdir: str, filter):
|
||||
pc.makedir(dstdir)
|
||||
with os.scandir(srcdir) as entries:
|
||||
for ent in entries:
|
||||
if filter(ent):
|
||||
if ent.is_dir(follow_symlinks=False):
|
||||
pc.makedir(f"{dstdir}/{ent.name}")
|
||||
elif ent.is_file(follow_symlinks=False):
|
||||
pc.addfile(ent.path, f"{dstdir}/{ent.name}")
|
||||
elif ent.is_symlink() and not os.path.isabs(os.readlink(ent.path)):
|
||||
pc.addfile(ent.path, f"{dstdir}/{ent.name}")
|
||||
|
||||
|
||||
def _autopack_filter_lib(ent) -> bool:
|
||||
if ent.is_dir(follow_symlinks=False):
|
||||
return False
|
||||
if ent.name.endswith(".so"):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def _autopack_filter_bin(ent) -> bool:
|
||||
return os.access(ent.path, os.X_OK) and ent.is_file(follow_symlinks=False)
|
||||
|
||||
|
||||
def _auto_pack(profiles: list[str], pc: pkgcomposer.PkgComposer):
|
||||
if "lib" in profiles:
|
||||
_do_auto_pack(pc, artifacts_dir(), "lib", _autopack_filter_lib)
|
||||
if "bin" in profiles:
|
||||
_do_auto_pack(pc, artifacts_dir(), "bin", _autopack_filter_bin)
|
||||
|
||||
|
||||
def use_auto_pack(profiles: list[str]):
|
||||
make.on_pack(lambda pc: _auto_pack(profiles, pc))
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import zipfile
|
||||
|
||||
|
||||
def filename(url):
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
path = parsed.path
|
||||
filename = os.path.basename(path)
|
||||
|
||||
if not filename:
|
||||
raise ValueError("No filename found in URL")
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def download(url, output):
|
||||
subprocess.run(["curl", "-L", "-o", output, url], check=True)
|
||||
|
||||
|
||||
def tar_common_root(tar: tarfile.TarFile) -> str | None:
|
||||
root = None
|
||||
for member in tar.getmembers():
|
||||
this_root = member.path.split("/")[0]
|
||||
if root is None:
|
||||
root = this_root
|
||||
if this_root != root:
|
||||
return None
|
||||
return root
|
||||
|
||||
|
||||
def zip_common_root(zip_file: zipfile.ZipFile) -> str | None:
|
||||
members = zip_file.infolist()
|
||||
if not members:
|
||||
return None
|
||||
root = None
|
||||
for member in members:
|
||||
path = member.filename.replace('\\', '/').lstrip('./').lstrip('/')
|
||||
if not path:
|
||||
continue
|
||||
this_root = path.split('/')[0]
|
||||
if this_root in ('', '.', '..'):
|
||||
continue
|
||||
if root is None:
|
||||
root = this_root
|
||||
elif this_root != root:
|
||||
return None
|
||||
return root
|
||||
|
||||
|
||||
def sources_dir_name() -> str:
|
||||
with open("./target/sources.tag") as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def source_url(url: str):
|
||||
if os.path.exists("./target/sources.tag"):
|
||||
return
|
||||
download_path = f"./target/{filename(url)}"
|
||||
download(url, download_path)
|
||||
|
||||
if download_path.endswith(".zip"):
|
||||
with zipfile.ZipFile(download_path, "r") as zip:
|
||||
common_root = zip_common_root(zip)
|
||||
else:
|
||||
with tarfile.open(download_path, "r") as tar:
|
||||
common_root = tar_common_root(tar)
|
||||
|
||||
extract_dir = "./target"
|
||||
sources_dir = f"./target/{common_root}"
|
||||
if common_root in ["", ".", None]:
|
||||
extract_dir = "./target/sources"
|
||||
sources_dir = "./target/sources"
|
||||
|
||||
if download_path.endswith(".zip"):
|
||||
with zipfile.ZipFile(download_path, "r") as zip:
|
||||
zip.extractall(extract_dir)
|
||||
else:
|
||||
with tarfile.open(download_path, "r") as tar:
|
||||
tar.extractall(extract_dir)
|
||||
|
||||
with open("./target/sources.tag", "wt+") as file:
|
||||
file.write(sources_dir)
|
||||
|
||||
|
||||
def _git_repo_name(url: str) -> str:
|
||||
return url.split("/")[-1].replace(".git", "")
|
||||
|
||||
|
||||
def source_git(url: str, branch: str | None = None):
|
||||
source_path = os.getcwd() + "/target/" + _git_repo_name(url)
|
||||
if os.path.exists("./target/sources.tag"):
|
||||
return
|
||||
cmdline = ["git", "clone", "--depth=1"]
|
||||
if branch:
|
||||
cmdline += ["-b", branch]
|
||||
cmdline += [url, source_path]
|
||||
subprocess.run(cmdline, check=True)
|
||||
with open("./target/sources.tag", "wt+") as file:
|
||||
file.write(source_path)
|
||||
Reference in New Issue
Block a user