From 8f5bed832c4d797231f6d65ec52d03ca08c511f3 Mon Sep 17 00:00:00 2001 From: Dariusz Grabowski Date: Wed, 29 Mar 2023 09:42:48 +0200 Subject: [PATCH] (#16749) openldap: conan v2 support --- recipes/openldap/all/conandata.yml | 2 +- recipes/openldap/all/conanfile.py | 103 ++++++++---------- .../openldap/all/test_package/CMakeLists.txt | 2 - .../openldap/all/test_package/conanfile.py | 19 +++- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../openldap/all/test_v1_package/conanfile.py | 17 +++ .../all/test_v1_package/test_package.cpp | 83 ++++++++++++++ 7 files changed, 167 insertions(+), 67 deletions(-) create mode 100644 recipes/openldap/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/openldap/all/test_v1_package/conanfile.py create mode 100644 recipes/openldap/all/test_v1_package/test_package.cpp diff --git a/recipes/openldap/all/conandata.yml b/recipes/openldap/all/conandata.yml index 9fc035f4ad1451..77f9b06823ecf2 100644 --- a/recipes/openldap/all/conandata.yml +++ b/recipes/openldap/all/conandata.yml @@ -4,5 +4,5 @@ sources: sha256: 9d576ea6962d7db8a2e2808574e8c257c15aef55f403a1fb5a0faf35de70e6f3 patches: "2.6.1": - - base_path: source_subfolder + - base_path: . patch_file: patches/configure-2.6.1.patch diff --git a/recipes/openldap/all/conanfile.py b/recipes/openldap/all/conanfile.py index 49a19895302e6e..6fa93a91fc47ab 100644 --- a/recipes/openldap/all/conanfile.py +++ b/recipes/openldap/all/conanfile.py @@ -1,7 +1,11 @@ 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.tools.files import get, apply_conandata_patches, rmdir, rm, copy +from conan.tools.gnu import AutotoolsToolchain, Autotools, AutotoolsDeps +from conan.tools.apple import fix_apple_shared_install_name +from conan.tools.layout import basic_layout +from conan.errors import ConanInvalidConfiguration +required_conan_version = ">=1.55" class OpenldapConan(ConanFile): @@ -22,82 +26,63 @@ class OpenldapConan(ConanFile): "shared": False, "fPIC": True, "with_cyrus_sasl": True - } - _autotools = None - _configure_vars = None - - @property - def _source_subfolder(self): - return "source_subfolder" + short_paths = True + def layout(self): + basic_layout(self, src_folder="src") + def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") def source(self): - tools.get(**self.conan_data["sources"][self.version], - strip_root=True, destination=self._source_subfolder) + get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self.source_folder) + apply_conandata_patches(self) def requirements(self): - self.requires("openssl/1.1.1q") + self.requires("openssl/1.1.1t") if self.options.with_cyrus_sasl: self.requires("cyrus-sasl/2.1.27") 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 + f"{self.ref} is only supported on Linux") + def generate(self): 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)), - "--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 + autotools_tc = AutotoolsToolchain(self) + autotools_tc.update_configure_args({ + "--with-cyrus_sasl": yes_no(self.options.with_cyrus_sasl), + "--with-pic": yes_no(self.options.get_safe("fPIC", True)), + "--without-fetch": "", + "--with-tls": "openssl", + "--enable-auditlog": "", + "--libexecdir": "${prefix}/bin" + }) + + env = autotools_tc.environment() + env.define("systemdsystemunitdir", os.path.join(self.package_folder, "res")) + autotools_tc.generate(env) + + deps = AutotoolsDeps(self) + deps.generate() 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) + 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") + autotools = Autotools(self) + autotools.install() + fix_apple_shared_install_name(self) + 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) + for folder in ["var", "share", "etc", "lib/pkgconfig", "res", "root", "libexec", "home"]: + rmdir(self, os.path.join(self.package_folder, folder)) + rm(self, pattern="*.la", folder=os.path.join( self.package_folder,"lib"), recursive=True) def package_info(self): bin_path = os.path.join(self.package_folder, "bin") diff --git a/recipes/openldap/all/test_package/CMakeLists.txt b/recipes/openldap/all/test_package/CMakeLists.txt index fb813fde0a56b6..13991f6e706dd9 100644 --- a/recipes/openldap/all/test_package/CMakeLists.txt +++ b/recipes/openldap/all/test_package/CMakeLists.txt @@ -1,7 +1,5 @@ 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) target_link_libraries(${PROJECT_NAME} openldap::openldap) diff --git a/recipes/openldap/all/test_package/conanfile.py b/recipes/openldap/all/test_package/conanfile.py index 49a3a66ea5bad4..bee537dde211ea 100644 --- a/recipes/openldap/all/test_package/conanfile.py +++ b/recipes/openldap/all/test_package/conanfile.py @@ -1,17 +1,26 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.cmake import CMake +from conan.tools.build import cross_building +from conan.tools.layout import basic_layout import os class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeToolchain", "CMakeDeps" + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) cmake.configure() cmake.build() + def layout(self): + basic_layout(self) + 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 not cross_building(self): + cmd = os.path.join(self.cpp.build.bindir, "test_package") + self.run(cmd, env="conanrun") 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 00000000000000..fb813fde0a56b6 --- /dev/null +++ b/recipes/openldap/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +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) +target_link_libraries(${PROJECT_NAME} openldap::openldap) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) 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 00000000000000..49a3a66ea5bad4 --- /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/all/test_v1_package/test_package.cpp b/recipes/openldap/all/test_v1_package/test_package.cpp new file mode 100644 index 00000000000000..ab1267d80b23a4 --- /dev/null +++ b/recipes/openldap/all/test_v1_package/test_package.cpp @@ -0,0 +1,83 @@ +/* ldapurl -- a tool for generating LDAP URLs */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2008-2021 The OpenLDAP Foundation. + * Portions Copyright 2008 Pierangelo Masarati, SysNet + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* Portions Copyright (c) 1992-1996 Regents of the University of Michigan. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that this notice is preserved and that due credit is given + * to the University of Michigan at Ann Arbor. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. This + * software is provided ``as is'' without express or implied warranty. + */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by Pierangelo Masarati + * for inclusion in OpenLDAP software. + */ + +#include +#include +#include "openldap.h" + +static int do_uri_create(LDAPURLDesc *lud) { + char *uri; + + if (lud->lud_scheme == NULL) { + lud->lud_scheme = "ldap"; + } + + if (lud->lud_port == -1) { + if (strcasecmp(lud->lud_scheme, "ldap") == 0) { + lud->lud_port = LDAP_PORT; + + } else if (strcasecmp(lud->lud_scheme, "ldaps") == 0) { + lud->lud_port = LDAPS_PORT; + + } else if (strcasecmp(lud->lud_scheme, "ldapi") == 0) { + lud->lud_port = 0; + + } else { + /* forgiving... */ + lud->lud_port = 0; + } + } + + if (lud->lud_scope == -1) { + lud->lud_scope = LDAP_SCOPE_DEFAULT; + } + + uri = ldap_url_desc2str(lud); + + if (uri == NULL) { + fprintf(stderr, "unable to generate URI\n"); + exit(EXIT_FAILURE); + } + + printf("%s\n", uri); + free(uri); + + return 0; +} + +int main() { + LDAPURLDesc lud = {0}; + + lud.lud_port = -1; + lud.lud_scope = -1; + + return do_uri_create(&lud); +}