Skip to content

Commit

Permalink
(#16067) Migrate RapidFuzz to conan 2.0 and add 1.10.4 version
Browse files Browse the repository at this point in the history
* Migrate RapidFuzz to conan 2.0 and add 1.10.4 version

* Fix PR errors

* Add requirements for C++17

* Apply templates

* Fix lint

* Fix minimal msvc version

* Add missing layout

* Sort versions in conandata

* Fix order in config.yml

* Fix min cppstd version requirement on older version

* Fix minimal cppstd version
  • Loading branch information
AlexandrePTJ authored Mar 27, 2023
1 parent 8bf16c2 commit 62d319c
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 24 deletions.
3 changes: 3 additions & 0 deletions recipes/rapidfuzz/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.10.4":
url: "https://github.com/maxbachmann/rapidfuzz-cpp/archive/refs/tags/v1.10.4.tar.gz"
sha256: "84a1ea8759aaa5bc8587c26504421d6fd34ad2a8dc74bf469b0cc3cc6758e17a"
"cci.20210513":
url: "https://github.com/maxbachmann/rapidfuzz-cpp/archive/d1e82379395cafc6d439c1c1e2cbe7512eaf2518.tar.gz"
sha256: "e5c306aae2fb4b34a381fbffaa97399114f20de14d83914ac2c9013b0226ce57"
65 changes: 51 additions & 14 deletions recipes/rapidfuzz/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@
from conans import ConanFile, tools
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.33.0"

required_conan_version = ">=1.52.0"

class RapidFuzzConan(ConanFile):

class PackageConan(ConanFile):
name = "rapidfuzz"
description = "Rapid fuzzy string matching in C++ using the Levenshtein Distance "
topics = ("conan", "cpp", "levenshtein", "string-matching", "string-similarity", "string-comparison")
description = "Rapid fuzzy string matching in C++ using the Levenshtein Distance"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/maxbachmann/rapidfuzz-cpp"
license = "MIT"
topics = ("levenshtein", "string-matching", "string-similarity", "string-comparison", "header-only")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
if self.version == "cci.20210513":
return 98
return 17

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "16",
"msvc": "192",
"gcc": "6",
"clang": "6",
"apple-clang": "12",
}

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

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

def validate(self):
if self.settings.compiler.get_safe("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(
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],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)


def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="rapidfuzz/*.hpp", dst="include", src=self._source_subfolder)
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "rapidfuzz/*.hpp", self.source_folder, os.path.join(self.package_folder, "include"))
copy(self, "rapidfuzz/*.impl", self.source_folder, os.path.join(self.package_folder, "include"))

def package_id(self):
self.info.header_only()
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
8 changes: 4 additions & 4 deletions recipes/rapidfuzz/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(rapidfuzz REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} PRIVATE rapidfuzz::rapidfuzz)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
21 changes: 15 additions & 6 deletions recipes/rapidfuzz/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", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/rapidfuzz/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.8)
project(test_package LANGUAGES CXX)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
18 changes: 18 additions & 0 deletions recipes/rapidfuzz/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


class TestPackageV1Conan(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 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/rapidfuzz/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"1.10.4":
folder: "all"
"cci.20210513":
folder: "all"

0 comments on commit 62d319c

Please sign in to comment.