From 2bece1b45ce018af4a772384aa64e3d9abd0e186 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 20 Jul 2023 23:18:06 +0300 Subject: [PATCH 1/7] tgbot: migrate to Conan v2 --- recipes/tgbot/all/CMakeLists.txt | 7 -- recipes/tgbot/all/conanfile.py | 93 +++++++++++-------- recipes/tgbot/all/test_package/CMakeLists.txt | 7 +- recipes/tgbot/all/test_package/conanfile.py | 20 +++- .../tgbot/all/test_v1_package/CMakeLists.txt | 8 ++ .../tgbot/all/test_v1_package/conanfile.py | 16 ++++ 6 files changed, 93 insertions(+), 58 deletions(-) delete mode 100644 recipes/tgbot/all/CMakeLists.txt create mode 100644 recipes/tgbot/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/tgbot/all/test_v1_package/conanfile.py diff --git a/recipes/tgbot/all/CMakeLists.txt b/recipes/tgbot/all/CMakeLists.txt deleted file mode 100644 index 959835f6b0885..0000000000000 --- a/recipes/tgbot/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory(source_subfolder) diff --git a/recipes/tgbot/all/conanfile.py b/recipes/tgbot/all/conanfile.py index b7db60eafd261..6fb62d417437e 100644 --- a/recipes/tgbot/all/conanfile.py +++ b/recipes/tgbot/all/conanfile.py @@ -1,19 +1,23 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration 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.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, replace_in_file + +required_conan_version = ">=1.53.0" class TgbotConan(ConanFile): name = "tgbot" - - url = "https://github.com/conan-io/conan-center-index" - homepage = "http://reo7sp.github.io/tgbot-cpp" description = "C++ library for Telegram bot API" - topics = ("tgbot", "telegram", "telegram-api", "telegram-bot", "bot") license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "http://reo7sp.github.io/tgbot-cpp" + topics = ("telegram", "telegram-api", "telegram-bot", "bot") + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -24,27 +28,21 @@ class TgbotConan(ConanFile): "fPIC": True, } - generators = "cmake", "cmake_find_package" - exports_sources = ["CMakeLists.txt"] - - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): - self.requires("boost/1.79.0") - self.requires("libcurl/7.84.0") - self.requires("openssl/1.1.1q") + self.requires("boost/1.83.0", transitive_headers=True, transitive_libs=True) + self.requires("libcurl/[>=7.78 <9]", transitive_headers=True, transitive_libs=True) + self.requires("openssl/[>=1.1 <4]") @property def _required_boost_components(self): @@ -52,41 +50,54 @@ def _required_boost_components(self): def validate(self): if self.settings.compiler.cppstd: - tools.check_min_cppstd(self, 11) - miss_boost_required_comp = any(getattr(self.options["boost"], "without_{}".format(boost_comp), True) for boost_comp in self._required_boost_components) - if self.options["boost"].header_only or miss_boost_required_comp: - raise ConanInvalidConfiguration("{0} requires non header-only boost with these components: {1}".format(self.name, ", ".join(self._required_boost_components))) + check_min_cppstd(self, 11) + miss_boost_required_comp = any( + self.dependencies["boost"].options.get_safe(f"without_{boost_comp}", True) + for boost_comp in self._required_boost_components + ) + if self.dependencies["boost"].options.header_only or miss_boost_required_comp: + raise ConanInvalidConfiguration( + f"{self.name} requires non header-only boost with these components: " + + ", ".join(self._required_boost_components) + ) 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 = CMakeToolchain(self) + tc.variables["ENABLE_TESTS"] = False + tc.generate() + tc = CMakeDeps(self) + tc.generate() def _patch_sources(self): # Don't force PIC - tools.replace_in_file( - os.path.join(self._source_subfolder, "CMakeLists.txt"), + replace_in_file( + self, + os.path.join(self.source_folder, "CMakeLists.txt"), "set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)", - "" + "", ) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["ENABLE_TESTS"] = False - self._cmake.configure() - return self._cmake - def build(self): self._patch_sources() - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - cmake = self._configure_cmake() + cmake = CMake(self) cmake.install() - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) + copy(self, "LICENSE", + dst=os.path.join(self.package_folder, "licenses"), + src=self.source_folder) def package_info(self): self.cpp_info.libs = ["TgBot"] - self.cpp_info.requires = ["boost::headers", "boost::system", "libcurl::libcurl", "openssl::openssl"] + self.cpp_info.requires = [ + "boost::headers", + "boost::system", + "libcurl::libcurl", + "openssl::openssl", + ] diff --git a/recipes/tgbot/all/test_package/CMakeLists.txt b/recipes/tgbot/all/test_package/CMakeLists.txt index b41fdddf1c066..ebe398c29035c 100644 --- a/recipes/tgbot/all/test_package/CMakeLists.txt +++ b/recipes/tgbot/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(test_package CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -find_package(tgbot REQUIRED) +find_package(tgbot REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) diff --git a/recipes/tgbot/all/test_package/conanfile.py b/recipes/tgbot/all/test_package/conanfile.py index 7122b776c7119..ef5d7042163ec 100644 --- a/recipes/tgbot/all/test_package/conanfile.py +++ b/recipes/tgbot/all/test_package/conanfile.py @@ -1,10 +1,19 @@ +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 TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake_find_package", "cmake" + 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) @@ -12,5 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "test_package"), run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/tgbot/all/test_v1_package/CMakeLists.txt b/recipes/tgbot/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/tgbot/all/test_v1_package/CMakeLists.txt @@ -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/) diff --git a/recipes/tgbot/all/test_v1_package/conanfile.py b/recipes/tgbot/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..7122b776c7119 --- /dev/null +++ b/recipes/tgbot/all/test_v1_package/conanfile.py @@ -0,0 +1,16 @@ +import os +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake_find_package", "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + self.run(os.path.join("bin", "test_package"), run_environment=True) From 2c427f2a59792cf710371d059c1e90df94f2df5c Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 1 Nov 2023 15:48:30 +0200 Subject: [PATCH 2/7] tgbot: drop the older v1.2 and v1.2.1 --- recipes/tgbot/all/conandata.yml | 6 ------ recipes/tgbot/config.yml | 4 ---- 2 files changed, 10 deletions(-) diff --git a/recipes/tgbot/all/conandata.yml b/recipes/tgbot/all/conandata.yml index 054b04f19ea35..e2625bd0a2fbb 100644 --- a/recipes/tgbot/all/conandata.yml +++ b/recipes/tgbot/all/conandata.yml @@ -5,9 +5,3 @@ sources: "1.3": url: "https://github.com/reo7sp/tgbot-cpp/archive/v1.3.tar.gz" sha256: "85b9aef49c595d39fc9dc330b1b83625bea9509966dc623f7b4c1ee7309679c9" - "1.2.1": - url: "https://github.com/reo7sp/tgbot-cpp/archive/v1.2.1.tar.gz" - sha256: "bcc82cc8c421e96098ba6ef350acc0c1ce9fbbc21a11b91eb8643324757d09f2" - "1.2": - url: "https://github.com/reo7sp/tgbot-cpp/archive/v1.2.tar.gz" - sha256: "6d5158db38fb092e12060080a611ccdccde35cfb85f030996daee9619bebc513" diff --git a/recipes/tgbot/config.yml b/recipes/tgbot/config.yml index 220c83c443ceb..39a996dda935d 100644 --- a/recipes/tgbot/config.yml +++ b/recipes/tgbot/config.yml @@ -3,7 +3,3 @@ versions: folder: all "1.3": folder: all - "1.2.1": - folder: all - "1.2": - folder: all From 214c4a37ef66e3c98b888ff00aee601a48c051ea Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 3 Nov 2023 16:49:28 +0200 Subject: [PATCH 3/7] tgbot: fix test_v1_package --- recipes/tgbot/all/test_v1_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/tgbot/all/test_v1_package/conanfile.py b/recipes/tgbot/all/test_v1_package/conanfile.py index 7122b776c7119..80f8edbcec938 100644 --- a/recipes/tgbot/all/test_v1_package/conanfile.py +++ b/recipes/tgbot/all/test_v1_package/conanfile.py @@ -4,7 +4,7 @@ class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake_find_package", "cmake" + generators = "cmake_find_package_multi", "cmake" def build(self): cmake = CMake(self) From ad0b6d2acc54d0343bdf5d692438ff218d27e92b Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 4 Nov 2023 12:30:00 +0200 Subject: [PATCH 4/7] tgbot: fix_apple_shared_install_name() --- recipes/tgbot/all/conanfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/tgbot/all/conanfile.py b/recipes/tgbot/all/conanfile.py index 6fb62d417437e..358a416f38f77 100644 --- a/recipes/tgbot/all/conanfile.py +++ b/recipes/tgbot/all/conanfile.py @@ -2,6 +2,7 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration +from conan.tools.apple import fix_apple_shared_install_name from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.files import copy, get, replace_in_file @@ -92,6 +93,7 @@ def package(self): copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + fix_apple_shared_install_name(self) def package_info(self): self.cpp_info.libs = ["TgBot"] From 70756b9a8aaf73e423a6ad3461e73030f7483fae Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 4 Nov 2023 12:32:31 +0200 Subject: [PATCH 5/7] tgbot: add missing boost::stacktrace require --- recipes/tgbot/all/conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/tgbot/all/conanfile.py b/recipes/tgbot/all/conanfile.py index 358a416f38f77..f2352558ff714 100644 --- a/recipes/tgbot/all/conanfile.py +++ b/recipes/tgbot/all/conanfile.py @@ -99,6 +99,7 @@ def package_info(self): self.cpp_info.libs = ["TgBot"] self.cpp_info.requires = [ "boost::headers", + "boost::stacktrace", "boost::system", "libcurl::libcurl", "openssl::openssl", From c6b31c5cb633dfc58b561b443129aa9dcd919a8a Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 5 Nov 2023 12:38:20 +0200 Subject: [PATCH 6/7] tgbot: just require boost::boost Would need to add boost::stacktrace_backtrace, but it's an optional indirect component. --- recipes/tgbot/all/conanfile.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/recipes/tgbot/all/conanfile.py b/recipes/tgbot/all/conanfile.py index f2352558ff714..90c59c28ebbc3 100644 --- a/recipes/tgbot/all/conanfile.py +++ b/recipes/tgbot/all/conanfile.py @@ -97,10 +97,3 @@ def package(self): def package_info(self): self.cpp_info.libs = ["TgBot"] - self.cpp_info.requires = [ - "boost::headers", - "boost::stacktrace", - "boost::system", - "libcurl::libcurl", - "openssl::openssl", - ] From a38fb4a0b6f7bb6b03c24c9243feb1b4a77ae873 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 14 Nov 2023 09:21:30 +0200 Subject: [PATCH 7/7] tgbot: improvements from review Co-authored-by: Uilian Ries --- recipes/tgbot/all/conanfile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/recipes/tgbot/all/conanfile.py b/recipes/tgbot/all/conanfile.py index 90c59c28ebbc3..1fb99e68206f6 100644 --- a/recipes/tgbot/all/conanfile.py +++ b/recipes/tgbot/all/conanfile.py @@ -41,7 +41,9 @@ def layout(self): cmake_layout(self, src_folder="src") def requirements(self): + # tgbot/Api.h:#include self.requires("boost/1.83.0", transitive_headers=True, transitive_libs=True) + # tgbot/net/CurlHttpClient.h:#include self.requires("libcurl/[>=7.78 <9]", transitive_headers=True, transitive_libs=True) self.requires("openssl/[>=1.1 <4]") @@ -97,3 +99,4 @@ def package(self): def package_info(self): self.cpp_info.libs = ["TgBot"] + self.cpp_info.defines = ["HAVE_CURL=1"]