From 619b058879e0a1c21ad5badef8cf99aca2ccfd7e Mon Sep 17 00:00:00 2001 From: Vasyl Holovachko Date: Fri, 19 Apr 2024 21:38:35 +0200 Subject: [PATCH 1/2] zxcvbn: added recipe for version 2.5 --- recipes/zxcvbn/all/conandata.yml | 19 +++++ recipes/zxcvbn/all/conanfile.py | 83 +++++++++++++++++++ .../zxcvbn/all/patches/2.5-0001-tests.patch | 11 +++ .../zxcvbn/all/patches/2.5-0002-windows.patch | 37 +++++++++ .../all/patches/2.5-0003-crossbuilding.patch | 13 +++ .../zxcvbn/all/test_package/CMakeLists.txt | 7 ++ recipes/zxcvbn/all/test_package/conanfile.py | 25 ++++++ .../zxcvbn/all/test_package/test_package.c | 7 ++ recipes/zxcvbn/config.yml | 3 + 9 files changed, 205 insertions(+) create mode 100644 recipes/zxcvbn/all/conandata.yml create mode 100644 recipes/zxcvbn/all/conanfile.py create mode 100644 recipes/zxcvbn/all/patches/2.5-0001-tests.patch create mode 100644 recipes/zxcvbn/all/patches/2.5-0002-windows.patch create mode 100644 recipes/zxcvbn/all/patches/2.5-0003-crossbuilding.patch create mode 100644 recipes/zxcvbn/all/test_package/CMakeLists.txt create mode 100644 recipes/zxcvbn/all/test_package/conanfile.py create mode 100644 recipes/zxcvbn/all/test_package/test_package.c create mode 100644 recipes/zxcvbn/config.yml diff --git a/recipes/zxcvbn/all/conandata.yml b/recipes/zxcvbn/all/conandata.yml new file mode 100644 index 0000000000000..96c3cf2110611 --- /dev/null +++ b/recipes/zxcvbn/all/conandata.yml @@ -0,0 +1,19 @@ +sources: + "2.5": + archive: + url: "https://github.com/tsyrogit/zxcvbn-c/archive/refs/tags/v2.5.tar.gz" + sha256: "77d6c6ecb35952a8d8ce7f736b7a2bf466275c48210e309b73782d6b7e84dffd" + cmakelists: + url: "https://raw.githubusercontent.com/tsyrogit/zxcvbn-c/31948901f613a8500e710fe13772591e4ab245bc/CMakeLists.txt" + sha256: "8a5f3c6a7afd203fc3e5e877ec06252a0823473a976e0db910334425005affaa" +patches: + "2.5": + - patch_file: "patches/2.5-0001-tests.patch" + patch_description: "disable building of tests which are broken in the CMakeLists.txt" + patch_type: "portability" + - patch_file: "patches/2.5-0002-windows.patch" + patch_description: "add Windows/Emscripten portability by disabling libm linking and unsupported compile options" + patch_type: "portability" + - patch_file: "patches/2.5-0003-crossbuilding.patch" + patch_description: "crossbuilding: disable the dictgen executable building" + patch_type: "portability" diff --git a/recipes/zxcvbn/all/conanfile.py b/recipes/zxcvbn/all/conanfile.py new file mode 100644 index 0000000000000..33079814bf555 --- /dev/null +++ b/recipes/zxcvbn/all/conanfile.py @@ -0,0 +1,83 @@ +from conan import ConanFile +from conan.tools.build import cross_building +from conan.tools.cmake import CMake, CMakeToolchain +from conan.tools.files import copy, download, export_conandata_patches, get, patch, rm +import os + +required_conan_version = ">=1.54.0" + +class ZxcvbnConan(ConanFile): + name = "zxcvbn" + description = "C/C++ implementation of the zxcvbn password strength estimation" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/tsyrogit/zxcvbn-c" + topics = ("password", "security", "zxcvbn") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def build_requirements(self): + if cross_building(self): + self.tool_requires(f"{self.name}/{self.version}") + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def source(self): + sources = self.conan_data["sources"][self.version] + get(self, **sources["archive"], strip_root=True) + download(self, filename="CMakeLists.txt", **sources["cmakelists"]) + # fixes Linux build when "Makefile" is generated but the original "makefile" used + rm(self, "makefile", self.source_folder) + # for the conditional #include "stdafx.h" in zxcvbn.c + with open(os.path.join(self.source_folder, "stdafx.h"), "ab") as f: + f.close() + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def _patch_sources(self): + for it in self.conan_data.get("patches", {}).get(self.version, []): + if "windows" in it["patch_file"] and self.settings.os not in ["Windows", "Emscripten"]: + continue + if "crossbuilding" in it["patch_file"] and not cross_building(self): + continue + entry = it.copy() + patch_file_path = os.path.join(self.export_sources_folder, entry.pop("patch_file")) + patch(self, patch_file=patch_file_path, **entry) + + def build(self): + self._patch_sources() + cmake = CMake(self) + cmake.configure() + cmake.build(target="zxcvbn-shared" if self.options.shared else "zxcvbn-static") + + def package(self): + copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy(self, "zxcvbn.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include")) + for pattern in ["*.a", "*.so*", "*.dylib", "*.lib"]: + copy(self, pattern, src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) + for pattern in ["*.dll", "dictgen", "dictgen.exe"]: + copy(self, pattern, src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) + + def package_info(self): + self.cpp_info.libs = ["zxcvbn"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("m") diff --git a/recipes/zxcvbn/all/patches/2.5-0001-tests.patch b/recipes/zxcvbn/all/patches/2.5-0001-tests.patch new file mode 100644 index 0000000000000..34ebe3d292cff --- /dev/null +++ b/recipes/zxcvbn/all/patches/2.5-0001-tests.patch @@ -0,0 +1,11 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -38,7 +38,7 @@ + set_target_properties(zxcvbn-static PROPERTIES OUTPUT_NAME zxcvbn) + + # in root projects we also want to build/run tests... +-if(PROJECT_IS_TOP_LEVEL) ++if(FALSE) + + # C tests + add_executable(test-internals test-internals.c dict-src.h dict-crc.h zxcvbn.h) diff --git a/recipes/zxcvbn/all/patches/2.5-0002-windows.patch b/recipes/zxcvbn/all/patches/2.5-0002-windows.patch new file mode 100644 index 0000000000000..004371cec8f76 --- /dev/null +++ b/recipes/zxcvbn/all/patches/2.5-0002-windows.patch @@ -0,0 +1,37 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -6,10 +6,10 @@ + target_compile_features(dictgen PUBLIC cxx_std_11) + target_compile_options(dictgen PRIVATE "-O3") + +-add_compile_options("-Wall" "-Wextra") + +-find_library(LIBM m) + ++ ++ + # list of dictionaries + set(WORDS words-eng_wiki.txt words-female.txt words-male.txt words-passwd.txt words-surname.txt words-tv_film.txt) + list(TRANSFORM WORDS PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) +@@ -23,18 +23,18 @@ + add_library(zxcvbn-shared SHARED zxcvbn.c dict-crc.h dict-src.h) + target_include_directories(zxcvbn-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(zxcvbn-shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +-target_link_libraries(zxcvbn-shared PUBLIC ${LIBM}) ++ + set_target_properties(zxcvbn-shared PROPERTIES + POSITION_INDEPENDENT_CODE ON + OUTPUT_NAME zxcvbn + VERSION ${CMAKE_PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +-) ++ WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + # build static version of library + add_library(zxcvbn-static STATIC zxcvbn.c dict-crc.h dict-src.h) + target_include_directories(zxcvbn-static PRIVATE ${CMAKE_CURRENT_BINARY_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +-target_link_libraries(zxcvbn-static PUBLIC ${LIBM}) ++ + set_target_properties(zxcvbn-static PROPERTIES OUTPUT_NAME zxcvbn) + + # in root projects we also want to build/run tests... diff --git a/recipes/zxcvbn/all/patches/2.5-0003-crossbuilding.patch b/recipes/zxcvbn/all/patches/2.5-0003-crossbuilding.patch new file mode 100644 index 0000000000000..8e840ab62b677 --- /dev/null +++ b/recipes/zxcvbn/all/patches/2.5-0003-crossbuilding.patch @@ -0,0 +1,13 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -2,7 +2,7 @@ + + project(zxcvbn-c VERSION 0 LANGUAGES C CXX) + +-add_executable(dictgen dict-generate.cpp) +-target_compile_features(dictgen PUBLIC cxx_std_11) +-target_compile_options(dictgen PRIVATE "-O3") ++add_custom_target(dictgen ++ COMMAND ${CMAKE_COMMAND} -E echo "Using prebuilt dictgen" ++) + diff --git a/recipes/zxcvbn/all/test_package/CMakeLists.txt b/recipes/zxcvbn/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..f6c2cf0f3a762 --- /dev/null +++ b/recipes/zxcvbn/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(zxcvbn REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE zxcvbn::zxcvbn) diff --git a/recipes/zxcvbn/all/test_package/conanfile.py b/recipes/zxcvbn/all/test_package/conanfile.py new file mode 100644 index 0000000000000..9db52e8a9c80b --- /dev/null +++ b/recipes/zxcvbn/all/test_package/conanfile.py @@ -0,0 +1,25 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + +class ZxcvbnTestPackageConan(ConanFile): + 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 can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/zxcvbn/all/test_package/test_package.c b/recipes/zxcvbn/all/test_package/test_package.c new file mode 100644 index 0000000000000..94532fb932215 --- /dev/null +++ b/recipes/zxcvbn/all/test_package/test_package.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + ZxcvbnMatch("password", NULL, NULL); + + return EXIT_SUCCESS; +} diff --git a/recipes/zxcvbn/config.yml b/recipes/zxcvbn/config.yml new file mode 100644 index 0000000000000..ab826811e95e7 --- /dev/null +++ b/recipes/zxcvbn/config.yml @@ -0,0 +1,3 @@ +versions: + "2.5": + folder: all From d89cac73fb9fd76037071ed4f53e7ef3d9577394 Mon Sep 17 00:00:00 2001 From: Vasyl Holovachko Date: Tue, 23 Apr 2024 17:08:53 +0200 Subject: [PATCH 2/2] zxcvbn: refactored conditional patches --- recipes/zxcvbn/all/conandata.yml | 8 +----- recipes/zxcvbn/all/conanfile.py | 25 +++++++++++-------- ...01-tests.patch => 2.5-0001-no-tests.patch} | 0 ...ossbuilding.patch => 2.5-no-dictgen.patch} | 0 ...5-0002-windows.patch => 2.5-no-libm.patch} | 25 +++---------------- .../all/patches/2.5-windows-portability.patch | 17 +++++++++++++ 6 files changed, 37 insertions(+), 38 deletions(-) rename recipes/zxcvbn/all/patches/{2.5-0001-tests.patch => 2.5-0001-no-tests.patch} (100%) rename recipes/zxcvbn/all/patches/{2.5-0003-crossbuilding.patch => 2.5-no-dictgen.patch} (100%) rename recipes/zxcvbn/all/patches/{2.5-0002-windows.patch => 2.5-no-libm.patch} (58%) create mode 100644 recipes/zxcvbn/all/patches/2.5-windows-portability.patch diff --git a/recipes/zxcvbn/all/conandata.yml b/recipes/zxcvbn/all/conandata.yml index 96c3cf2110611..2c740c75e8472 100644 --- a/recipes/zxcvbn/all/conandata.yml +++ b/recipes/zxcvbn/all/conandata.yml @@ -8,12 +8,6 @@ sources: sha256: "8a5f3c6a7afd203fc3e5e877ec06252a0823473a976e0db910334425005affaa" patches: "2.5": - - patch_file: "patches/2.5-0001-tests.patch" + - patch_file: "patches/2.5-0001-no-tests.patch" patch_description: "disable building of tests which are broken in the CMakeLists.txt" patch_type: "portability" - - patch_file: "patches/2.5-0002-windows.patch" - patch_description: "add Windows/Emscripten portability by disabling libm linking and unsupported compile options" - patch_type: "portability" - - patch_file: "patches/2.5-0003-crossbuilding.patch" - patch_description: "crossbuilding: disable the dictgen executable building" - patch_type: "portability" diff --git a/recipes/zxcvbn/all/conanfile.py b/recipes/zxcvbn/all/conanfile.py index 33079814bf555..e2844b44c434f 100644 --- a/recipes/zxcvbn/all/conanfile.py +++ b/recipes/zxcvbn/all/conanfile.py @@ -1,7 +1,7 @@ from conan import ConanFile from conan.tools.build import cross_building from conan.tools.cmake import CMake, CMakeToolchain -from conan.tools.files import copy, download, export_conandata_patches, get, patch, rm +from conan.tools.files import apply_conandata_patches, copy, download, get, patch, rm import os required_conan_version = ">=1.54.0" @@ -29,7 +29,7 @@ def build_requirements(self): self.tool_requires(f"{self.name}/{self.version}") def export_sources(self): - export_conandata_patches(self) + copy(self, f"{self.version}-*.patch", dst=os.path.join(self.export_sources_folder, "patches"), src=os.path.join(self.recipe_folder, "patches")) def config_options(self): if self.settings.os == "Windows": @@ -53,15 +53,20 @@ def generate(self): tc = CMakeToolchain(self) tc.generate() + def _patch_if_exists(self, patch_name): + patch_file=os.path.join(self.export_sources_folder, "patches", f"{self.version}-{patch_name}.patch") + if os.path.exists(patch_file): + print(f"Applying the '{patch_name}' patch...") + patch(self, patch_file=patch_file) + def _patch_sources(self): - for it in self.conan_data.get("patches", {}).get(self.version, []): - if "windows" in it["patch_file"] and self.settings.os not in ["Windows", "Emscripten"]: - continue - if "crossbuilding" in it["patch_file"] and not cross_building(self): - continue - entry = it.copy() - patch_file_path = os.path.join(self.export_sources_folder, entry.pop("patch_file")) - patch(self, patch_file=patch_file_path, **entry) + apply_conandata_patches(self) + if cross_building(self): + self._patch_if_exists("no-dictgen") + if self.settings.os not in ["Linux", "FreeBSD"]: + self._patch_if_exists("no-libm") + if self.settings.os == "Windows": + self._patch_if_exists("windows-portability") def build(self): self._patch_sources() diff --git a/recipes/zxcvbn/all/patches/2.5-0001-tests.patch b/recipes/zxcvbn/all/patches/2.5-0001-no-tests.patch similarity index 100% rename from recipes/zxcvbn/all/patches/2.5-0001-tests.patch rename to recipes/zxcvbn/all/patches/2.5-0001-no-tests.patch diff --git a/recipes/zxcvbn/all/patches/2.5-0003-crossbuilding.patch b/recipes/zxcvbn/all/patches/2.5-no-dictgen.patch similarity index 100% rename from recipes/zxcvbn/all/patches/2.5-0003-crossbuilding.patch rename to recipes/zxcvbn/all/patches/2.5-no-dictgen.patch diff --git a/recipes/zxcvbn/all/patches/2.5-0002-windows.patch b/recipes/zxcvbn/all/patches/2.5-no-libm.patch similarity index 58% rename from recipes/zxcvbn/all/patches/2.5-0002-windows.patch rename to recipes/zxcvbn/all/patches/2.5-no-libm.patch index 004371cec8f76..780cb13cc0604 100644 --- a/recipes/zxcvbn/all/patches/2.5-0002-windows.patch +++ b/recipes/zxcvbn/all/patches/2.5-no-libm.patch @@ -1,19 +1,6 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -6,10 +6,10 @@ - target_compile_features(dictgen PUBLIC cxx_std_11) - target_compile_options(dictgen PRIVATE "-O3") - --add_compile_options("-Wall" "-Wextra") - --find_library(LIBM m) - -+ -+ - # list of dictionaries - set(WORDS words-eng_wiki.txt words-female.txt words-male.txt words-passwd.txt words-surname.txt words-tv_film.txt) - list(TRANSFORM WORDS PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) -@@ -23,18 +23,18 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -23,7 +23,7 @@ add_custom_command(OUTPUT dict-crc.h zxcvbn.dict COMMAND dictgen -b -o ${CMAKE_C add_library(zxcvbn-shared SHARED zxcvbn.c dict-crc.h dict-src.h) target_include_directories(zxcvbn-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(zxcvbn-shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) @@ -22,11 +9,7 @@ set_target_properties(zxcvbn-shared PROPERTIES POSITION_INDEPENDENT_CODE ON OUTPUT_NAME zxcvbn - VERSION ${CMAKE_PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} --) -+ WINDOWS_EXPORT_ALL_SYMBOLS TRUE) - +@@ -34,7 +34,7 @@ set_target_properties(zxcvbn-shared PROPERTIES # build static version of library add_library(zxcvbn-static STATIC zxcvbn.c dict-crc.h dict-src.h) target_include_directories(zxcvbn-static PRIVATE ${CMAKE_CURRENT_BINARY_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/recipes/zxcvbn/all/patches/2.5-windows-portability.patch b/recipes/zxcvbn/all/patches/2.5-windows-portability.patch new file mode 100644 index 0000000000000..b41c3ad45f931 --- /dev/null +++ b/recipes/zxcvbn/all/patches/2.5-windows-portability.patch @@ -0,0 +1,17 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,4 +9,4 @@ +-add_compile_options("-Wall" "-Wextra") ++ + + find_library(LIBM m) + +@@ -29,7 +29,7 @@ set_target_properties(zxcvbn-shared PROPERTIES + OUTPUT_NAME zxcvbn + VERSION ${CMAKE_PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +-) ++ WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + # build static version of library + add_library(zxcvbn-static STATIC zxcvbn.c dict-crc.h dict-src.h)