Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unleash-client-cpp: add version 1.3.0, support conan v2 #22894

Merged
merged 9 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/unleash-client-cpp/all/CMakeLists.txt

This file was deleted.

9 changes: 8 additions & 1 deletion recipes/unleash-client-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
sources:
"1.3.0":
url: "https://github.com/aruizs/unleash-client-cpp/archive/refs/tags/v1.3.0.tar.gz"
sha256: "fa0b8d6101c6dbd08db23a3d353f386c17e9436a63d658f88c7d0b8619b8d501"
"1.1.1":
url: "https://github.com/aruizs/unleash-client-cpp/archive/refs/tags/v1.1.1.tar.gz"
sha256: "2750dc231bf608910d4270ac39d83d46d25b88cc547a9d4d31f7ce4950effa7c"
patches:
"1.1.1":
- patch_file: "patches/0001-no-conan-cmake.patch"
base_path: "source_subfolder"
patch_description: "remove conan cmake module"
patch_type: "portability"
- patch_file: "patches/0002-include-sstream.patch"
patch_description: "include sstream"
patch_type: "portability"
86 changes: 39 additions & 47 deletions recipes/unleash-client-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
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 apply_conandata_patches, copy, export_conandata_patches, get, rmdir
import os

required_conan_version = ">=1.43.0"

required_conan_version = ">=1.53.0"

class UnleashConan(ConanFile):
name = "unleash-client-cpp"
homepage = "https://github.com/aruizs/unleash-client-cpp/"
description = "Unleash Client SDK for C++ projects."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
description = "Unleash Client SDK for C++ projects."
homepage = "https://github.com/aruizs/unleash-client-cpp/"
topics = ("unleash", "feature", "flag", "toggle")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -23,17 +25,6 @@ class UnleashConan(ConanFile):
"fPIC": True,
}

generators = "cmake", "cmake_find_package"
_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _min_cppstd(self):
return "17"
Expand All @@ -42,16 +33,15 @@ def _min_cppstd(self):
def _compilers_min_version(self):
return {
"Visual Studio": "15", # Should we check toolset?
"msvc": "190",
"gcc": "7",
toge marked this conversation as resolved.
Show resolved Hide resolved
"clang": "4.0",
"apple-clang": "3.8",
"intel": "17",
}
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

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

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -61,13 +51,16 @@ def configure(self):
if self.options.shared:
del self.options.fPIC

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

def requirements(self):
self.requires("cpr/1.7.2")
self.requires("nlohmann_json/3.10.5")
self.requires("cpr/1.10.5")
self.requires("nlohmann_json/3.11.3")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._min_cppstd)
check_min_cppstd(self, self._min_cppstd)

def loose_lt_semver(v1, v2):
lv1 = [int(v) for v in v1.split(".")]
Expand All @@ -78,39 +71,38 @@ def loose_lt_semver(v1, v2):
min_version = self._compilers_min_version.get(str(self.settings.compiler), False)
if min_version and loose_lt_semver(str(self.settings.compiler.version), min_version):
raise ConanInvalidConfiguration(
"{} requires C++{}, which your compiler does not support.".format(self.name, self._min_cppstd)
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

if self.settings.compiler in ["clang", "apple-clang"] and self.settings.compiler.libcxx == "libc++":
raise ConanInvalidConfiguration(
f"{self.ref} doesn't support clang with libc++. Use libstdc++ instead."
)

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["ENABLE_TESTING"] = False
self._cmake.definitions["ENABLE_TEST_COVERAGE"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_TESTING"] = False
tc.variables["ENABLE_TESTING_COVERAGE"] = False
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.libs = ["unleash"]
self.cpp_info.set_property("cmake_file_name", "unleash")
self.cpp_info.set_property("cmake_target_name", "unleash::unleash")
self.cpp_info.libs = ["unleash"]

self.cpp_info.names["cmake_find_package"] = "unleash"
self.cpp_info.names["cmake_find_package_multi"] = "unleash"

18 changes: 18 additions & 0 deletions recipes/unleash-client-cpp/all/patches/0002-include-sstream.patch
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/src/strategies/userwithid.cpp b/src/strategies/userwithid.cpp
index c2f3c7e..4dfbc28 100644
--- a/src/strategies/userwithid.cpp
+++ b/src/strategies/userwithid.cpp
@@ -1,5 +1,6 @@
#include "unleash/strategies/userwithid.h"
#include <iostream>
+#include <sstream>
#include <nlohmann/json.hpp>

namespace unleash {
@@ -19,4 +20,4 @@ bool UserWithId::isEnabled(const Context &context) {
return true;
return false;
}
-} // namespace unleash
\ No newline at end of file
+} // namespace unleash
7 changes: 2 additions & 5 deletions recipes/unleash-client-cpp/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)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES CXX)

find_package(unleash CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} unleash::unleash)
target_link_libraries(${PROJECT_NAME} PRIVATE unleash::unleash)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
19 changes: 14 additions & 5 deletions recipes/unleash-client-cpp/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", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
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")
2 changes: 2 additions & 0 deletions recipes/unleash-client-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"1.3.0":
folder: all
"1.1.1":
folder: all
Loading