Skip to content

Commit

Permalink
hiredis/0.x.x: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jan 21, 2024
1 parent 0f346a0 commit de839ed
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 46 deletions.
1 change: 0 additions & 1 deletion recipes/hiredis/0.x.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ sources:
patches:
"0.14.1":
- patch_file: "patches/0001-fix-makefile.patch"

Check warning on line 7 in recipes/hiredis/0.x.x/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0001-fix ... ^ (line: 7)
base_path: "source_subfolder"
80 changes: 44 additions & 36 deletions recipes/hiredis/0.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.36.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import unix_path

required_conan_version = ">=1.53.0"


class HiredisConan(ConanFile):
name = "hiredis"
description = "Hiredis is a minimalistic C client library for the Redis database."
license = "BSD-3-Clause"
topics = ("hiredis", "redis", "client", "database")
homepage = "https://github.com/redis/hiredis"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/redis/hiredis"
topics = ("redis", "client", "database")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -23,55 +29,57 @@ class HiredisConan(ConanFile):
"fPIC": True,
}

@property
def _source_subfolder(self):
return "source_subfolder"

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
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 validate(self):
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("hiredis {} is not supported on Windows.".format(self.version))
raise ConanInvalidConfiguration(f"hiredis {self.version} is not supported on Windows.")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = AutotoolsToolchain(self)
tc.make_args = [
"PREFIX=/",
f"DESTDIR={unix_path(self, self.package_folder)}",
]
tc.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
# Do not force PIC if static
if not self.options.shared:
makefile = os.path.join(self._source_subfolder, "Makefile")
tools.replace_in_file(makefile, "-fPIC ", "")
makefile = os.path.join(self.source_folder, "Makefile")
replace_in_file(self, makefile, "-fPIC ", "")

def build(self):
self._patch_sources()
with tools.chdir(self._source_subfolder):
autoTools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autoTools.make()
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.make()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
with tools.chdir(self._source_subfolder):
autoTools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autoTools.install(vars={
"DESTDIR": tools.unix_path(self.package_folder),
"PREFIX": "",
})
tools.remove_files_by_mask(
os.path.join(self.package_folder, "lib"),
"*.a" if self.options.shared else "*.[so|dylib]*",
)
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install()
if not self.options.shared:
rm(self, "*.so*", os.path.join(self.package_folder, "lib"), recursive=True)
rm(self, "*.dylib*", os.path.join(self.package_folder, "lib"), recursive=True)
else:
rm(self, "*.a", os.path.join(self.package_folder, "lib"), recursive=True)
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "hiredis")
Expand Down
7 changes: 3 additions & 4 deletions recipes/hiredis/0.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(hiredis REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE hiredis::hiredis)
19 changes: 14 additions & 5 deletions recipes/hiredis/0.x.x/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", "arch", "compiler", "build_type"
generators = "cmake"
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)
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")
8 changes: 8 additions & 0 deletions recipes/hiredis/0.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
17 changes: 17 additions & 0 deletions recipes/hiredis/0.x.x/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", "arch", "compiler", "build_type"
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)

0 comments on commit de839ed

Please sign in to comment.