Merge pull request #5 from existedinnettw/fix/large_LKB_source

This commit is contained in:
existedinnettw 2026-05-23 00:45:18 +08:00 committed by GitHub
commit fdeb035971
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 87 additions and 1 deletions

View File

@ -11,7 +11,9 @@ from conan.tools.files import copy, get, save
class LinuxKbuildTreeConan(ConanFile):
name = "linux-kbuild-tree"
package_type = "application"
package_type = "unknown"
upload_policy = "skip"
build_policy = "missing"
settings = "os", "arch", "compiler", "build_type"
@ -127,6 +129,11 @@ class LinuxKbuildTreeConan(ConanFile):
keep_path=False,
)
def package_info(self):
self.cpp_info.includedirs = []
self.cpp_info.libdirs = []
self.cpp_info.bindirs = []
def _linux_ref_from_version(self):
# Upstream Linux tags base releases as v6.8, while the kernel release
# and Conan package version are commonly represented as 6.8.0.

View File

@ -0,0 +1 @@
obj-m += test_kbuild_module.o

View File

@ -0,0 +1,61 @@
import os
import shlex
from conan import ConanFile
from conan.errors import ConanException
from conan.tools.files import copy
class TestPackageConan(ConanFile):
test_type = "explicit"
settings = "os", "compiler", "build_type", "arch"
exports_sources = "Makefile", "test_kbuild_module.c"
def requirements(self):
self.requires(self.tested_reference_str)
def layout(self):
self.folders.build = "build"
self.folders.generators = os.path.join(self.folders.build, "generators")
def build(self):
kernel_tree = self.dependencies["linux-kbuild-tree"].package_folder
module_dir = os.path.join(self.build_folder, "module")
copy(self, "*", src=self.source_folder, dst=module_dir)
tree_info = self._read_tree_info(kernel_tree)
arch = tree_info.get("arch", "")
cross_compile = tree_info.get("cross_compile", "")
jobs = self.conf.get("tools.build:jobs", default=None)
make_jobs = f" -j{jobs}" if jobs else ""
command = (
f"make --no-print-directory -C {shlex.quote(kernel_tree)}{make_jobs} "
f"M={shlex.quote(module_dir)} "
f"ARCH={shlex.quote(arch)} "
f"CROSS_COMPILE={shlex.quote(cross_compile)} "
"KBUILD_MODPOST_WARN=1 "
"modules"
)
self.run(command)
def test(self):
module_path = os.path.join(self.build_folder, "module", "test_kbuild_module.ko")
if not os.path.isfile(module_path):
raise ConanException(f"Kernel module was not built: {module_path}")
def _read_tree_info(self, kernel_tree):
path = os.path.join(kernel_tree, "kbuild-tree-info.txt")
if not os.path.isfile(path):
raise ConanException(f"Missing linux-kbuild-tree metadata: {path}")
result = {}
with open(path, encoding="utf-8") as tree_info:
for line in tree_info:
line = line.strip()
if not line or "=" not in line:
continue
key, value = line.split("=", 1)
result[key] = value
return result

View File

@ -0,0 +1,17 @@
#include <linux/init.h>
#include <linux/module.h>
static int __init test_kbuild_module_init(void)
{
return 0;
}
static void __exit test_kbuild_module_exit(void)
{
}
module_init(test_kbuild_module_init);
module_exit(test_kbuild_module_exit);
MODULE_DESCRIPTION("linux-kbuild-tree Conan test module");
MODULE_LICENSE("GPL");