This repository was archived by the owner on Nov 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.py
More file actions
96 lines (77 loc) · 2.19 KB
/
cli.py
File metadata and controls
96 lines (77 loc) · 2.19 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
#!/usr/bin/env python3
import os
import shutil
from pathlib import Path
from typing import Annotated
import dotenv
import typer
from typer import Option
from typer.main import Typer
from kernel_builder.config.config import LOGFILE
from kernel_builder.constants import OUTPUT, ROOT, TOOLCHAIN, WORKSPACE
from kernel_builder.kernel_builder import KernelBuilder
from kernel_builder.utils.log import configure_log
app: Typer = typer.Typer(help="GKI Kernel Builder CLI", pretty_exceptions_enable=False)
def _bool_env(var: str, default: bool = False) -> bool:
return os.getenv(var, str(default)).lower() in ("true", "1", "yes")
@app.command()
def build(
ksu: Annotated[
str,
Option(
"--ksu",
"-k",
envvar="KSU",
help="KernelSU variant (NONE, OFFICIAL, SUKI, NEXT)",
),
] = "NONE",
susfs: Annotated[
bool,
Option(
"--susfs/--no-susfs",
"-s",
help="Enable SUSFS support",
),
] = _bool_env("SUSFS"),
lxc: Annotated[
bool,
Option(
"--lxc/--no-lxc",
"-l",
help="Enable or disable LXC",
),
] = _bool_env("LXC"),
) -> None:
if ksu == "NONE" and susfs:
typer.secho("[ERROR] SUSFS requires KernelSU", err=True, fg=typer.colors.RED)
raise typer.Exit(1)
if os.getenv("GITHUB_ACTIONS") != "true":
dotenv.load_dotenv()
configure_log(logfile=LOGFILE)
os.environ.update(
KSU=str(ksu),
SUSFS=str(susfs).lower(),
LXC=str(lxc).lower(),
)
builder: KernelBuilder = KernelBuilder(ksu, susfs, lxc)
builder.run_build()
@app.command()
def clean(
all: Annotated[
bool,
typer.Option(
"--all/--no-all",
"-a",
help="Also delete dist/ (output) directory",
),
] = False,
) -> None:
targets: list[Path] = [WORKSPACE, TOOLCHAIN]
if all:
targets.append(OUTPUT)
for folder in targets:
shutil.rmtree(folder, ignore_errors=True)
(ROOT / "github.env").unlink(missing_ok=True)
typer.secho("Cleanup completed!", fg=typer.colors.GREEN)
if __name__ == "__main__":
app()