mirror of
https://github.com/BigfootACA/arch-image-builder.git
synced 2024-11-11 05:57:52 +08:00
builder: add preset for build package
Signed-off-by: BigfootACA <bigfoot@classfun.cn>
This commit is contained in:
parent
f9fe91f5e9
commit
245a0ab00f
@ -11,7 +11,7 @@ Currently only support Arch based distros
|
||||
Install required packages
|
||||
|
||||
```commandline
|
||||
pacman -S rsync pyalpm python-yaml python-libarchive-c
|
||||
pacman -S p7zip rsync pyalpm python-yaml python-libarchive-c
|
||||
```
|
||||
|
||||
For cross build (UNTESTED)
|
||||
@ -29,7 +29,8 @@ python build.py -c target/ayn-odin2-sdcard,locale/zh-cn,desktop/gnome
|
||||
## Options
|
||||
|
||||
| Option | Description |
|
||||
|-------------------------------------|---------------------------|
|
||||
|-------------------------------------|----------------------------------|
|
||||
| -p PRESET, --preset PRESET | Select preset to create package |
|
||||
| -c CONFIG, --config CONFIG | Select configs to build |
|
||||
| -o WORKSPACE, --workspace WORKSPACE | Set workspace for builder |
|
||||
| -d, --debug | Enable debug logging |
|
||||
|
@ -105,3 +105,14 @@ def load_configs(ctx: ArchBuilderContext, configs: list[str]):
|
||||
if ctx.config is None:
|
||||
raise ArchBuilderConfigError("no any config loaded")
|
||||
log.debug(f"loaded {loaded} configs")
|
||||
|
||||
|
||||
def load_preset(ctx: ArchBuilderContext, preset: str):
|
||||
file = preset
|
||||
if not preset.startswith("/"):
|
||||
file = "presets/" + preset
|
||||
ctx.preset = True
|
||||
load_configs(ctx, [file])
|
||||
if "package" not in ctx.config:
|
||||
raise ArchBuilderConfigError("bad preset config")
|
||||
log.info(f"loaded preset {preset}")
|
||||
|
@ -1,5 +1,6 @@
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from subprocess import Popen, PIPE
|
||||
from logging import getLogger
|
||||
from builder.lib.cpu import cpu_arch_get
|
||||
@ -88,6 +89,16 @@ class ArchBuilderContext:
|
||||
passwd: PasswdFile = PasswdFile()
|
||||
group: GroupFile = GroupFile()
|
||||
|
||||
"""
|
||||
Use a preset to build package
|
||||
"""
|
||||
preset: bool = False
|
||||
|
||||
"""
|
||||
Package version
|
||||
"""
|
||||
version: str = datetime.now().strftime('%Y%m%d%H%M%S')
|
||||
|
||||
def get(self, key: str, default=None):
|
||||
"""
|
||||
Get config value
|
||||
@ -101,7 +112,9 @@ class ArchBuilderContext:
|
||||
|
||||
def __init__(self):
|
||||
self.cgroup = CGroup("arch-image-builder")
|
||||
self.cgroup.create()
|
||||
self.config["version"] = self.version
|
||||
try: self.cgroup.create()
|
||||
except: log.warning("failed to create cgroup", exc_info=1)
|
||||
|
||||
def __deinit__(self):
|
||||
self.cleanup()
|
||||
|
@ -6,6 +6,7 @@ from argparse import ArgumentParser
|
||||
from builder.build import bootstrap
|
||||
from builder.lib import config, utils
|
||||
from builder.lib.context import ArchBuilderContext
|
||||
from builder.lib.config import ArchBuilderConfigError
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -14,7 +15,8 @@ def parse_arguments(ctx: ArchBuilderContext):
|
||||
prog="arch-image-builder",
|
||||
description="Build flashable image for Arch Linux",
|
||||
)
|
||||
parser.add_argument("-c", "--config", help="Select config to build", required=True, action='append')
|
||||
parser.add_argument("-p", "--preset", help="Select preset to create package")
|
||||
parser.add_argument("-c", "--config", help="Select config to build", action='append')
|
||||
parser.add_argument("-o", "--workspace", help="Set workspace for builder", default=ctx.work)
|
||||
parser.add_argument("-d", "--debug", help="Enable debug logging", default=False, action='store_true')
|
||||
parser.add_argument("-G", "--no-gpgcheck", help="Disable GPG check", default=False, action='store_true')
|
||||
@ -31,9 +33,16 @@ def parse_arguments(ctx: ArchBuilderContext):
|
||||
|
||||
# collect configs path
|
||||
configs = []
|
||||
if args.config:
|
||||
for conf in args.config:
|
||||
configs.extend(conf.split(","))
|
||||
|
||||
# load preset config for build package
|
||||
if args.preset:
|
||||
config.load_preset(ctx, args.preset)
|
||||
pcfgs = ctx.get("package.configs", [])
|
||||
configs.extend(pcfgs)
|
||||
|
||||
# load and populate configs
|
||||
config.load_configs(ctx, configs)
|
||||
config.populate_config(ctx)
|
||||
@ -63,6 +72,20 @@ def check_system():
|
||||
raise FileNotFoundError("pacman not found")
|
||||
|
||||
|
||||
def done_package(ctx: ArchBuilderContext):
|
||||
file: str = ctx.get("package.file", "")
|
||||
out = file
|
||||
if not out.startswith("/"):
|
||||
out = os.path.join(ctx.work, file)
|
||||
if not out.endswith(".7z"):
|
||||
raise ArchBuilderConfigError("current only supports 7z")
|
||||
log.info(f"creating package {file}")
|
||||
args = ["7z", "a", "-ms=on", "-mx=9", out, "."]
|
||||
ret = ctx.run_external(args, cwd=ctx.get_output())
|
||||
if ret != 0: raise OSError("create package failed")
|
||||
log.info(f"created package at {out}")
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(stream=stdout, level=logging.INFO)
|
||||
check_system()
|
||||
@ -71,7 +94,10 @@ def main():
|
||||
ctx.dir = os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
||||
ctx.work = os.path.realpath(os.path.join(ctx.dir, "build"))
|
||||
parse_arguments(ctx)
|
||||
log.info(f"package version: {ctx.version}")
|
||||
log.info(f"source tree folder: {ctx.dir}")
|
||||
log.info(f"workspace folder: {ctx.work}")
|
||||
log.info(f"build target name: {ctx.target}")
|
||||
bootstrap.build_rootfs(ctx)
|
||||
if ctx.preset:
|
||||
done_package(ctx)
|
||||
|
5
configs/presets/ayn-odin2-sdcard-gnome-global.yaml
Normal file
5
configs/presets/ayn-odin2-sdcard-gnome-global.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
package:
|
||||
file: ArchLinuxARM-AYN-Odin2-SDCard-GNOME-Global-${version}.7z
|
||||
configs:
|
||||
- target/ayn-odin2-sdcard
|
||||
- desktop/gnome
|
6
configs/presets/ayn-odin2-sdcard-gnome-zh-cn.yaml
Normal file
6
configs/presets/ayn-odin2-sdcard-gnome-zh-cn.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
package:
|
||||
file: ArchLinuxARM-AYN-Odin2-SDCard-GNOME-zh_CN-${version}.7z
|
||||
configs:
|
||||
- target/ayn-odin2-sdcard
|
||||
- locale/zh-cn
|
||||
- desktop/gnome
|
5
configs/presets/ayn-odin2-ufs-gnome-global.yaml
Normal file
5
configs/presets/ayn-odin2-ufs-gnome-global.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
package:
|
||||
file: ArchLinuxARM-AYN-Odin2-UFS-GNOME-Global-${version}.7z
|
||||
configs:
|
||||
- target/ayn-odin2-ufs
|
||||
- desktop/gnome
|
6
configs/presets/ayn-odin2-ufs-gnome-zh-cn.yaml
Normal file
6
configs/presets/ayn-odin2-ufs-gnome-zh-cn.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
package:
|
||||
file: ArchLinuxARM-AYN-Odin2-UFS-GNOME-zh_CN-${version}.7z
|
||||
configs:
|
||||
- target/ayn-odin2-ufs
|
||||
- locale/zh-cn
|
||||
- desktop/gnome
|
Loading…
Reference in New Issue
Block a user