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: migrate to Conan v2 #18739

Closed
wants to merge 8 commits into from
Closed
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: 9 additions & 1 deletion recipes/unleash-client-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
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_type: "conan"
patch_description: "Do not load Conan in CMakeLists.txt"
- patch_file: "patches/0002-fix-includes.patch"
patch_type: "portability"
patch_description: "Fix missing includes when building with Clang"
patch_source: "https://github.com/aruizs/unleash-client-cpp/pull/19"
101 changes: 45 additions & 56 deletions recipes/unleash-client-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.43.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 apply_conandata_patches, copy, export_conandata_patches, get, rmdir
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 = "C++ client SDK for Unleash, an open-source feature flag management service."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
description = "Unleash Client SDK for C++ projects."
topics = ("unleash", "feature", "flag", "toggle")
homepage = "https://github.com/aruizs/unleash-client-cpp/"
topics = ("unleash", "feature-flag")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -23,88 +29,72 @@ 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"
return 17

@property
def _compilers_min_version(self):
def _compilers_minimum_version(self):
return {
"Visual Studio": "15", # Should we check toolset?
"msvc": "191",
"gcc": "7",
"clang": "4.0",
"apple-clang": "3.8",
"intel": "17",
"intel-cc": "17",
}

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":
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]

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 self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_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.version == "1.1.1" and self.settings.arch == "armv8":
raise ConanInvalidConfiguration("armv8 is not supported by unleash-client-cpp 1.1.1")

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_TEST_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", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
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.set_property("cmake_file_name", "unleash")
Expand All @@ -113,4 +103,3 @@ def package_info(self):

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

32 changes: 32 additions & 0 deletions recipes/unleash-client-cpp/all/patches/0002-fix-includes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--- src/strategies/applicationhostname.cpp
+++ src/strategies/applicationhostname.cpp
@@ -6,7 +6,7 @@
#else
#include <unistd.h>
#endif
-#include <iostream>
+#include <sstream>


namespace unleash {

--- src/strategies/remoteaddress.cpp
+++ src/strategies/remoteaddress.cpp
@@ -1,5 +1,6 @@
#include "unleash/strategies/remoteaddress.h"
#include <nlohmann/json.hpp>
+#include <sstream>

namespace unleash {
RemoteAddress::RemoteAddress(std::string_view parameters, std::string_view constraints) : Strategy("remoteAddress", constraints) {

--- src/strategies/userwithid.cpp
+++ src/strategies/userwithid.cpp
@@ -1,6 +1,6 @@
#include "unleash/strategies/userwithid.h"
-#include <iostream>
#include <nlohmann/json.hpp>
+#include <sstream>

namespace unleash {
UserWithId::UserWithId(std::string_view parameters, std::string_view constraints) : Strategy("userWithId", constraints) {
9 changes: 3 additions & 6 deletions recipes/unleash-client-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

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

find_package(unleash CONFIG REQUIRED)
find_package(unleash REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} unleash::unleash)
Expand Down
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")
11 changes: 6 additions & 5 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 <unleash/unleashclient.h>

#include <iostream>

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

unleashClient.isEnabled("feature.toogle");
return 0;
}
8 changes: 8 additions & 0 deletions recipes/unleash-client-cpp/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/unleash-client-cpp/all/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)
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