forked from Mirror/pmbootstrap
Introduce a new module: pmb.core to contain explicitly typed pmbootstrap API. The first component being Suffix and SuffixType. This explicitly defines what suffixes are possible, future changes should aim to further constrain this API (e.g. by validating against available device codenames or architectures for buildroot suffixes). Additionally, migrate the entire codebase over to using pathlib.Path. This is a relatively new part of the Python standard library that uses a more object oriented model for path handling. It also uses strong type hinting and has other features that make it much cleaner and easier to work with than pure f-strings. The Chroot class overloads the "/" operator the same way the Path object does, allowing one to write paths relative to a given chroot as: builddir = chroot / "home/pmos/build" The Chroot class also has a string representation ("native", or "rootfs_valve-jupiter"), and a .path property for directly accessing the absolute path (as a Path object). The general idea here is to encapsulate common patterns into type hinted code, and gradually reduce the amount of assumptions made around the codebase so that future changes are easier to implement. As the chroot suffixes are now part of the Chroot class, we also implement validation for them, this encodes the rules on suffix naming and will cause a runtime exception if a suffix doesn't follow the rules.
130 lines
4.5 KiB
Python
130 lines
4.5 KiB
Python
# Copyright 2023 Oliver Smith
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
from pmb.core.types import PmbArgs
|
|
import pmb.helpers.run
|
|
import pmb.aportgen.core
|
|
import pmb.parse.apkindex
|
|
import pmb.parse.arch
|
|
|
|
|
|
def generate_apkbuild(args: PmbArgs, pkgname, deviceinfo, patches):
|
|
device = "-".join(pkgname.split("-")[1:])
|
|
carch = pmb.parse.arch.alpine_to_kernel(deviceinfo["arch"])
|
|
|
|
makedepends = ["bash", "bc", "bison", "devicepkg-dev", "findutils", "flex",
|
|
"openssl-dev", "perl"]
|
|
|
|
build = """
|
|
unset LDFLAGS
|
|
make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \\
|
|
KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS\""""
|
|
|
|
package = """
|
|
downstreamkernel_package "$builddir" "$pkgdir" "$_carch\" \\
|
|
"$_flavor" "$_outdir\""""
|
|
|
|
if deviceinfo.get("header_version") == "2":
|
|
package += """
|
|
|
|
make dtbs_install O="$_outdir" ARCH="$_carch" \\
|
|
INSTALL_DTBS_PATH="$pkgdir\"/boot/dtbs"""
|
|
|
|
if deviceinfo["bootimg_qcdt"] == "true":
|
|
build += """\n
|
|
# Master DTB (deviceinfo_bootimg_qcdt)"""
|
|
vendors = ["spreadtrum", "exynos", "other"]
|
|
soc_vendor = pmb.helpers.cli.ask("SoC vendor", vendors,
|
|
vendors[-1], complete=vendors)
|
|
if soc_vendor == "spreadtrum":
|
|
makedepends.append("dtbtool-sprd")
|
|
build += """
|
|
dtbTool-sprd -p "$_outdir/scripts/dtc/" \\
|
|
-o "$_outdir/arch/$_carch/boot"/dt.img \\
|
|
"$_outdir/arch/$_carch/boot/dts/\""""
|
|
elif soc_vendor == "exynos":
|
|
codename = "-".join(pkgname.split("-")[2:])
|
|
makedepends.append("dtbtool-exynos")
|
|
build += """
|
|
dtbTool-exynos -o "$_outdir/arch/$_carch/boot"/dt.img \\
|
|
$(find "$_outdir/arch/$_carch/boot/dts/\""""
|
|
build += f" -name *{codename}*.dtb)"
|
|
else:
|
|
makedepends.append("dtbtool")
|
|
build += """
|
|
dtbTool -o "$_outdir/arch/$_carch/boot"/dt.img \\
|
|
"$_outdir/arch/$_carch/boot/\""""
|
|
package += """
|
|
install -Dm644 "$_outdir/arch/$_carch/boot"/dt.img \\
|
|
"$pkgdir"/boot/dt.img"""
|
|
|
|
makedepends.sort()
|
|
makedepends_fmt = ("\n" + " " * 12).join(makedepends)
|
|
patches = ("\n" + " " * 12).join(patches)
|
|
content = f"""\
|
|
# Reference: <https://postmarketos.org/vendorkernel>
|
|
# Kernel config based on: arch/{carch}/configs/(CHANGEME!)
|
|
|
|
pkgname={pkgname}
|
|
pkgver=3.x.x
|
|
pkgrel=0
|
|
pkgdesc="{deviceinfo["name"]} kernel fork"
|
|
arch="{deviceinfo["arch"]}"
|
|
_carch="{carch}"
|
|
_flavor="{device}"
|
|
url="https://kernel.org"
|
|
license="GPL-2.0-only"
|
|
options="!strip !check !tracedeps pmb:cross-native"
|
|
makedepends="
|
|
{makedepends_fmt}
|
|
"
|
|
|
|
# Source
|
|
_repository="(CHANGEME!)"
|
|
_commit="ffffffffffffffffffffffffffffffffffffffff"
|
|
_config="config-$_flavor.$arch"
|
|
source="
|
|
$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
|
|
$_config
|
|
{patches}
|
|
"
|
|
builddir="$srcdir/$_repository-$_commit"
|
|
_outdir="out"
|
|
|
|
prepare() {{
|
|
default_prepare
|
|
. downstreamkernel_prepare
|
|
}}
|
|
|
|
build() {{{build}
|
|
}}
|
|
|
|
package() {{{package}
|
|
}}
|
|
|
|
sha512sums="(run 'pmbootstrap checksum {pkgname}' to fill)"
|
|
"""
|
|
|
|
# Write the file
|
|
with (pmb.config.work / "aportgen/APKBUILD").open("w", encoding="utf-8") as hndl:
|
|
for line in content.rstrip().split("\n"):
|
|
hndl.write(line[8:].replace(" " * 4, "\t") + "\n")
|
|
|
|
|
|
def generate(args: PmbArgs, pkgname):
|
|
device = "-".join(pkgname.split("-")[1:])
|
|
deviceinfo = pmb.parse.deviceinfo(args, device)
|
|
|
|
# Symlink commonly used patches
|
|
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "aportgen"])
|
|
patches = [
|
|
"gcc7-give-up-on-ilog2-const-optimizations.patch",
|
|
"gcc8-fix-put-user.patch",
|
|
"gcc10-extern_YYLOC_global_declaration.patch",
|
|
"kernel-use-the-gnu89-standard-explicitly.patch",
|
|
]
|
|
for patch in patches:
|
|
pmb.helpers.run.user(args, ["ln", "-s",
|
|
"../../.shared-patches/linux/" + patch,
|
|
(pmb.config.work / "aportgen" / patch)])
|
|
|
|
generate_apkbuild(args, pkgname, deviceinfo, patches)
|