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 all 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.

10 changes: 3 additions & 7 deletions recipes/unleash-client-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
sources:
"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"
"1.3.0":
url: "https://github.com/aruizs/unleash-client-cpp/archive/refs/tags/v1.3.0.tar.gz"
sha256: "fa0b8d6101c6dbd08db23a3d353f386c17e9436a63d658f88c7d0b8619b8d501"
91 changes: 35 additions & 56 deletions recipes/unleash-client-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
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 copy, get, rmdir
import os

required_conan_version = ">=1.43.0"
from conan.tools.scm import Version

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 +27,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,75 +35,61 @@ def _min_cppstd(self):
def _compilers_min_version(self):
return {
"Visual Studio": "15", # Should we check toolset?
"msvc": "191",
"gcc": "7",
"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"])

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("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)

def loose_lt_semver(v1, v2):
lv1 = [int(v) for v in v1.split(".")]
lv2 = [int(v) for v in v2.split(".")]
min_length = min(len(lv1), len(lv2))
return lv1[:min_length] < lv2[:min_length]
check_min_cppstd(self, self._min_cppstd)

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):
if min_version and Version(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."
)

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()
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"

11 changes: 0 additions & 11 deletions recipes/unleash-client-cpp/all/patches/0001-no-conan-cmake.patch

This file was deleted.

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")
7 changes: 4 additions & 3 deletions recipes/unleash-client-cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <cassert>
#include <ios>
#include <iostream>

#include <unleash/unleashclient.h>

int main() {
unleash::UnleashClient unleashClient = unleash::UnleashClient::create("production", "https://www.apple.com/%");
unleashClient.initializeClient();
return unleashClient.isEnabled("feature.toogle");

std::cout << "feature.toggle - is enabled: " << std::boolalpha << unleashClient.isEnabled("feature.toogle") << '\n';
return 0;
}
2 changes: 1 addition & 1 deletion recipes/unleash-client-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"1.1.1":
"1.3.0":
folder: all
Loading