From 9bb342065ffaae1f6fd46594ea14e8ff7bfd9a4a Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 19 Apr 2024 16:11:26 +0300 Subject: [PATCH] (#18800) openldap: migrate to Conan v2 * openldap: migrate to Conan v2 * openldap: clean up package_folder * openldap: bump cyrus-sasl * openldap: add VirtualRunEnv for OpenSSL * openldap: add v2.6.6, simplify patching * openldap: project is C-only, not C++ * openldap: add resolv system dep * openldap: downgrade to cyrus-sasl/2.1.27 to fix missing binary, maybe * openldap: bump cyrus-sasl * openldap: bump to v2.6.7 * openldap: apply PR suggestions * openldap: add components with pkg_config_names * Simplify slapd install for openldap Signed-off-by: Uilian Ries --------- Signed-off-by: Uilian Ries Co-authored-by: Uilian Ries --- recipes/openldap/all/conandata.yml | 11 +- recipes/openldap/all/conanfile.py | 152 +++++++++--------- .../all/patches/configure-2.6.1.patch | 12 -- .../openldap/all/test_package/CMakeLists.txt | 13 +- .../openldap/all/test_package/conanfile.py | 21 ++- .../{test_package.cpp => test_package.c} | 5 +- .../all/test_v1_package/CMakeLists.txt | 8 + .../openldap/all/test_v1_package/conanfile.py | 17 ++ recipes/openldap/config.yml | 2 + 9 files changed, 134 insertions(+), 107 deletions(-) delete mode 100644 recipes/openldap/all/patches/configure-2.6.1.patch rename recipes/openldap/all/test_package/{test_package.cpp => test_package.c} (99%) create mode 100644 recipes/openldap/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/openldap/all/test_v1_package/conanfile.py diff --git a/recipes/openldap/all/conandata.yml b/recipes/openldap/all/conandata.yml index 9fc035f4ad145..0b8d44649e6e8 100644 --- a/recipes/openldap/all/conandata.yml +++ b/recipes/openldap/all/conandata.yml @@ -1,8 +1,7 @@ sources: + "2.6.7": + url: "https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.7.tgz" + sha256: "cd775f625c944ed78a3da18a03b03b08eea73c8aabc97b41bb336e9a10954930" "2.6.1": - url: https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.1.tgz - sha256: 9d576ea6962d7db8a2e2808574e8c257c15aef55f403a1fb5a0faf35de70e6f3 -patches: - "2.6.1": - - base_path: source_subfolder - patch_file: patches/configure-2.6.1.patch + url: "https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.1.tgz" + sha256: "9d576ea6962d7db8a2e2808574e8c257c15aef55f403a1fb5a0faf35de70e6f3" diff --git a/recipes/openldap/all/conanfile.py b/recipes/openldap/all/conanfile.py index 49a19895302e6..dd459608a66e3 100644 --- a/recipes/openldap/all/conanfile.py +++ b/recipes/openldap/all/conanfile.py @@ -1,110 +1,114 @@ import os -from conans import ConanFile, AutoToolsBuildEnvironment, tools -from conans.errors import ConanInvalidConfiguration -required_conan_version = ">=1.43.0" + +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import cross_building +from conan.tools.env import VirtualRunEnv +from conan.tools.files import chdir, copy, get, rm, rmdir, replace_in_file +from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain +from conan.tools.layout import basic_layout + +required_conan_version = ">=1.53.0" class OpenldapConan(ConanFile): name = "openldap" - description = "OpenLDAP C++ library" + description = "OpenLDAP C library" + license = "OLDAP-2.8" url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.openldap.org/" - license = "OLDAP-2.8" topics = ("ldap", "load-balancer", "directory-access") - exports_sources = ["patches/*"] - settings = settings = "os", "compiler", "build_type", "arch" + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], - "with_cyrus_sasl": [True, False] + "with_cyrus_sasl": [True, False], } default_options = { "shared": False, "fPIC": True, - "with_cyrus_sasl": True - + "with_cyrus_sasl": True, } - _autotools = None - _configure_vars = None - - @property - def _source_subfolder(self): - return "source_subfolder" def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") - def source(self): - tools.get(**self.conan_data["sources"][self.version], - strip_root=True, destination=self._source_subfolder) + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): - self.requires("openssl/1.1.1q") + self.requires("openssl/[>=1.1 <4]") if self.options.with_cyrus_sasl: - self.requires("cyrus-sasl/2.1.27") + self.requires("cyrus-sasl/2.1.28") def validate(self): - if self.settings.os != "Linux": - raise ConanInvalidConfiguration( - f"{self.name} is only supported on Linux") - - def _configure_autotools(self): - if self._autotools: - return self._autotools - - def yes_no(v): return "yes" if v else "no" - self._autotools = AutoToolsBuildEnvironment(self) - configure_args = [ - "--enable-shared={}".format(yes_no(self.options.shared)), - "--enable-static={}".format(yes_no(not self.options.shared)), + if self.settings.os not in ["Linux", "FreeBSD"]: + raise ConanInvalidConfiguration(f"{self.name} is only supported on Linux") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") + + def yes_no(v): + return "yes" if v else "no" + + tc = AutotoolsToolchain(self) + tc.configure_args += [ "--with-cyrus_sasl={}".format(yes_no(self.options.with_cyrus_sasl)), - "--with-pic={}".format(yes_no(self.options.get_safe("fPIC", True))), "--without-fetch", "--with-tls=openssl", - "--enable-auditlog"] - self._configure_vars = self._autotools.vars - self._configure_vars["systemdsystemunitdir"] = os.path.join( - self.package_folder, "res") - - # Need to link to -pthread instead of -lpthread for gcc 8 shared=True - # on CI job. Otherwise, linking fails. - self._autotools.libs.remove("pthread") - self._configure_vars["LIBS"] = self._configure_vars["LIBS"].replace( - "-lpthread", "-pthread") - - self._autotools.configure( - args=configure_args, - configure_dir=self._source_subfolder, - vars=self._configure_vars) - return self._autotools + "--enable-auditlog", + "--libexecdir=${prefix}/bin", + f"systemdsystemunitdir={os.path.join(self.package_folder, 'res')}", + ] + tc.generate() + tc = AutotoolsDeps(self) + tc.generate() + + def _patch_sources(self): + replace_in_file(self, os.path.join(self.source_folder, "configure"), + "WITH_SYSTEMD=no\nsystemdsystemunitdir=", "WITH_SYSTEMD=no") def build(self): - for patch in self.conan_data["patches"][self.version]: - tools.patch(**patch) - autotools = self._configure_autotools() - - autotools.make(vars=self._configure_vars) + self._patch_sources() + with chdir(self, self.source_folder): + autotools = Autotools(self) + autotools.configure() + autotools.make() def package(self): - autotools = self._configure_autotools() - autotools.install(vars=self._configure_vars) - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder) - for folder in ["var", "share", "etc", "lib/pkgconfig", "res"]: - tools.rmdir(os.path.join(self.package_folder, folder)) - tools.remove_files_by_mask( - os.path.join( - self.package_folder, - "lib"), - "*.la") + with chdir(self, self.source_folder): + autotools = Autotools(self) + autotools.install() + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + copy(self, "COPYRIGHT", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + rm(self, "*.la", self.package_folder, recursive=True) + for folder in ["var", "share", "etc", os.path.join("lib", "pkgconfig"), "home"]: + rmdir(self, os.path.join(self.package_folder, folder)) def package_info(self): - bin_path = os.path.join(self.package_folder, "bin") - self.env_info.PATH.append(bin_path) - self.output.info( - "Appending PATH environment variable: {}".format(bin_path)) + self.cpp_info.components["ldap"].set_property("pkg_config_name", "ldap") + self.cpp_info.components["ldap"].libs = ["ldap"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["ldap"].system_libs = ["pthread", "resolv"] + self.cpp_info.components["ldap"].requires = ["lber", "openssl::ssl", "openssl::crypto"] + if self.options.with_cyrus_sasl: + self.cpp_info.components["ldap"].requires.append("cyrus-sasl::cyrus-sasl") - self.cpp_info.libs = ["ldap", "lber"] + self.cpp_info.components["lber"].set_property("pkg_config_name", "lber") + self.cpp_info.components["lber"].libs = ["lber"] if self.settings.os in ["Linux", "FreeBSD"]: - self.cpp_info.system_libs = ["pthread"] + self.cpp_info.components["lber"].system_libs = ["pthread"] + + # TODO: to remove in conan v2 + bin_path = os.path.join(self.package_folder, "bin") + self.env_info.PATH.append(bin_path) diff --git a/recipes/openldap/all/patches/configure-2.6.1.patch b/recipes/openldap/all/patches/configure-2.6.1.patch deleted file mode 100644 index 9fb405dfefc10..0000000000000 --- a/recipes/openldap/all/patches/configure-2.6.1.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/configure b/configure -index 8521174..8ea6133 100755 ---- a/configure -+++ b/configure -@@ -22337,7 +22337,6 @@ $as_echo "$as_me: WARNING: Strong authentication not supported!" >&2;} - fi - - WITH_SYSTEMD=no --systemdsystemunitdir= - ol_link_systemd=no - if test $ol_enable_slapd == no && test $ol_enable_balancer != yes ; then - if test $ol_with_systemd != no ; then diff --git a/recipes/openldap/all/test_package/CMakeLists.txt b/recipes/openldap/all/test_package/CMakeLists.txt index fb813fde0a56b..c77039fd606a9 100644 --- a/recipes/openldap/all/test_package/CMakeLists.txt +++ b/recipes/openldap/all/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) -find_package(openldap CONFIG REQUIRED) -add_executable(${PROJECT_NAME} test_package.cpp) +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(openldap REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) target_link_libraries(${PROJECT_NAME} openldap::openldap) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) diff --git a/recipes/openldap/all/test_package/conanfile.py b/recipes/openldap/all/test_package/conanfile.py index 49a3a66ea5bad..ef5d7042163ec 100644 --- a/recipes/openldap/all/test_package/conanfile.py +++ b/recipes/openldap/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/openldap/all/test_package/test_package.cpp b/recipes/openldap/all/test_package/test_package.c similarity index 99% rename from recipes/openldap/all/test_package/test_package.cpp rename to recipes/openldap/all/test_package/test_package.c index ab1267d80b23a..ca578bf88f1df 100644 --- a/recipes/openldap/all/test_package/test_package.cpp +++ b/recipes/openldap/all/test_package/test_package.c @@ -29,10 +29,11 @@ * for inclusion in OpenLDAP software. */ -#include -#include #include "openldap.h" +#include +#include + static int do_uri_create(LDAPURLDesc *lud) { char *uri; diff --git a/recipes/openldap/all/test_v1_package/CMakeLists.txt b/recipes/openldap/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/openldap/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/openldap/all/test_v1_package/conanfile.py b/recipes/openldap/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..49a3a66ea5bad --- /dev/null +++ b/recipes/openldap/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/openldap/config.yml b/recipes/openldap/config.yml index 36b28f1209ae7..7177bd469e00d 100644 --- a/recipes/openldap/config.yml +++ b/recipes/openldap/config.yml @@ -1,3 +1,5 @@ versions: + "2.6.7": + folder: all "2.6.1": folder: all