Skip to content

absent: modernize #9336

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

Merged
merged 1 commit into from
Feb 14, 2022
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
28 changes: 14 additions & 14 deletions recipes/absent/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
66 changes: 46 additions & 20 deletions recipes/absent/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
4 changes: 2 additions & 2 deletions recipes/absent/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions recipes/absent/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
8 changes: 4 additions & 4 deletions recipes/absent/config.yml
Original file line number Diff line number Diff line change
@@ -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