Skip to content

Commit

Permalink
release: bump KSU version to v0.9.3, update interface usage, add arch…
Browse files Browse the repository at this point in the history
…itecture docs
  • Loading branch information
seppzer0 authored Apr 27, 2024
1 parent 22c1257 commit 687e7b6
Show file tree
Hide file tree
Showing 52 changed files with 803 additions and 374 deletions.
11 changes: 4 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ variables:

job-build:
stage: build_and_tag
tags:
- docker
- linux
image: docker:25.0.3-cli-alpine3.19
services:
- docker:dind
Expand All @@ -31,10 +28,10 @@ job-build:
job-tag:
stage: build_and_tag
script:
- USERNAME=$CUSTOM_CI_USERNAME
- PASSWORD=$CUSTOM_CI_PASSWORD
- EMAIL=$CUSTOM_CI_EMAIL
- TAGNAME=v$(sh scripts/get_version.sh)
- USERNAME="$CUSTOM_CI_USERNAME"
- PASSWORD="$CUSTOM_CI_PASSWORD"
- EMAIL="$CUSTOM_CI_EMAIL"
- TAGNAME="v$(sh scripts/get_version.sh)"
- git config --global user.name "${USERNAME}"
- git config --global user.email "${EMAIL}"
- git remote remove origin
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN python3 -m pip install pip --upgrade && \
# install shared tools from tools.json;
#
# The idea here is that we pre-pack all the tools into the Docker/Podman image that can be used for any device:
# (which are toolchains, binutils -- everything except device-specific kernel source);
# (toolchains, binutils -- everything except device-specific kernel source);
#
# This significantly reduces the total build time, as each time we make a build call for a device,
# only device-specific kernel source is being downloaded into the container.
Expand Down
15 changes: 9 additions & 6 deletions builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,33 @@ def main(args: argparse.Namespace) -> None:
case "local":
match args.command:
case "kernel":
KernelCommand(
kc = KernelCommand(
codename = args.codename,
base = args.base,
lkv = args.lkv,
clean_kernel = args.clean_kernel,
ksu = args.ksu,
).run()
)
kc.execute()
case "assets":
AssetsCommand(
ac = AssetsCommand(
codename = args.codename,
base = args.base,
chroot = args.chroot,
clean_assets = args.clean_assets,
rom_only = args.rom_only,
ksu = args.ksu,
).run()
)
ac.execute()
case "bundle":
BundleCommand(
bc = BundleCommand(
codename = args.codename,
base = args.base,
lkv = args.lkv,
package_type = args.package_type,
ksu = args.ksu,
).run()
)
bc.execute()


if __name__ == "__main__":
Expand Down
20 changes: 10 additions & 10 deletions builder/clients/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class GitHubApi(BaseModel):
:param Optional[str]=None file_filter: A filter to select specific files from project's artifacts.
"""

_endpoint = "https://api.github.com/repos/{}/releases/latest"
_direct_url = "https://github.com/{}"

project: str
file_filter: Optional[str] = None

def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self._endpoint = self._endpoint.format(self.project)
self._direct_url = self._direct_url.format(self.project)
@property
def endpoint(self) -> str:
return f"https://api.github.com/repos/{self.project}/releases/latest"

@property
def direct_url(self) -> str:
return f"https://github.com/{self.project}"

def run(self) -> str | None:
"""Get the latest version of an artifact from GitHub project."""
response = requests.get(self._endpoint).json()
response = requests.get(self.endpoint).json()
# this will check whether the GitHub API usage is exceeded
try:
data = response["message"]
Expand Down Expand Up @@ -58,10 +58,10 @@ def run(self) -> str | None:
data = "".join(browser_download_urls)
except Exception:
# if not available via API -- use regular "git clone"
rdir = Path(dcfg.assets, self._direct_url.rsplit("/", 1)[1])
rdir = Path(dcfg.assets, self.direct_url.rsplit("/", 1)[1])
msg.note(f"Non-API GitHub resolution for {self.project}")
cm.remove(rdir)
ccmd.launch(f"git clone --depth 1 --remote-submodules --recurse-submodules --shallow-submodules {self._direct_url} {rdir}")
ccmd.launch(f"git clone --depth 1 --remote-submodules --recurse-submodules --shallow-submodules {self.direct_url} {rdir}")
os.chdir(rdir)
cm.remove(".git*")
os.chdir(dcfg.assets)
Expand Down
2 changes: 1 addition & 1 deletion builder/clients/rom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class RomApi(BaseModel, IRomApi):
"""A generic class for interacting with ROMs' APIs.
"""Generic class for interacting with ROMs' APIs.
:param str endpoint: API endpoint to interact with.
:param str json_key: A JSON key to look for in the response.
Expand Down
26 changes: 24 additions & 2 deletions builder/commands/assets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
from typing import Literal
from pydantic import BaseModel

from builder.core import AssetsCollector
from builder.interfaces import ICommand


class AssetsCommand(BaseModel, ICommand):
"""Command responsible for launching the 'assets_collector' core module directly.
:param str codename: Device codename.
:param str base: Kernel source base.
:param Literal["full","minimal"] chroot: Chroot type.
:param bool rom_only: Flag indicating ROM-only asset collection.
:param bool ksu: Flag indicating KernelSU support.
"""

codename: str
base: str
chroot: Literal["full", "minimal"]
clean_assets: bool
rom_only: bool
ksu: bool

class AssetsCommand(AssetsCollector):
"""A command responsible for launching the 'assets_collector' core module directly."""
def execute(self) -> None:
kb = AssetsCollector(**self.__dict__)
kb.run()
22 changes: 13 additions & 9 deletions builder/commands/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from builder.core import KernelBuilder, AssetsCollector
from builder.tools import cleaning as cm, commands as ccmd, fileoperations as fo, messages as msg
from builder.configs import DirectoryConfig as dcfg
from builder.interfaces import IBundleCommand
from builder.managers import ResourceManager
from builder.interfaces import ICommand, IBundleCommand


class BundleCommand(BaseModel, IBundleCommand):
"""A command that packages the artifacts produced both
class BundleCommand(BaseModel, ICommand, IBundleCommand):
"""Command that packages the artifacts produced both
by 'kernel_builder' and 'assets_collector' core modules.
:param str base: Kernel source base.
Expand All @@ -29,27 +30,30 @@ class BundleCommand(BaseModel, IBundleCommand):

def build_kernel(self, rom_name: str, clean_only: bool = False) -> None:
if not dcfg.kernel.is_dir() or clean_only is True:
KernelBuilder(
kb = KernelBuilder(
codename = self.codename,
base = rom_name,
lkv = self.lkv,
clean_kernel = clean_only,
ksu = self.ksu,
).run()
rm=ResourceManager(codename=self.codename, lkv=self.lkv, base=self.base)
)
kb.run()

@property
def _rom_only_flag(self) -> bool:
return True if "full" not in self.package_type else False

def collect_assets(self, rom_name: str, chroot: Literal["full", "minimal"]) -> None:
AssetsCollector(
ac = AssetsCollector(
codename = self.codename,
base = rom_name,
chroot = chroot,
clean_assets = True,
rom_only = self._rom_only_flag,
ksu = self.ksu,
).run()
)
ac.run()

def conan_sources(self) -> None:
sourcedir = dcfg.root / "source"
Expand Down Expand Up @@ -97,7 +101,7 @@ def conan_upload(reference: str) -> None:
f"conan upload -f {reference} -r {alias}"
ccmd.launch(cmd)

def run(self) -> None:
def execute(self) -> None:
os.chdir(dcfg.root)
# determine the bundle type and process it
match self.package_type:
Expand All @@ -111,7 +115,7 @@ def run(self) -> None:
for f in contents:
os.remove(f)
else:
os.mkdir(dcfg.bundle)
os.makedirs(dcfg.bundle)
# copy kernel
kfn = "".join(os.listdir(dcfg.kernel))
shutil.copy(dcfg.kernel / kfn, dcfg.bundle / kfn)
Expand Down
29 changes: 25 additions & 4 deletions builder/commands/kernel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
from pydantic import BaseModel

from builder.core import KernelBuilder
from builder.managers import ResourceManager
from builder.interfaces import ICommand

class KernelCommand(BaseModel, ICommand):
"""Command responsible for launching the 'kernel_builder' core module directly.
:param str codename: Device codename.
:param str base: Kernel source base.
:param str lkv: Linux kernel version.
:param bool clean_kernel: Flag to clean folder with kernel sources.
:param bool ksu: Flag indicating KernelSU support.
"""

class KernelCommand(KernelBuilder):
"""A command responsible for launching the 'kernel_builder' core module directly."""
codename: str
base: str
lkv: str
clean_kernel: bool
ksu: bool

def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
def execute(self) -> None:
# create resource manager and pass it to the builder
kb = KernelBuilder(
**self.__dict__,
rm=ResourceManager(codename=self.codename, lkv=self.lkv, base=self.base)
)
kb.run()
2 changes: 1 addition & 1 deletion builder/configs/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class ArgumentConfig(BaseModel):
"""A variable storage to use across the application.
"""Variable storage for use across the app.
:param Literal["docker","podman"] benv: Build environment.
:param Literal["kernel","assets","bundle"] command: Builder command to be launched.
Expand Down
3 changes: 2 additions & 1 deletion builder/configs/directory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import Path
from pydantic.dataclasses import dataclass


@dataclass
class DirectoryConfig:
"""A config for key directory paths."""
"""Config for key directory paths."""
root: Path = Path(__file__).absolute().parents[2]
kernel: Path = root / "kernel"
assets: Path = root / "assets"
Expand Down
2 changes: 1 addition & 1 deletion builder/core/assets_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _check(self) -> None:
os.chdir(dcfg.root)
# directory check
if not dcfg.assets.is_dir():
os.mkdir(dcfg.assets)
os.makedirs(dcfg.assets)
else:
if len(os.listdir(dcfg.assets)) != 0:
cmsg = f'[ ? ] Found an existing "{dcfg.assets.name}" folder, clean it? [Y/n]: '
Expand Down
Loading

0 comments on commit 687e7b6

Please sign in to comment.