-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* eudev: Add recipe * Set pkg_config_name to libudev * Enable libblkid * Specify requires and use consistent option name with_selinux * Bump to the latest version * Fix compatibility of the pkg-config file Set the version for pkg-config properly and set exec_prefix. This maps to version checks for libudev. * Bump version * Add PkgConfigDeps to test package * Convert version to string * Fix version for Conan V1 * Save version of libudev to a file for package_info * Bump linux-headers-generic to 6.5.9 --------- Co-authored-by: Rubén Rincón Blanco <[email protected]> Co-authored-by: Daniel <[email protected]>
- Loading branch information
1 parent
a4a994f
commit cab4970
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"3.2.14": | ||
url: "https://github.com/eudev-project/eudev/releases/download/v3.2.14/eudev-3.2.14.tar.gz" | ||
sha256: "8da4319102f24abbf7fff5ce9c416af848df163b29590e666d334cc1927f006f" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import os | ||
import re | ||
|
||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.build import cross_building | ||
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv | ||
from conan.tools.files import copy, get, load, rm, rmdir, save | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps, PkgConfigDeps | ||
from conan.tools.layout import basic_layout | ||
|
||
|
||
required_conan_version = ">=1.54.0" | ||
|
||
|
||
class EudevConan(ConanFile): | ||
name = "eudev" | ||
description = "eudev is a standalone dynamic and persistent device naming support (aka userspace devfs) daemon that runs independently from the init system." | ||
license = "GPL-2.0-or-later" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/eudev-project/eudev" | ||
topics = ("device", "udev") | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"hwdb": [True, False], | ||
"mtd_probe": [True, False], | ||
"programs": [True, False], | ||
"with_kmod": [True, False], | ||
"with_libblkid": [True, False], | ||
"with_selinux": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"hwdb": False, | ||
"mtd_probe": False, | ||
"programs": True, | ||
"with_kmod": True, | ||
"with_libblkid": True, | ||
"with_selinux": True, | ||
} | ||
provides = "libudev" | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
self.settings.rm_safe("compiler.cppstd") | ||
self.settings.rm_safe("compiler.libcxx") | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def requirements(self): | ||
self.requires("acl/2.3.1") | ||
self.requires("libcap/2.69") | ||
self.requires("libxslt/1.1.34") | ||
self.requires("linux-headers-generic/6.5.9") | ||
|
||
if self.options.with_kmod: | ||
self.requires("kmod/30") | ||
if self.options.with_libblkid: | ||
self.requires("libmount/2.39.2") | ||
if self.options.with_selinux: | ||
self.requires("libselinux/3.6") | ||
|
||
def validate(self): | ||
if self.settings.os != "Linux": | ||
raise ConanInvalidConfiguration(f"{self.ref} is not supported on {self.settings.os}.") | ||
|
||
def build_requirements(self): | ||
self.tool_requires("gperf/3.1") | ||
if not self.conf.get("tools.gnu:pkg_config", check_type=str): | ||
self.tool_requires("pkgconf/2.1.0") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
env = VirtualBuildEnv(self) | ||
env.generate() | ||
if not cross_building(self): | ||
env = VirtualRunEnv(self) | ||
env.generate(scope="build") | ||
tc = AutotoolsToolchain(self) | ||
def yes_no(v): | ||
return "yes" if v else "no" | ||
tc.configure_args.extend([ | ||
"--sysconfdir=${prefix}/res", | ||
f"--enable-programs={yes_no(self.options.programs)}", | ||
f"--enable-blkid={yes_no(self.options.with_libblkid)}", | ||
f"--enable-selinux={yes_no(self.options.with_selinux)}", | ||
f"--enable-kmod={yes_no(self.options.with_kmod)}", | ||
f"--enable-hwdb={yes_no(self.options.hwdb)}", | ||
f"--enable-mtd_probe={yes_no(self.options.mtd_probe)}", | ||
"--enable-manpages=no", | ||
]) | ||
tc.generate() | ||
tc = PkgConfigDeps(self) | ||
tc.generate() | ||
tc = AutotoolsDeps(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
autotools = Autotools(self) | ||
autotools.configure() | ||
autotools.make() | ||
|
||
@property | ||
def _libudev_version_txt(self): | ||
return os.path.join(self.package_folder, "res", f"{self.name}-libudev-version.txt") | ||
|
||
def package(self): | ||
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
autotools = Autotools(self) | ||
autotools.install() | ||
|
||
pkg_config = load(self, os.path.join(self.package_folder, "lib", "pkgconfig", "libudev.pc")) | ||
libudev_version = next(re.finditer("^Version: ([^\n$]+)[$\n]", pkg_config, flags=re.MULTILINE)).group(1) | ||
save(self, self._libudev_version_txt, libudev_version) | ||
|
||
rm(self, "*.la", os.path.join(self.package_folder, "lib")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["udev"] | ||
libudev_version = load(self, self._libudev_version_txt).strip() | ||
self.cpp_info.set_property("pkg_config_name", "libudev") | ||
self.cpp_info.set_property("system_package_version", str(libudev_version)) | ||
pkgconfig_variables = { | ||
'exec_prefix': '${prefix}', | ||
} | ||
self.cpp_info.set_property( | ||
"pkg_config_custom_content", | ||
"\n".join(f"{key}={value}" for key, value in pkgconfig_variables.items())) | ||
self.cpp_info.requires = ["acl::acl", "libcap::cap", "libxslt::xslt", "linux-headers-generic::linux-headers-generic"] | ||
if self.options.with_kmod: | ||
self.cpp_info.requires.append("kmod::kmod") | ||
if self.options.with_libblkid: | ||
self.cpp_info.requires.append("libmount::libblkid") | ||
if self.options.with_selinux: | ||
self.cpp_info.requires.append("libselinux::selinux") | ||
|
||
# todo Remove this workaround for Conan v1 | ||
self.cpp_info.set_property("component_version", str(libudev_version)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES C) | ||
|
||
find_package(eudev REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE eudev::eudev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
from conan.tools.gnu import PkgConfig | ||
from conan.tools.scm import Version | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "PkgConfigDeps", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
pkg_config = PkgConfig(self, "libudev", pkg_config_path=self.generators_folder) | ||
assert Version(pkg_config.version) >= 251, f"{pkg_config.version} should be >= 251" | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <libudev.h> | ||
|
||
|
||
int main() { | ||
struct udev *udev; | ||
struct udev_enumerate *enumerate; | ||
|
||
udev = udev_new(); | ||
if (!udev) { | ||
fprintf(stderr, "Cannot create udev context.\n"); | ||
return 1; | ||
} | ||
|
||
enumerate = udev_enumerate_new(udev); | ||
if (!enumerate) { | ||
fprintf(stderr, "Cannot create enumerate context.\n"); | ||
} | ||
|
||
udev_enumerate_unref(enumerate); | ||
udev_unref(udev); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"3.2.14": | ||
folder: all |