build: envkernel: overmount outdir/Makefile to use local include (MR 2504)

the kernel has pending patches in -next which adjust the generated
Makefile in the output directory to include the source tree makefile
with an absolute path, this breaks envkernel which relies on it being a
relative path.

Fix this by mounting our own Makefile instead using the relative path.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-11-30 00:47:31 +01:00 committed by Oliver Smith
parent 932ac18791
commit aa847501c8
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -119,6 +119,20 @@ def modify_apkbuild(pkgname: str, aport: Path) -> None:
pmb.aportgen.core.rewrite(pkgname, apkbuild_path, fields=fields)
def overmount_makefile(context: Context, kbuild_out: str) -> None:
makefile = context.config.work / "tmp_kernel.mk"
makefile.open("w").write("""
# Automatically generated by pmbootstrap to use relative include paths
include ../Makefile
""")
makefile_target = Chroot.native() / "mnt/linux" / kbuild_out / "Makefile"
logging.info("Overmounting Makefile to use relative include paths")
if not pmb.helpers.mount.ismount(makefile_target):
pmb.helpers.mount.bind_file(makefile, makefile_target)
def run_abuild(
context: Context, pkgname: str, arch: Arch, apkbuild_path: Path, kbuild_out: str
) -> None:
@ -141,6 +155,9 @@ def run_abuild(
pmb.helpers.mount.bind(Path("."), chroot / "mnt/linux")
if kbuild_out:
overmount_makefile(context, kbuild_out)
if not os.path.exists(chroot / kbuild_out_source):
raise RuntimeError(
"No '.output' dir found in your kernel source dir. "
@ -180,7 +197,7 @@ def run_abuild(
)
# Create symlink from abuild working directory to envkernel build directory
pmb.chroot.root(["ln", "-sf", "/mnt/linux", build_path / "src"])
pmb.chroot.root(["ln", "-sf", kbuild_out_source, build_path / "src"])
cmd: list[PathString] = ["cp", apkbuild_path, chroot / build_path / "APKBUILD"]
pmb.helpers.run.root(cmd)