Skip to content

Commit

Permalink
(#16749) openldap: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
grabowski-d committed Apr 11, 2023
1 parent 336de16 commit 8f5bed8
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 67 deletions.
2 changes: 1 addition & 1 deletion recipes/openldap/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
103 changes: 44 additions & 59 deletions recipes/openldap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions recipes/openldap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
19 changes: 14 additions & 5 deletions recipes/openldap/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions recipes/openldap/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions recipes/openldap/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
83 changes: 83 additions & 0 deletions recipes/openldap/all/test_v1_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* ldapurl -- a tool for generating LDAP URLs */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* 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
* <http://www.OpenLDAP.org/license.html>.
*/
/* 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 <stdio.h>
#include <cstdlib>
#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);
}

0 comments on commit 8f5bed8

Please sign in to comment.