@@ -0,0 +1 @@
|
||||
from . import arch, atombuild, make, packie, pkgcomposer, sources, managed_source
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ def prepare_build_env(root: str, extreq: list[str] = []):
|
||||
|
||||
|
||||
def enter_build_env(root: str, cmd: list[str], chdir: str = "/"):
|
||||
reserve_env = ["https_proxy", "http_proxy", "all_proxy"]
|
||||
reserve_env = ["https_proxy", "http_proxy", "all_proxy", "SEMIOS_SOURCE_REPO"]
|
||||
reserve_env_args = []
|
||||
for i in reserve_env:
|
||||
if os.environ.get(i):
|
||||
|
||||
+15
-4
@@ -4,7 +4,7 @@ import os
|
||||
|
||||
from lib import arch
|
||||
|
||||
from . import pkgcomposer, sources
|
||||
from . import pkgcomposer, sources, managed_source
|
||||
|
||||
_key_global = "@global"
|
||||
_key_version = "version"
|
||||
@@ -18,6 +18,9 @@ _key_recommendations = "recommendations"
|
||||
_key_provides = "provides"
|
||||
_key_configure = "configure"
|
||||
|
||||
_managed_source_url = None
|
||||
_managed_source_postprocess = ""
|
||||
|
||||
_current_pkgname: str = _key_global
|
||||
_pkginfo: dict[str, dict[str, typing.Any]] = {
|
||||
_key_global: {
|
||||
@@ -32,7 +35,7 @@ _pkginfo: dict[str, dict[str, typing.Any]] = {
|
||||
_supported_arch: typing.Callable[[str], bool] = lambda x: True
|
||||
_on_build: typing.Callable[[], None] | None = None
|
||||
|
||||
_in_atombuild = False
|
||||
_dry_run = False
|
||||
_builddep: list[str] = []
|
||||
|
||||
_blocked_hooks: list[str] = []
|
||||
@@ -155,14 +158,22 @@ def block_hook(hook: str):
|
||||
|
||||
|
||||
def source_url(url: str):
|
||||
if not _in_atombuild:
|
||||
if not _dry_run:
|
||||
sources.source_url(url)
|
||||
|
||||
|
||||
def source_git(url: str, branch: str | None = None):
|
||||
if not _in_atombuild:
|
||||
if not _dry_run:
|
||||
sources.source_git(url, branch)
|
||||
|
||||
|
||||
def source_managed(s: str, postprocess: str = ""):
|
||||
global _managed_source_url, _managed_source_postprocess
|
||||
_managed_source_url = s
|
||||
_managed_source_postprocess = postprocess
|
||||
if not _dry_run:
|
||||
sources.source_url(managed_source.get_repo_url(s))
|
||||
|
||||
|
||||
def in_atomic():
|
||||
return os.environ.get("SEMIOS_PKGBUILD_IN_ATOMIC", "0") == "1"
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
from urllib.parse import urlparse
|
||||
import os
|
||||
import subprocess
|
||||
from . import sources
|
||||
import glob
|
||||
|
||||
|
||||
DEFAULT_REPO="https://mirror2.semilabs.org/semios/srcpkgs"
|
||||
|
||||
|
||||
def postprocess_rust():
|
||||
subprocess.run(["cargo", "vendor"], check=True)
|
||||
os.makedirs(".cargo", exist_ok=True)
|
||||
with open(".cargo/config.toml", "a+") as fd:
|
||||
fd.write(
|
||||
"[source.crates-io]\nreplace-with = 'vendored-sources'\n[source.vendored-sources]\ndirectory = 'vendor'\n",
|
||||
)
|
||||
|
||||
def postprocess_autotools():
|
||||
subprocess.run(["sh", "autogen.sh"], check=True)
|
||||
subprocess.run(["./configure"], check=False)
|
||||
subprocess.run(["make", "dist"], check=True)
|
||||
tarballs = glob.glob("*.tar.gz")
|
||||
if len(tarballs) != 1:
|
||||
raise RuntimeError("No dist tarballs found.")
|
||||
subprocess.run(["tar", "xf", tarballs[0]], check=True)
|
||||
os.chdir(tarballs[0].replace(".tar.gz", ""))
|
||||
|
||||
|
||||
def get_origin_url(s):
|
||||
url = urlparse(s)
|
||||
if url.scheme == "github":
|
||||
return f"https://github.com/{url.hostname}{url.path}/archive/refs/tags/{url.fragment}.tar.gz"
|
||||
elif url.scheme == "gitea":
|
||||
return f"https://{url.hostname}{url.path}/archive/{url.fragment}.tar.gz"
|
||||
else:
|
||||
raise RuntimeError(f"Unsupported scheme \"{url.scheme}\"")
|
||||
|
||||
def get_updates(s):
|
||||
url = urlparse(s)
|
||||
current_version = url.fragment
|
||||
|
||||
def get_repo_filename(s):
|
||||
url = urlparse(s)
|
||||
if url.scheme == "github":
|
||||
ghname = f"{url.hostname}-{url.path.replace('/', '')}"
|
||||
return f"github-{ghname}-{url.fragment}.tar.zst"
|
||||
elif url.scheme == "gitea":
|
||||
gitea_name = url.path.replace('/', '')
|
||||
gitea_host = url.hostname.split('.')[-2]
|
||||
return f"{gitea_host}-{gitea_name}-{url.fragment}.tar.zst"
|
||||
else:
|
||||
raise RuntimeError(f"Unsupported scheme \"{url.scheme}\"")
|
||||
|
||||
def get_repo_url(s):
|
||||
url = urlparse(s)
|
||||
repo_url = os.environ.get("SEMIOS_SOURCE_REPO", DEFAULT_REPO)
|
||||
return f"{repo_url}/{get_repo_filename(s)}"
|
||||
|
||||
def create_srcpkg(s, postprocess="") -> str:
|
||||
origin_url = get_origin_url(s)
|
||||
origin_dir = sources.download_decompress(origin_url)
|
||||
os.chdir(origin_dir)
|
||||
for program in postprocess.split(','):
|
||||
program = program.strip()
|
||||
if program == "":
|
||||
continue
|
||||
elif program == "rust":
|
||||
postprocess_rust()
|
||||
elif program == "autotools":
|
||||
postprocess_autotools()
|
||||
else:
|
||||
raise RuntimeError(f"Unknown postprocessor \"{program}\"")
|
||||
subprocess.run(["tar", "cpf", "../srcpkg.tar", "--numeric-owner", "."], check=True)
|
||||
os.chdir("../")
|
||||
subprocess.run(["zstd", "-q", "-f", "-o", get_repo_filename(s), "srcpkg.tar"], check=True)
|
||||
return os.getcwd() + "/" + get_repo_filename(s)
|
||||
+13
-8
@@ -52,14 +52,7 @@ def zip_common_root(zip_file: zipfile.ZipFile) -> str | 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
|
||||
def download_decompress(url: str) -> str:
|
||||
download_path = f"./target/{filename(url)}"
|
||||
download(url, download_path)
|
||||
|
||||
@@ -83,6 +76,18 @@ def source_url(url: str):
|
||||
with tarfile.open(download_path, "r") as tar:
|
||||
tar.extractall(extract_dir)
|
||||
|
||||
return sources_dir
|
||||
|
||||
|
||||
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
|
||||
sources_dir = download_decompress(url)
|
||||
with open("./target/sources.tag", "wt+") as file:
|
||||
file.write(sources_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user