import argparse import importlib import os import shutil import sys import hooks import lib.arch import lib.make import lib.pkgcomposer import lib.sources os.chdir(os.path.dirname(__file__)) sys.path.append(os.path.abspath("lib")) argparser = argparse.ArgumentParser( description="SemiOS source package repository helper" ) argparser.add_argument( "--target", type=str, help="Target architecture to build the package for" ) argparser.add_argument("--build", type=str, help="Package to build") argparser.add_argument("--clean", type=str, help="Package to clean") args = argparser.parse_args() if args.target: lib.arch.set_target(args.target) else: lib.arch.set_target(lib.arch.get_target()) def run_build_package(package: str): try: os.chdir(f"packages/{package}") os.makedirs("target", exist_ok=True) except Exception: print(f"No such package {package}") exit(1) package_dir = os.getcwd() importlib.import_module(f"packages.{package}.pkgbuild") # Check architecture support if not lib.make._supported_arch(lib.arch.get_target()): print(f"Architecture {lib.arch.get_target()} is not supported for this package") exit(1) # Build the package if lib.make._on_build: os.chdir(lib.sources.sources_dir_name()) lib.make._on_build() else: print("on_build(): Not defined") # Run `post_build` hooks for n in hooks.post_build.keys(): if n in lib.make._blocked_hooks: continue hooks.post_build[n]() # Pack packages for pkgname in lib.make._pkginfo.keys(): if pkgname == lib.make._key_global: continue pkginfo = lib.make._pkginfo[pkgname] pkgver = pkginfo[lib.make._key_version] if pkginfo.get(lib.make._key_arch_any): pkgarch = "any" else: pkgarch = lib.arch.get_target() pkgfilename = f"{pkgname}={pkgver}@{pkgarch}" composer = lib.pkgcomposer.PkgComposer( f"{package_dir}/target/{pkgfilename}.pkg" ) composer.setworkdir(f"{package_dir}/target/{pkgfilename}") pkginfo[lib.make._key_on_pack](composer) manifest = { "name": pkgname, "version": pkgver, "arch": pkgarch, } composer.write_manifest(manifest) composer.compose() def run_clean_package(package: str): try: shutil.rmtree(f"packages/{package}/target") except Exception: pass if args.build: run_build_package(args.build) if args.clean: run_clean_package(args.clean)