From 77eb4e771938b1d5b361568b7ba6df2cb42af4a7 Mon Sep 17 00:00:00 2001 From: Nicolai Grodzitski Date: Thu, 26 Jan 2023 15:06:08 +0100 Subject: [PATCH] (#14878) Update logr to v0.6.0 * Update logr to v0.6.0 * Comply to new practices * Account for different backends * Review guided polishing Co-authored-by: Chris Mc Co-authored-by: Chris Mc --- recipes/logr/all/conandata.yml | 3 + recipes/logr/all/conanfile.py | 135 +++++++++--------- recipes/logr/all/test_package/CMakeLists.txt | 15 +- recipes/logr/all/test_package/conanfile.py | 22 ++- .../logr/all/test_v1_package/CMakeLists.txt | 11 ++ recipes/logr/all/test_v1_package/conanfile.py | 16 +++ recipes/logr/config.yml | 2 + 7 files changed, 115 insertions(+), 89 deletions(-) create mode 100644 recipes/logr/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/logr/all/test_v1_package/conanfile.py diff --git a/recipes/logr/all/conandata.yml b/recipes/logr/all/conandata.yml index 9076e1decadad..46dc2294ce601 100644 --- a/recipes/logr/all/conandata.yml +++ b/recipes/logr/all/conandata.yml @@ -14,3 +14,6 @@ sources: "0.5.1": url: "https://github.com/ngrodzitski/logr/archive/v0.5.1.tar.gz" sha256: "674be6a53d5b3f40273b1b5710ac9e32d870827032b5008c41621db47f4b3b0e" + "0.6.0": + url: "https://github.com/ngrodzitski/logr/archive/v0.6.0.tar.gz" + sha256: "2ecb40396add33f2120a79957633533381f3df13cb3b53278eb9dec3a1230eb2" diff --git a/recipes/logr/all/conanfile.py b/recipes/logr/all/conanfile.py index ee7363a51c446..a5e869c032b2e 100644 --- a/recipes/logr/all/conanfile.py +++ b/recipes/logr/all/conanfile.py @@ -1,7 +1,14 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps +from conan.tools.files import get, copy, rmdir +from conan.tools.layout import basic_layout +from conan.errors import ConanInvalidConfiguration +from conan.tools.microsoft import check_min_vs, is_msvc +from conan.tools.scm import Version import os +required_conan_version = ">=1.50.0" class LogrConan(ConanFile): name = "logr" @@ -13,110 +20,96 @@ class LogrConan(ConanFile): "for server/desktop applications" ) topics = ("logger", "development", "util", "utils") - generators = "cmake" + settings = "os", "compiler", "build_type", "arch" - no_copy_source = True options = {"backend": ["spdlog", "glog", "log4cplus", "boostlog", None]} default_options = {"backend": "spdlog"} - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): - self.requires("fmt/8.1.1") + if Version(self.version) >= "0.6.0": + fmt_ref = "fmt/9.1.0" + spdlog_ref = "spdlog/1.11.0" + else: + fmt_ref = "fmt/8.1.1" + spdlog_ref = "spdlog/1.9.2" + + self.requires(fmt_ref) if self.options.backend == "spdlog": - self.requires("spdlog/1.9.2") + self.requires(spdlog_ref) elif self.options.backend == "glog": - self.requires("glog/0.5.0") + self.requires("glog/0.6.0") elif self.options.backend == "log4cplus": self.requires("log4cplus/2.0.5") elif self.options.backend == "boostlog": self.requires("boost/1.77.0") - def configure(self): + def package_id(self): + self.info.settings.clear() + self.info.requires.clear() + + def validate(self): minimal_cpp_standard = "17" - if self.settings.compiler.cppstd: - tools.check_min_cppstd(self, minimal_cpp_standard) + if self.settings.get_safe("compiler.cppstd"): + check_min_cppstd(self, minimal_cpp_standard) minimal_version = { - "gcc": "7", - "clang": "7", - "apple-clang": "10", - "Visual Studio": "16", + "gcc": "10", + "clang": "11", + "apple-clang": "12", } - compiler = str(self.settings.compiler) - if compiler not in minimal_version: - self.output.warn( - ( - "%s recipe lacks information about the %s compiler " - "standard version support" + check_min_vs(self, 192) + if not is_msvc(self): + minimum_version = minimal_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires minimum {self.settings.compiler}-{minimum_version}." ) - % (self.name, compiler) - ) - self.output.warn( - "%s requires a compiler that supports at least C++%s" - % (self.name, minimal_cpp_standard) - ) - return - - version = tools.Version(self.settings.compiler.version) - if version < minimal_version[compiler]: - raise ConanInvalidConfiguration( - "%s requires a compiler that supports at least C++%s" - % (self.name, minimal_cpp_standard) - ) - - def _configure_cmake(self): - if self._cmake: - return self._cmake - - self._cmake = CMake(self) - self._cmake.definitions["LOGR_WITH_SPDLOG_BACKEND"] = ( + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["LOGR_WITH_SPDLOG_BACKEND"] = ( self.options.backend == "spdlog" ) - self._cmake.definitions["LOGR_WITH_GLOG_BACKEND"] = ( + tc.variables["LOGR_WITH_GLOG_BACKEND"] = ( self.options.backend == "glog" ) - self._cmake.definitions["LOGR_WITH_LOG4CPLUS_BACKEND"] = ( + tc.variables["LOGR_WITH_LOG4CPLUS_BACKEND"] = ( self.options.backend == "log4cplus" ) - self._cmake.definitions["LOGR_WITH_BOOSTLOG_BACKEND"] = ( + tc.variables["LOGR_WITH_BOOSTLOG_BACKEND"] = ( self.options.backend == "boostlog" ) + tc.variables["LOGR_INSTALL"] = True + tc.variables["LOGR_CONAN_PACKAGING"] = True + tc.variables["LOGR_BUILD_TESTS"] = False + tc.variables["LOGR_BUILD_EXAMPLES"] = False + tc.variables["LOGR_BUILD_BENCHMARKS"] = False + tc.generate() - self._cmake.definitions["LOGR_INSTALL"] = True - self._cmake.definitions["LOGR_CONAN_PACKAGING"] = True - self._cmake.definitions["LOGR_BUILD_TESTS"] = False - self._cmake.definitions["LOGR_BUILD_EXAMPLES"] = False - self._cmake.definitions["LOGR_BUILD_BENCHMARKS"] = False - - self._cmake.configure(source_folder=self._source_subfolder) - return self._cmake + deps = CMakeDeps(self) + deps.generate() def source(self): - tools.get(**self.conan_data["sources"][self.version]) - extracted_dir = self.name + "-" + self.version - os.rename(extracted_dir, self._source_subfolder) + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) def package(self): - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") - cmake = self._configure_cmake() + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, "logr")) cmake.install() - - tools.rmdir(os.path.join(self.package_folder, "lib")) - - def package_id(self): - self.info.settings.clear() + rmdir(self, os.path.join(self.package_folder, "lib")) def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.frameworkdirs = [] + self.cpp_info.libdirs = [] + self.cpp_info.set_property("cmake_file_name", "logr") + self.cpp_info.names["cmake_find_package"] = "logr" self.cpp_info.names["cmake_find_package_multi"] = "logr" diff --git a/recipes/logr/all/test_package/CMakeLists.txt b/recipes/logr/all/test_package/CMakeLists.txt index e76b63abc7322..866a0cc839d26 100644 --- a/recipes/logr/all/test_package/CMakeLists.txt +++ b/recipes/logr/all/test_package/CMakeLists.txt @@ -1,15 +1,8 @@ cmake_minimum_required(VERSION 3.8) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -project(PackageTest CXX) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +project(test_package CXX) find_package(logr REQUIRED) -add_executable(example example.cpp) -target_link_libraries(example logr::logr) +add_executable(${PROJECT_NAME} example.cpp) +target_link_libraries(${PROJECT_NAME} logr::logr) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/logr/all/test_package/conanfile.py b/recipes/logr/all/test_package/conanfile.py index cdeff684590d2..a9fb96656f203 100644 --- a/recipes/logr/all/test_package/conanfile.py +++ b/recipes/logr/all/test_package/conanfile.py @@ -1,11 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -from conans import ConanFile, CMake, tools +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" -class LogrTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package" + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -13,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "example") - 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") diff --git a/recipes/logr/all/test_v1_package/CMakeLists.txt b/recipes/logr/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..7a2102f144a4f --- /dev/null +++ b/recipes/logr/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(logr REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/example.cpp) +target_link_libraries(${PROJECT_NAME} logr::logr) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/logr/all/test_v1_package/conanfile.py b/recipes/logr/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..923245bfa853d --- /dev/null +++ b/recipes/logr/all/test_v1_package/conanfile.py @@ -0,0 +1,16 @@ +from conans import ConanFile, CMake, tools +import os + + +class LogrTestConan(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): + self.run(os.path.join("bin", "test_package"), run_environment=True) diff --git a/recipes/logr/config.yml b/recipes/logr/config.yml index c1a11eb732221..2642be9922766 100644 --- a/recipes/logr/config.yml +++ b/recipes/logr/config.yml @@ -11,3 +11,5 @@ versions: folder: all "0.5.1": folder: all + "0.6.0": + folder: all