-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmulti_build.py
More file actions
117 lines (97 loc) · 3.22 KB
/
multi_build.py
File metadata and controls
117 lines (97 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""
Wrapper-script to launch the builder for multiple setting combinations.
"""
import os
import shutil
import argparse
import subprocess
from pathlib import Path
def parse_args() -> argparse.Namespace:
"""Parse arguments.
:return: Namespace of arguments.
:rtype: argparse.Namespace
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--env",
choices={"docker", "podman", "local"},
default="docker"
)
return parser.parse_args()
def rmove(src: Path, dst: Path) -> None:
"""Recursively move files from one directory to another.
:param pathlib.Path src: Source path.
:param pathlib.Path dst: Destination path.
:return: None
"""
# for a directory
if src.is_dir():
if not dst.is_dir():
os.makedirs(dst)
contents = os.listdir(src)
for e in contents:
# do not copy restricted files
if e != src:
src_e = src / e
dst_e = dst / e
shutil.move(src_e, dst_e)
# for a single file
elif src.is_file():
shutil.move(src, dst)
def main(args: argparse.Namespace) -> None:
rootpath = Path(__file__).absolute().parents[1]
argsets = (
{
"command": "bundle",
"rom": "los",
"codename": "dumpling",
"lkv": "4.4",
"ksu": False
},
{
"command": "kernel",
"rom": "los",
"codename": "dumpling",
"lkv": "4.4",
"ksu": True
},
{
"command": "assets",
"rom": "los",
"codename": "cheeseburger",
"ksu": True
},
)
os.chdir(rootpath)
dir_shared = rootpath / "multi-build"
shutil.rmtree(dir_shared, ignore_errors=True)
os.makedirs(dir_shared)
for count, argset in enumerate(argsets, 1):
# define some of the values individually
benv = f"--build-env {args.env}"
base = f'--base {argset["rom"]}'
codename = f'--codename {argset["codename"]}'
lkv = f'--lkv {argset["lkv"]}' if argset["command"] in ("kernel", "bundle") else ""
ksu = "--ksu" if argset["ksu"] else ""
size = "--package-type slim" if argset["command"] == "bundle" else ""
extra = "--chroot minimal --rom-only --clean" if argset["command"] == "assets" else ""
# if the build is last, make it automatically remove the Docker/Podman image from runner
clean_image = "--clean-image" if count == len(argsets) and args.env in ("docker", "podman") else ""
# form and launch the command
cmd = f"python3 zkb {argset['command']} {benv} {base} {codename} {lkv} {size} {ksu} {clean_image} {extra}"
print(f"[CMD]: {cmd}")
subprocess.run(cmd.strip(), shell=True, check=True)
# define directory to copy artifacts to
out = ""
match argset["command"]:
case "bundle":
out = "bundle"
case "kernel":
out = "kernel"
case "assets":
out = "assets"
# convert into full path
out = Path(rootpath, out)
rmove(out, dir_shared)
if __name__ == "__main__":
main(parse_args())