From 5eae4407428d03b9a086190c37831791ec1cc362 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Thu, 10 Feb 2022 12:58:59 +0100 Subject: [PATCH] modernize --- recipes/absent/all/conandata.yml | 28 ++++---- recipes/absent/all/conanfile.py | 66 +++++++++++++------ .../absent/all/test_package/CMakeLists.txt | 4 +- recipes/absent/all/test_package/conanfile.py | 4 +- recipes/absent/config.yml | 8 +-- 5 files changed, 68 insertions(+), 42 deletions(-) diff --git a/recipes/absent/all/conandata.yml b/recipes/absent/all/conandata.yml index 5ab6cfbf7848a..474b5d79c89ae 100644 --- a/recipes/absent/all/conandata.yml +++ b/recipes/absent/all/conandata.yml @@ -1,16 +1,16 @@ sources: - "0.0.1": - sha256: 4fa1e40cc06c2147f5308e63f51a8785fcc41515b6a6a7c280459d005f1c0aeb - url: https://github.com/rvarago/absent/archive/0.0.1.tar.gz - "0.1.0": - sha256: 32be167191d695f7663cd6043b226c83798aeb617504ad6c82ddf3b3fdb08498 - url: https://github.com/rvarago/absent/archive/0.1.0.tar.gz - "0.2.0": - sha256: f3a587f1a5bdd74e4363378201e56c362830a62f0f92f1872038e71b7a1462c7 - url: https://github.com/rvarago/absent/archive/0.2.0.tar.gz - "0.3.0": - sha256: ac6d1b9cc2e57318eab1252bf5aa13c7bac25e316285a687c61dfdfa71e71e8d - url: https://github.com/rvarago/absent/archive/0.3.0.tar.gz "0.3.1": - sha256: fe0a96303c6438f1095273b093e56c8f10a3b79dea86676b59aec94e6ed89224 - url: https://github.com/rvarago/absent/archive/0.3.1.tar.gz + url: "https://github.com/rvarago/absent/archive/0.3.1.tar.gz" + sha256: "fe0a96303c6438f1095273b093e56c8f10a3b79dea86676b59aec94e6ed89224" + "0.3.0": + url: "https://github.com/rvarago/absent/archive/0.3.0.tar.gz" + sha256: "ac6d1b9cc2e57318eab1252bf5aa13c7bac25e316285a687c61dfdfa71e71e8d" + "0.2.0": + url: "https://github.com/rvarago/absent/archive/0.2.0.tar.gz" + sha256: "f3a587f1a5bdd74e4363378201e56c362830a62f0f92f1872038e71b7a1462c7" + "0.1.0": + url: "https://github.com/rvarago/absent/archive/0.1.0.tar.gz" + sha256: "32be167191d695f7663cd6043b226c83798aeb617504ad6c82ddf3b3fdb08498" + "0.0.1": + url: "https://github.com/rvarago/absent/archive/0.0.1.tar.gz" + sha256: "4fa1e40cc06c2147f5308e63f51a8785fcc41515b6a6a7c280459d005f1c0aeb" diff --git a/recipes/absent/all/conanfile.py b/recipes/absent/all/conanfile.py index 1e7a9d0acb314..bdc5f5e18836b 100644 --- a/recipes/absent/all/conanfile.py +++ b/recipes/absent/all/conanfile.py @@ -2,48 +2,64 @@ from conans.errors import ConanInvalidConfiguration import os -required_conan_version = ">=1.28.0" +required_conan_version = ">=1.43.0" + class AbsentConan(ConanFile): name = "absent" - description = "A small C++17 library meant to simplify the composition of nullable types in a generic, type-safe, and declarative way" + description = ( + "A small C++17 library meant to simplify the composition of nullable " + "types in a generic, type-safe, and declarative way" + ) homepage = "https://github.com/rvarago/absent" url = "https://github.com/conan-io/conan-center-index" license = "MIT" topics = ("nullable-types", "composition", "monadic-interface", "declarative-programming") no_copy_source = True - settings = "compiler" + settings = "os", "arch", "compiler", "build_type" generators = "cmake" @property def _source_subfolder(self): return "source_subfolder" - def _supports_cpp17(self): - supported_compilers = [("gcc", "7"), ("clang", "5"), ("apple-clang", "10"), ("Visual Studio", "15.7")] - compiler = self.settings.compiler - version = tools.Version(compiler.version) - return any(compiler == sc[0] and version >= sc[1] for sc in supported_compilers) - - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["BUILD_TESTS"] = "OFF" - cmake.configure(source_folder=self._source_subfolder) - return cmake + @property + def _compilers_minimum_version(self): + return { + "gcc": "7", + "clang": "5", + "apple-clang": "10", + "Visual Studio": "15.7", + } - def configure(self): + def validate(self): if self.settings.compiler.get_safe("cppstd"): tools.check_min_cppstd(self, "17") - elif not self._supports_cpp17(): - raise ConanInvalidConfiguration("Absent requires C++17 support") + + 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] + + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and loose_lt_semver(str(self.settings.compiler.version), minimum_version): + raise ConanInvalidConfiguration( + "{} requires C++17, which your compiler does not support.".format(self.name) + ) def package_id(self): self.info.header_only() def source(self): - tools.get(**self.conan_data["sources"][self.version]) - extracted_dir = self.name + "-" + self.version - os.rename(extracted_dir, self._source_subfolder) + tools.get(**self.conan_data["sources"][self.version], + destination=self._source_subfolder, strip_root=True) + + def _configure_cmake(self): + cmake = CMake(self) + cmake.definitions["BUILD_TESTS"] = "OFF" + cmake.configure(source_folder=self._source_subfolder) + return cmake def package(self): self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder) @@ -52,9 +68,19 @@ def package(self): tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): + self.cpp_info.set_property("cmake_file_name", "absent") + self.cpp_info.set_property("cmake_target_name", "rvarago::absent") + # TODO: back to global scope in conan v2 once cmake_find_package_* generators removed + self.cpp_info.components["absentlib"].bindirs = [] + self.cpp_info.components["absentlib"].frameworkdirs = [] + self.cpp_info.components["absentlib"].libdirs = [] + self.cpp_info.components["absentlib"].resdirs = [] + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "absent" self.cpp_info.filenames["cmake_find_package_multi"] = "absent" self.cpp_info.names["cmake_find_package"] = "rvarago" self.cpp_info.names["cmake_find_package_multi"] = "rvarago" self.cpp_info.components["absentlib"].names["cmake_find_package"] = "absent" self.cpp_info.components["absentlib"].names["cmake_find_package_multi"] = "absent" + self.cpp_info.components["absentlib"].set_property("cmake_target_name", "rvarago::absent") diff --git a/recipes/absent/all/test_package/CMakeLists.txt b/recipes/absent/all/test_package/CMakeLists.txt index d53ec3bc47d60..fe998526125cb 100644 --- a/recipes/absent/all/test_package/CMakeLists.txt +++ b/recipes/absent/all/test_package/CMakeLists.txt @@ -1,8 +1,8 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.8) project(test_package LANGUAGES CXX) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +conan_basic_setup(TARGETS) find_package(absent REQUIRED CONFIG) diff --git a/recipes/absent/all/test_package/conanfile.py b/recipes/absent/all/test_package/conanfile.py index 7e2dfe859bb27..38f4483872d47 100644 --- a/recipes/absent/all/test_package/conanfile.py +++ b/recipes/absent/all/test_package/conanfile.py @@ -3,7 +3,7 @@ class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" + settings = "os", "arch", "compiler", "build_type" generators = "cmake", "cmake_find_package_multi" def build(self): @@ -12,6 +12,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self.settings): + if not tools.cross_building(self): bin_path = os.path.join("bin", "test_package") self.run(bin_path, run_environment=True) diff --git a/recipes/absent/config.yml b/recipes/absent/config.yml index baa7fb144f2b6..4c4c018d5454b 100644 --- a/recipes/absent/config.yml +++ b/recipes/absent/config.yml @@ -1,11 +1,11 @@ versions: - "0.0.1": + "0.3.1": folder: all - "0.1.0": + "0.3.0": folder: all "0.2.0": folder: all - "0.3.0": + "0.1.0": folder: all - "0.3.1": + "0.0.1": folder: all