Skip to content

Commit

Permalink
[openldap] fix package
Browse files Browse the repository at this point in the history
  • Loading branch information
SSE4 committed Apr 16, 2024
1 parent 4522d7a commit 98b2017
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 62 deletions.
3 changes: 3 additions & 0 deletions recipes/openldap/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ sources:
"2.6.1":
url: https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.1.tgz
sha256: 9d576ea6962d7db8a2e2808574e8c257c15aef55f403a1fb5a0faf35de70e6f3
"2.6.7":
url: https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.7.tgz
sha256: cd775f625c944ed78a3da18a03b03b08eea73c8aabc97b41bb336e9a10954930
patches:
"2.6.1":
- base_path: source_subfolder
Expand Down
100 changes: 45 additions & 55 deletions recipes/openldap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import os
from conans import ConanFile, AutoToolsBuildEnvironment, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps, PkgConfigDeps
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv

Check warning on line 4 in recipes/openldap/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused Environment imported from conan.tools.env
from conan.tools.files import rmdir, get, copy, rm, apply_conandata_patches, export_conandata_patches
from conan.tools.build import cross_building
from conan.tools.layout import basic_layout
from conan.errors import ConanInvalidConfiguration
required_conan_version = ">=1.43.0"


Expand All @@ -12,7 +17,7 @@ class OpenldapConan(ConanFile):
license = "OLDAP-2.8"
topics = ("ldap", "load-balancer", "directory-access")
exports_sources = ["patches/*"]
settings = settings = "os", "compiler", "build_type", "arch"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -22,88 +27,73 @@ class OpenldapConan(ConanFile):
"shared": False,
"fPIC": True,
"with_cyrus_sasl": True

}
_autotools = None
_configure_vars = None

@property
def _source_subfolder(self):
return "source_subfolder"
def layout(self):
# src_folder must use the same source folder name the project
basic_layout(self, src_folder="src")

def export_sources(self):
export_conandata_patches(self)

def configure(self):
if self.options.shared:
del self.options.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)

def requirements(self):
self.requires("openssl/1.1.1q")
self.requires("openssl/3.2.1")
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 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"
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))),
tc.configure_args.extend([
f"--with-cyrus_sasl={yes_no(self.options.with_cyrus_sasl)}",
f"--with-pic={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"
])
tc.generate()
tc = PkgConfigDeps(self)
tc.generate()
tc = AutotoolsDeps(self)
tc.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)
apply_conandata_patches(self)
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)
autotools = Autotools(self)
autotools.install()
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "COPYRIGHT", self.source_folder, os.path.join(self.package_folder, "licenses"))
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")
rmdir(self, os.path.join(self.package_folder, folder))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))

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))
f"Appending PATH environment variable: {bin_path}")

self.cpp_info.libs = ["ldap", "lber"]
if self.settings.os in ["Linux", "FreeBSD"]:
Expand Down
3 changes: 1 addition & 2 deletions recipes/openldap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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.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"
test_type = "explicit"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"

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):
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")
2 changes: 2 additions & 0 deletions recipes/openldap/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"2.6.7":
folder: all
"2.6.1":
folder: all

0 comments on commit 98b2017

Please sign in to comment.