Skip to content

Commit

Permalink
(#18354) yandex-ozo: migrate to Conan v2
Browse files Browse the repository at this point in the history
* yandex-ozo: migrate to Conan v2

* yandex-ozo: add v0.1.0
  • Loading branch information
valgur authored Nov 8, 2023
1 parent a9cd59b commit 6138128
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 47 deletions.
5 changes: 4 additions & 1 deletion recipes/yandex-ozo/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"0.1.0":
url: "https://github.com/yandex/ozo/archive/refs/tags/v0.1.0.tar.gz"
sha256: "bf4f07c8105f9d5ccf0eebf88d3e33ee440b5668493f63e62de2cd184e80b39a"
"cci.20210509":
url: "https://github.com/yandex/ozo/archive/1b06a00ec3cea09108557bbec71cc7a6455dfb6b.tar.gz"
sha256: 97eaa2145be4366c390762e8a4d63e507e8be02a37f2c50e5ba0104a1ca192ee
sha256: "97eaa2145be4366c390762e8a4d63e507e8be02a37f2c50e5ba0104a1ca192ee"
82 changes: 48 additions & 34 deletions recipes/yandex-ozo/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import check_min_cppstd, Version
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version

required_conan_version = ">=1.52.0"


class YandexOzoConan(ConanFile):
name = "yandex-ozo"
description = "C++ header-only library for asynchronous access to PostgreSQL databases using ASIO"
topics = ("ozo", "yandex", "postgres", "postgresql", "cpp17", "database", "db", "asio")
license = "PostgreSQL"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/yandex/ozo"
license = "PostgreSQL"
topics = ("ozo", "yandex", "postgres", "postgresql", "cpp17", "database", "db", "asio", "header-only")

settings = "os", "compiler"
requires = ("boost/1.76.0", "resource_pool/cci.20210322", "libpq/13.2")
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

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

@property
def _compilers_minimum_version(self):
Expand All @@ -31,15 +35,26 @@ def _compilers_minimum_version(self):
"apple-clang": "10",
}

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("boost/1.79.0")
self.requires("resource_pool/cci.20210322")
self.requires("libpq/15.4")

def package_id(self):
self.info.clear()

def _validate_compiler_settings(self):
compiler = self.settings.compiler
if compiler.get_safe("cppstd"):
check_min_cppstd(self, "17")
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)

if not minimum_version:
self.output.warn("ozo requires C++17. Your compiler is unknown. Assuming it supports C++17.")
elif tools.Version(self.settings.compiler.version) < minimum_version:
self.output.warning("ozo requires C++17. Your compiler is unknown. Assuming it supports C++17.")
elif Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("ozo requires a compiler that supports at least C++17")

def validate(self):
Expand All @@ -49,38 +64,37 @@ def validate(self):
self._validate_compiler_settings()

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 package(self):
self.copy(pattern="*", dst=os.path.join("include", "ozo"), src=os.path.join(self._source_subfolder, "include", "ozo"))
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)

def package_id(self):
self.info.header_only()
copy(self, "*.h",
dst=os.path.join(self.package_folder, "include", "ozo"),
src=os.path.join(self.source_folder, "include", "ozo"))
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []

main_comp = self.cpp_info.components["_ozo"]
main_comp.requires = [
"boost::boost", "boost::system", "boost::thread", "boost::coroutine",
"resource_pool::resource_pool",
"libpq::pq",
]
main_comp.defines = [
"BOOST_HANA_CONFIG_ENABLE_STRING_UDL",
"BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT",
]
main_comp.names["cmake_find_package"] = "ozo"
main_comp.names["cmake_find_package_multi"] = "ozo"
main_comp.requires = ["boost::boost", "boost::system", "boost::thread", "boost::coroutine", "resource_pool::resource_pool", "libpq::pq"]
main_comp.defines = ["BOOST_HANA_CONFIG_ENABLE_STRING_UDL", "BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT"]
main_comp.set_property("cmake_target_name", "yandex::ozo")

compiler = self.settings.compiler
version = Version(compiler.version)
if compiler == "clang" or compiler == "apple-clang" or (compiler == "gcc" and version >= 9):
main_comp.cxxflags = [
"-Wno-gnu-string-literal-operator-template",
"-Wno-gnu-zero-variadic-macro-arguments",
]
main_comp.cxxflags = ["-Wno-gnu-string-literal-operator-template", "-Wno-gnu-zero-variadic-macro-arguments"]

self.cpp_info.set_property("cmake_file_name", "ozo")
self.cpp_info.set_property("cmake_target_name", "yandex::ozo")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "ozo"
self.cpp_info.filenames["cmake_find_package_multi"] = "ozo"
self.cpp_info.names["cmake_find_package"] = "yandex"
self.cpp_info.names["cmake_find_package_multi"] = "yandex"
main_comp.names["cmake_find_package"] = "ozo"
main_comp.names["cmake_find_package_multi"] = "ozo"
5 changes: 1 addition & 4 deletions recipes/yandex-ozo/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

find_package(ozo REQUIRED CONFIG)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_executable(example request.cpp)
target_compile_features(example PRIVATE cxx_std_17)
target_link_libraries(example PRIVATE yandex::ozo)
23 changes: 16 additions & 7 deletions recipes/yandex-ozo/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os
from conans import ConanFile, CMake, tools


class YandexOzoTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake_find_package_multi", "cmake"
class TestPackageConan(ConanFile):
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)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "example")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/yandex-ozo/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.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/yandex-ozo/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from conans import ConanFile, CMake, tools


class YandexOzoTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake_find_package_multi", "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
4 changes: 3 additions & 1 deletion recipes/yandex-ozo/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"0.1.0":
folder: all
"cci.20210509":
folder: "all"
folder: all

0 comments on commit 6138128

Please sign in to comment.