diff --git a/recipes/linux-kbuild-tree/all/conanfile.py b/recipes/linux-kbuild-tree/all/conanfile.py index bfde83a..708962f 100644 --- a/recipes/linux-kbuild-tree/all/conanfile.py +++ b/recipes/linux-kbuild-tree/all/conanfile.py @@ -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. diff --git a/recipes/linux-kbuild-tree/all/test_package/Makefile b/recipes/linux-kbuild-tree/all/test_package/Makefile new file mode 100644 index 0000000..c73dee3 --- /dev/null +++ b/recipes/linux-kbuild-tree/all/test_package/Makefile @@ -0,0 +1 @@ +obj-m += test_kbuild_module.o diff --git a/recipes/linux-kbuild-tree/all/test_package/conanfile.py b/recipes/linux-kbuild-tree/all/test_package/conanfile.py new file mode 100644 index 0000000..51c9150 --- /dev/null +++ b/recipes/linux-kbuild-tree/all/test_package/conanfile.py @@ -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 diff --git a/recipes/linux-kbuild-tree/all/test_package/test_kbuild_module.c b/recipes/linux-kbuild-tree/all/test_package/test_kbuild_module.c new file mode 100644 index 0000000..79ec65f --- /dev/null +++ b/recipes/linux-kbuild-tree/all/test_package/test_kbuild_module.c @@ -0,0 +1,17 @@ +#include +#include + +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");