From c8e4d78a59165d7e1b3eec2e79bb07213a75f2f2 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 29 Jun 2024 01:22:58 +0300 Subject: [PATCH] (#18652) wineditline: migrate to Conan v2 * wineditline: migrate to Conan v2 * wineditline: simplify patching * Use upstream CMakeLists Signed-off-by: Uilian Ries --------- Signed-off-by: Uilian Ries Co-authored-by: Uilian Ries --- recipes/wineditline/all/CMakeLists.txt | 8 --- recipes/wineditline/all/conandata.yml | 6 +- recipes/wineditline/all/conanfile.py | 69 +++++++++---------- .../all/patches/0001-fix-cmakelists.patch | 43 ------------ .../all/test_package/CMakeLists.txt | 5 +- .../wineditline/all/test_package/conanfile.py | 22 ++++-- .../all/test_package/test_package.c | 11 +-- .../all/test_v1_package/CMakeLists.txt | 8 +++ .../all/test_v1_package/conanfile.py | 18 +++++ 9 files changed, 80 insertions(+), 110 deletions(-) delete mode 100644 recipes/wineditline/all/CMakeLists.txt delete mode 100644 recipes/wineditline/all/patches/0001-fix-cmakelists.patch create mode 100644 recipes/wineditline/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/wineditline/all/test_v1_package/conanfile.py diff --git a/recipes/wineditline/all/CMakeLists.txt b/recipes/wineditline/all/CMakeLists.txt deleted file mode 100644 index 1fedb144d2f6c..0000000000000 --- a/recipes/wineditline/all/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.1) - -project(WinEditLineWrapper C) - -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup(TARGETS) - -add_subdirectory(source_subfolder) diff --git a/recipes/wineditline/all/conandata.yml b/recipes/wineditline/all/conandata.yml index 789f36bc66156..d9e2a2c6f39a9 100644 --- a/recipes/wineditline/all/conandata.yml +++ b/recipes/wineditline/all/conandata.yml @@ -1,8 +1,4 @@ sources: "2.206": sha256: "2d255c417244e963261dc6171684265f405df030e90ba6e6690a99284d645161" - url: https://sourceforge.net/projects/mingweditline/files/wineditline-2.206.zip/download -patches: - "2.206": - - patch_file: patches/0001-fix-cmakelists.patch - base_path: source_subfolder + url: "https://sourceforge.net/projects/mingweditline/files/wineditline-2.206.zip" diff --git a/recipes/wineditline/all/conanfile.py b/recipes/wineditline/all/conanfile.py index 3888bf2a8557f..1a01961f91168 100644 --- a/recipes/wineditline/all/conanfile.py +++ b/recipes/wineditline/all/conanfile.py @@ -1,64 +1,63 @@ -import functools import os -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.53.0" class WineditlineConan(ConanFile): name = "wineditline" - description = ( - "A BSD-licensed EditLine API implementation for the native " - "Windows Console" - ) + description = "A BSD-licensed EditLine API implementation for the native Windows Console" + license = "BSD-3-Clause" url = "https://github.com/conan-io/conan-center-index" homepage = "http://mingweditline.sourceforge.net/" topics = ("readline", "editline", "windows") - license = "BSD-3-Clause" - generators = ("cmake",) - settings = ("os", "arch", "compiler", "build_type") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], } default_options = { "shared": False, } - exports_sources = ("patches/*", "CMakeLists.txt") + provides = "editline" + + @property + def _target_name(self): + return "edit" if self.options.shared else "edit_static" + + def configure(self): + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + cmake_layout(self, src_folder="src") def validate(self): if self.settings.os != "Windows": - message = "wineditline is supported only on Windows." - raise ConanInvalidConfiguration(message) - - @property - def _source_subfolder(self): - return "source_subfolder" + raise ConanInvalidConfiguration(f"{self.ref} is supported only on Windows.") def source(self): - root = self._source_subfolder - get_args = self.conan_data["sources"][self.version] - tools.get(**get_args, destination=root, strip_root=True) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - def configure(self): - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + def generate(self): + tc = CMakeToolchain(self) + tc.generate() - @functools.lru_cache(1) - def _configure_cmake(self): + def build(self): cmake = CMake(self) cmake.configure() - return cmake - - def build(self): - for patch in self.conan_data["patches"][self.version]: - tools.patch(**patch) - self._configure_cmake().build() + cmake.build(target=self._target_name) def package(self): - self.copy("COPYING", "licenses", self._source_subfolder) - self._configure_cmake().install() + copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + copy(self, "*.h", dst=os.path.join(self.package_folder, "include", "editline"), src=os.path.join(self.source_folder, "src", "editline")) + copy(self, "*.lib", dst=os.path.join(self.package_folder, "lib"), src=self.build_folder, keep_path=False) + copy(self, "*.dll", dst=os.path.join(self.package_folder, "bin"), src=self.build_folder, keep_path=False) def package_info(self): - self.cpp_info.libs = ["edit"] + self.cpp_info.libs = [self._target_name] diff --git a/recipes/wineditline/all/patches/0001-fix-cmakelists.patch b/recipes/wineditline/all/patches/0001-fix-cmakelists.patch deleted file mode 100644 index ef01b0ca0616b..0000000000000 --- a/recipes/wineditline/all/patches/0001-fix-cmakelists.patch +++ /dev/null @@ -1,43 +0,0 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -1,25 +1,16 @@ --cmake_minimum_required (VERSION 2.6) --project (WinEditLine) --set (WinEditLine_VERSION_MAJOR 2) --set (WinEditLine_VERSION_MINOR 2) --if (MSVC AND MSVC_USE_STATIC_RUNTIME) --foreach(flag_var -- CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE -- CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) -- if(${flag_var} MATCHES "/MD") -- string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") -- endif(${flag_var} MATCHES "/MD") --endforeach(flag_var) --endif() --if(NOT DEFINED LIB_SUFFIX) -- if(CMAKE_SIZEOF_VOID_P MATCHES 4) -- set(LIB_SUFFIX "32") -- else() -- set(LIB_SUFFIX "64") -- endif() --endif() --configure_file ( -- "${PROJECT_SOURCE_DIR}/src/config.h.in" -- "${PROJECT_BINARY_DIR}/config.h" -+cmake_minimum_required(VERSION 3.1) -+ -+project(WinEditLine C) -+ -+add_library(edit src/editline.c src/fn_complete.c src/history.c src/libedit.def) -+target_include_directories(edit PRIVATE src) -+ -+include(GNUInstallDirs) -+ -+install( -+ TARGETS edit -+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" -+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) --add_subdirectory (src) -+ -+install(DIRECTORY src/editline DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/recipes/wineditline/all/test_package/CMakeLists.txt b/recipes/wineditline/all/test_package/CMakeLists.txt index 84a38c545c793..3d8aa097f7a2f 100644 --- a/recipes/wineditline/all/test_package/CMakeLists.txt +++ b/recipes/wineditline/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(test_package C) -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup(TARGETS) - find_package(wineditline REQUIRED CONFIG) add_executable(test_package test_package.c) diff --git a/recipes/wineditline/all/test_package/conanfile.py b/recipes/wineditline/all/test_package/conanfile.py index ec80e0c5cc134..ef5d7042163ec 100644 --- a/recipes/wineditline/all/test_package/conanfile.py +++ b/recipes/wineditline/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", "compiler", "build_type", "arch") - generators = ("cmake", "cmake_find_package_multi") + settings = "os", "arch", "compiler", "build_type" + 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) @@ -13,6 +21,6 @@ def build(self): 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") diff --git a/recipes/wineditline/all/test_package/test_package.c b/recipes/wineditline/all/test_package/test_package.c index b51e6feba3274..452b5269fcee7 100644 --- a/recipes/wineditline/all/test_package/test_package.c +++ b/recipes/wineditline/all/test_package/test_package.c @@ -1,12 +1,7 @@ #include #include -int main(int argc, char const* argv[]) -{ - (void)argc; - (void)argv; - - free_history_entry(NULL); - - return 0; +int main() { + free_history_entry(NULL); + return 0; } diff --git a/recipes/wineditline/all/test_v1_package/CMakeLists.txt b/recipes/wineditline/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/wineditline/all/test_v1_package/CMakeLists.txt @@ -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/) diff --git a/recipes/wineditline/all/test_v1_package/conanfile.py b/recipes/wineditline/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..ec80e0c5cc134 --- /dev/null +++ b/recipes/wineditline/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +import os + +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = ("os", "compiler", "build_type", "arch") + 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)