From 1214a12a235b661b9f62869c5bed70d501259c13 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Tue, 27 Apr 2021 19:11:12 -0400 Subject: [PATCH 01/11] Add support for cpr 1.6.2 --- recipes/cpr/all/conandata.yml | 7 ++++ recipes/cpr/all/conanfile.py | 39 ++++++++++++++++--- .../all/patches/008-fix-curl-components.patch | 36 +++++++++++++++++ recipes/cpr/config.yml | 2 + 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 recipes/cpr/all/patches/008-fix-curl-components.patch diff --git a/recipes/cpr/all/conandata.yml b/recipes/cpr/all/conandata.yml index 4fd92fd427d17..4a1d4f821a3eb 100644 --- a/recipes/cpr/all/conandata.yml +++ b/recipes/cpr/all/conandata.yml @@ -14,6 +14,10 @@ sources: "1.6.0": sha256: "5a20a9f014b47988f5230d008174e5db2b33f8c547df825e6beae0c78fc05a9e" url: https://github.com/whoshuu/cpr/archive/1.6.0.tar.gz + "1.6.2": + sha256: "c45f9c55797380c6ba44060f0c73713fbd7989eeb1147aedb8723aa14f3afaa3" + url: https://github.com/whoshuu/cpr/archive/1.6.2.tar.gz + patches: "1.3.0": - patch_file: "patches/001-fix-curl-define.patch" @@ -39,3 +43,6 @@ patches: base_path: "source_subfolder" - patch_file: "patches/007-patch-sanitizer.patch" base_path: "source_subfolder" + "1.6.2": + - patch_file: "patches/008-fix-curl-components.patch" + base_path: "source_subfolder" diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 080b443527dd0..8ecb33a21bc12 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -18,12 +18,16 @@ class CprConan(ConanFile): "fPIC": [True, False], "with_openssl": [True, False], "with_winssl": [True, False], + "with_darwinssl": [True, False], + "no_ssl": [True, False], } default_options = { "shared": False, "fPIC": True, "with_openssl": True, "with_winssl": False, + "with_darwinssl": False, + "no_ssl": False, } _cmake = None @@ -40,13 +44,23 @@ def _build_subfolder(self): def _supports_openssl(self): # https://github.com/whoshuu/cpr/commit/b036a3279ba62720d1e43362d32202bf412ea152 # https://github.com/whoshuu/cpr/releases/tag/1.5.0 - return tools.Version(self.version) >= "1.5.0" + return tools.Version(self.version) >= "1.5.0" and not tools.is_apple_os(self.settings.os) @property def _supports_winssl(self): # https://github.com/whoshuu/cpr/commit/18e1fc5c3fc0ffc07695f1d78897fb69e7474ea9 # https://github.com/whoshuu/cpr/releases/tag/1.5.1 - return tools.Version(self.version) >= "1.5.1" + return tools.Version(self.version) >= "1.5.1" and self.settings.os == "Windows" + + @property + def _supports_darwinssl(self): + # https://github.com/whoshuu/cpr/releases/tag/1.6.1 + return tools.Version(self.version) >= "1.6.1" + + @property + def _can_disable_ssl(self): + # https://github.com/whoshuu/cpr/releases/tag/1.6.0 + return not self._uses_old_cmake_options @property def _uses_old_cmake_options(self): @@ -74,6 +88,8 @@ def configure(self): del self.options.with_openssl if not self._supports_winssl: del self.options.with_winssl + if not self._supports_darwinssl: + del self.options.with_darwinssl # Make sure libcurl uses the same SSL implementation if self.options.get_safe("with_openssl", False): @@ -82,6 +98,8 @@ def configure(self): if self.options.get_safe("with_winssl", False): # self.options["libcurl"].with_winssl = True # deprecated in https://github.com/conan-io/conan-center-index/pull/2880 self.options["libcurl"].with_ssl = "schannel" + if self.options.get_safe("with_darwinssl", False): + self.options["libcurl"].with_ssl = "darwinssl" def source(self): @@ -120,27 +138,38 @@ def _configure_cmake(self): self._cmake.definitions[self._get_cmake_option("CPR_BUILD_TESTS")] = False self._cmake.definitions[self._get_cmake_option("CPR_GENERATE_COVERAGE")] = False self._cmake.definitions[self._get_cmake_option("CPR_USE_SYSTEM_GTEST")] = False + if self._supports_openssl: self._cmake.definitions["CMAKE_USE_OPENSSL"] = self.options.get_safe("with_openssl", False) + + if self._supports_darwinssl: + self._cmake.definitions[self._get_cmake_option("CPR_FORCE_DARWINSSL_BACKEND")] = self.options.get_safe("with_darwinssl", False) + if self._supports_winssl: # The CMake options changed # https://github.com/whoshuu/cpr/commit/18e1fc5c3fc0ffc07695f1d78897fb69e7474ea9#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR39-R40 self._cmake.definitions[self._get_cmake_option("CPR_FORCE_OPENSSL_BACKEND")] = self.options.get_safe("with_openssl", False) self._cmake.definitions[self._get_cmake_option("CPR_FORCE_WINSSL_BACKEND")] = self.options.get_safe("with_winssl", False) - supports_any_ssl = self.options.get_safe("with_openssl", False) or self.options.get_safe("with_winssl", False) - if not self._uses_old_cmake_options and not supports_any_ssl: + if self._can_disable_ssl and self.options.get_safe("no_ssl", False): self._cmake.definitions["CPR_ENABLE_SSL"] = False self._cmake.configure(build_folder=self._build_subfolder) return self._cmake def validate(self): if not self._uses_valid_abi_and_compiler: - raise ConanInvalidConfiguration("Cannot compile CPR/1.6.0 with libstdc++ on clang < 9") + raise ConanInvalidConfiguration("Cannot compile cpr/1.6.0 with libstdc++ on clang < 9") + + if not self._can_disable_ssl and self.options.get_safe("no_ssl", False): + # https://github.com/whoshuu/cpr/issues/546 + raise ConanInvalidConfiguration("cpr < 1.6.0 cannot manually disable SSL.") if self.options.get_safe("with_openssl", False) and tools.is_apple_os(self.settings.os): # https://github.com/whoshuu/cpr/issues/546 raise ConanInvalidConfiguration("cpr cannot be built on macOS with openssl") + if self.options.get_safe("with_darwinssl", False) and not tools.is_apple_os(self.settings.os): + raise ConanInvalidConfiguration("cpr only supports darwinssl on macOS") + if self.options.get_safe("with_winssl", False) and self.settings.os != "Windows": raise ConanInvalidConfiguration("cpr only supports winssl on Windows") diff --git a/recipes/cpr/all/patches/008-fix-curl-components.patch b/recipes/cpr/all/patches/008-fix-curl-components.patch new file mode 100644 index 0000000000000..3b91c2b61c447 --- /dev/null +++ b/recipes/cpr/all/patches/008-fix-curl-components.patch @@ -0,0 +1,36 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -120,29 +120,11 @@ endif() + + # Curl configuration + if(CPR_FORCE_USE_SYSTEM_CURL) +- if(CPR_ENABLE_SSL) +- find_package(CURL COMPONENTS HTTP HTTPS SSL) +- if(CURL_FOUND) +- message(STATUS "Curl ${CURL_VERSION_STRING} found on this system.") +- # To be able to load certificates under Windows when using OpenSSL: +- if(CMAKE_USE_OPENSSL AND WIN32 AND (NOT (CURL_VERSION_STRING VERSION_GREATER_EQUAL "7.71.0"))) +- message(FATAL_ERROR "Your system curl version (${CURL_VERSION_STRING}) is too old to support OpenSSL on Windows which requires curl >= 7.71.0. Update your curl version, use WinSSL, disable SSL or use the build in version of curl.") +- endif() +- else() +- find_package(CURL COMPONENTS HTTP) +- if(CURL_FOUND) +- message(FATAL_ERROR "Curl found on this system but WITHOUT HTTPS/SSL support. Either disable SSL by setting CPR_ENABLE_SSL to OFF or use the build in version of curl by setting CPR_FORCE_USE_SYSTEM_CURL to OFF.") +- else() +- message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.") +- endif() +- endif() ++ find_package(CURL) ++ if(CURL_FOUND) ++ message(STATUS "Curl found on this system.") + else() +- find_package(CURL COMPONENTS HTTP) +- if(CURL_FOUND) +- message(STATUS "Curl found on this system.") +- else() +- message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.") +- endif() ++ message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.") + endif() + else() + message(STATUS "Configuring build in curl...") diff --git a/recipes/cpr/config.yml b/recipes/cpr/config.yml index db247a08e22f6..4b27e15b26e7f 100644 --- a/recipes/cpr/config.yml +++ b/recipes/cpr/config.yml @@ -9,3 +9,5 @@ versions: folder: all "1.6.0": folder: all + "1.6.2": + folder: all From 01e244887d3ac5029701b3c6ce4e45ca41e4dfb2 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Tue, 27 Apr 2021 22:12:08 -0400 Subject: [PATCH 02/11] Limit darwinssl to macos --- recipes/cpr/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 8ecb33a21bc12..c2a42cdf1d2d2 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -55,7 +55,7 @@ def _supports_winssl(self): @property def _supports_darwinssl(self): # https://github.com/whoshuu/cpr/releases/tag/1.6.1 - return tools.Version(self.version) >= "1.6.1" + return tools.Version(self.version) >= "1.6.1" and tools.is_apple_os(self.settings.os) @property def _can_disable_ssl(self): From ea0f20ab518767491f1541388f7f2dd6121d7370 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Wed, 28 Apr 2021 00:22:42 -0400 Subject: [PATCH 03/11] Refactor SSL options to use string value --- recipes/cpr/all/conanfile.py | 135 +++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 47 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index c2a42cdf1d2d2..926e469d0fd74 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -1,9 +1,13 @@ +from typing import no_type_check from conans import ConanFile, CMake, tools from conans.errors import ConanInvalidConfiguration import os class CprConan(ConanFile): + AUTO_SSL = "auto" + NO_SSL = "off" + name = "cpr" description = "C++ Requests: Curl for People, a spiritual port of Python Requests" url = "https://github.com/conan-io/conan-center-index" @@ -18,16 +22,14 @@ class CprConan(ConanFile): "fPIC": [True, False], "with_openssl": [True, False], "with_winssl": [True, False], - "with_darwinssl": [True, False], - "no_ssl": [True, False], + "ssl": ["openssl", "darwinssl", "winssl", AUTO_SSL, NO_SSL] } default_options = { "shared": False, "fPIC": True, - "with_openssl": True, + "with_openssl": False, "with_winssl": False, - "with_darwinssl": False, - "no_ssl": False, + "ssl": AUTO_SSL } _cmake = None @@ -58,7 +60,7 @@ def _supports_darwinssl(self): return tools.Version(self.version) >= "1.6.1" and tools.is_apple_os(self.settings.os) @property - def _can_disable_ssl(self): + def _can_auto_ssl(self): # https://github.com/whoshuu/cpr/releases/tag/1.6.0 return not self._uses_old_cmake_options @@ -82,24 +84,24 @@ def config_options(self): del self.options.fPIC def configure(self): + SSL_CURL_LIBS = { + "openssl": "openssl", + "darwinssl": "darwinssl", + "winssl": "schannel" + } + if self.options.shared: del self.options.fPIC if not self._supports_openssl: del self.options.with_openssl if not self._supports_winssl: del self.options.with_winssl - if not self._supports_darwinssl: - del self.options.with_darwinssl + ssl_library = self._get_ssl_library() # Make sure libcurl uses the same SSL implementation - if self.options.get_safe("with_openssl", False): - # self.options["libcurl"].with_openssl = True # deprecated in https://github.com/conan-io/conan-center-index/pull/2880 - self.options["libcurl"].with_ssl = "openssl" - if self.options.get_safe("with_winssl", False): - # self.options["libcurl"].with_winssl = True # deprecated in https://github.com/conan-io/conan-center-index/pull/2880 - self.options["libcurl"].with_ssl = "schannel" - if self.options.get_safe("with_darwinssl", False): - self.options["libcurl"].with_ssl = "darwinssl" + # "auto" will be handled by cpr + if self._supports_ssl_library(ssl_library) and ssl_library in SSL_CURL_LIBS: + self.options["libcurl"].with_ssl = SSL_CURL_LIBS[ssl_library] def source(self): @@ -139,52 +141,91 @@ def _configure_cmake(self): self._cmake.definitions[self._get_cmake_option("CPR_GENERATE_COVERAGE")] = False self._cmake.definitions[self._get_cmake_option("CPR_USE_SYSTEM_GTEST")] = False - if self._supports_openssl: - self._cmake.definitions["CMAKE_USE_OPENSSL"] = self.options.get_safe("with_openssl", False) - - if self._supports_darwinssl: - self._cmake.definitions[self._get_cmake_option("CPR_FORCE_DARWINSSL_BACKEND")] = self.options.get_safe("with_darwinssl", False) + self._cmake.definitions["CMAKE_USE_OPENSSL"] = self._supports_openssl and self.options.get_safe("with_openssl", False) + ssl_value = self.options.get_safe("ssl") + SSL_OPTIONS = { + "CPR_FORCE_DARWINSSL_BACKEND": ssl_value == "darwinssl", + "CPR_FORCE_OPENSSL_BACKEND": ssl_value == "openssl", + "CPR_FORCE_WINSSL_BACKEND": ssl_value == "winssl", + } - if self._supports_winssl: # The CMake options changed - # https://github.com/whoshuu/cpr/commit/18e1fc5c3fc0ffc07695f1d78897fb69e7474ea9#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR39-R40 - self._cmake.definitions[self._get_cmake_option("CPR_FORCE_OPENSSL_BACKEND")] = self.options.get_safe("with_openssl", False) - self._cmake.definitions[self._get_cmake_option("CPR_FORCE_WINSSL_BACKEND")] = self.options.get_safe("with_winssl", False) + for cmake_option, value in SSL_OPTIONS.items(): + self._cmake.definitions[self._get_cmake_option(cmake_option)] = value - if self._can_disable_ssl and self.options.get_safe("no_ssl", False): + # If we are on a version where disabling SSL requires a cmake option, disable it + if not self._uses_old_cmake_options and self._get_ssl_library() == CprConan.NO_SSL: self._cmake.definitions["CPR_ENABLE_SSL"] = False + self._cmake.configure(build_folder=self._build_subfolder) return self._cmake - def validate(self): - if not self._uses_valid_abi_and_compiler: - raise ConanInvalidConfiguration("Cannot compile cpr/1.6.0 with libstdc++ on clang < 9") + # Check if the system supports the given ssl library + def _supports_ssl_library(self, library): + if library == CprConan.NO_SSL: + return True + elif library == CprConan.AUTO_SSL: + return self._can_auto_ssl + + validators = { + "openssl": self._supports_openssl, + "darwinssl": self._supports_darwinssl, + "winssl": self._supports_winssl + } - if not self._can_disable_ssl and self.options.get_safe("no_ssl", False): - # https://github.com/whoshuu/cpr/issues/546 - raise ConanInvalidConfiguration("cpr < 1.6.0 cannot manually disable SSL.") + if library not in validators: + # This should never happen, as the options are validated by conan. + raise ValueError(f"Unknown SSL library: {library}") - if self.options.get_safe("with_openssl", False) and tools.is_apple_os(self.settings.os): - # https://github.com/whoshuu/cpr/issues/546 - raise ConanInvalidConfiguration("cpr cannot be built on macOS with openssl") + return validators[library] - if self.options.get_safe("with_darwinssl", False) and not tools.is_apple_os(self.settings.os): - raise ConanInvalidConfiguration("cpr only supports darwinssl on macOS") + # Get the configured ssl library + def _get_ssl_library(self): + ssl_library = str(self.options.get_safe("ssl")) + if self.options.get_safe("with_openssl", False): + self.output.warn("with_openssl is deprecated. Please use the ssl option.") + return "openssl" + elif self.options.get_safe("with_winssl", False): + self.output.warn("with_winssl is deprecated. Please use the ssl option.") + return "winssl" + elif not self._can_auto_ssl and ssl_library == CprConan.AUTO_SSL: + if self._supports_openssl: + self.output.info("Auto SSL is not available below version 1.6.0. Falling back to openssl") + return "openssl" + elif not self._supports_openssl: + self.output.info("Auto SSL is not available below version 1.6.0, and openssl not supported. Disabling SSL") + return CprConan.NO_SSL + elif ssl_library == CprConan.AUTO_SSL and tools.Version(self.version) in ["1.6.0", "1.6.1"] and tools.is_apple_os(self.settings.os): + # https://github.com/whoshuu/cpr/issues/546 + self.output.info("Auto SSL is not available on macOS with version 1.6.0/1.6.1, and openssl not supported. Disabling SSL") + return CprConan.NO_SSL + + return ssl_library + + def validate(self): + SSL_FAILURE_MESSAGES = { + "openssl": "OpenSSL is not supported on macOS or on CPR versions < 1.5.0", + "darwinssl": "DarwinSSL is only supported on macOS and on CPR versions >= 1.6.1", + "winssl": "WinSSL is only on Windows and on CPR versions >= 1.5.1", + CprConan.AUTO_SSL: "Automatic SSL selection is only available on CPR versions >= 1.6.0" + } - if self.options.get_safe("with_winssl", False) and self.settings.os != "Windows": - raise ConanInvalidConfiguration("cpr only supports winssl on Windows") + if not self._uses_valid_abi_and_compiler: + raise ConanInvalidConfiguration("Cannot compile cpr/1.6.0 with libstdc++ on clang < 9") + + ssl_library = self._get_ssl_library() + if not self._supports_ssl_library(ssl_library): + raise ConanInvalidConfiguration( + f"Invalid SSL selection for the given configuration: {SSL_FAILURE_MESSAGES[ssl_library]}" + if ssl_library not in (CprConan.AUTO_SSL, CprConan.NO_SSL) + else f"Invalid value of ssl option, {ssl_library}" + ) - if self.options.get_safe("with_openssl", False) and self.options.get_safe("with_winssl", False): - raise ConanInvalidConfiguration("cpr can not be built with both openssl and winssl") + if ssl_library not in (CprConan.AUTO_SSL, CprConan.NO_SSL) and ssl_library != self.options["libcurl"].with_ssl: + raise ConanInvalidConfiguration(f"cpr requires libcurl to be built with the option with_ssl='{self.options.get_safe('ssl')}'.") if self.settings.compiler == "Visual Studio" and self.options.shared and "MT" in self.settings.compiler.runtime: raise ConanInvalidConfiguration("Visual Studio build for shared library with MT runtime is not supported") - if self.options.get_safe("with_openssl", False) and self.options["libcurl"].with_ssl != "openssl": - raise ConanInvalidConfiguration("cpr requires libcurl to be built with the option with_ssl='openssl'.") - - if self.options.get_safe("with_winssl", False) and self.options["libcurl"].with_ssl != "schannel": - raise ConanInvalidConfiguration("cpr requires libcurl to be built with the option with_ssl='schannel'.") - def build(self): self._patch_sources() From c72da76461ae60b301d26da50fb89c99ba4faf28 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Wed, 28 Apr 2021 09:46:40 -0400 Subject: [PATCH 04/11] Style fixes --- recipes/cpr/all/conanfile.py | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 926e469d0fd74..f1593153b6a0a 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -5,8 +5,8 @@ class CprConan(ConanFile): - AUTO_SSL = "auto" - NO_SSL = "off" + _AUTO_SSL = "auto" + _NO_SSL = "off" name = "cpr" description = "C++ Requests: Curl for People, a spiritual port of Python Requests" @@ -22,14 +22,14 @@ class CprConan(ConanFile): "fPIC": [True, False], "with_openssl": [True, False], "with_winssl": [True, False], - "ssl": ["openssl", "darwinssl", "winssl", AUTO_SSL, NO_SSL] + "with_ssl": ["openssl", "darwinssl", "winssl", _AUTO_SSL, _NO_SSL] } default_options = { "shared": False, "fPIC": True, "with_openssl": False, "with_winssl": False, - "ssl": AUTO_SSL + "with_ssl": _AUTO_SSL } _cmake = None @@ -141,19 +141,19 @@ def _configure_cmake(self): self._cmake.definitions[self._get_cmake_option("CPR_GENERATE_COVERAGE")] = False self._cmake.definitions[self._get_cmake_option("CPR_USE_SYSTEM_GTEST")] = False - self._cmake.definitions["CMAKE_USE_OPENSSL"] = self._supports_openssl and self.options.get_safe("with_openssl", False) - ssl_value = self.options.get_safe("ssl") + ssl_value = self._get_ssl_library() SSL_OPTIONS = { "CPR_FORCE_DARWINSSL_BACKEND": ssl_value == "darwinssl", "CPR_FORCE_OPENSSL_BACKEND": ssl_value == "openssl", "CPR_FORCE_WINSSL_BACKEND": ssl_value == "winssl", + "CMAKE_USE_OPENSSL": ssl_value == "openssl" } for cmake_option, value in SSL_OPTIONS.items(): self._cmake.definitions[self._get_cmake_option(cmake_option)] = value # If we are on a version where disabling SSL requires a cmake option, disable it - if not self._uses_old_cmake_options and self._get_ssl_library() == CprConan.NO_SSL: + if not self._uses_old_cmake_options and self._get_ssl_library() == CprConan._NO_SSL: self._cmake.definitions["CPR_ENABLE_SSL"] = False self._cmake.configure(build_folder=self._build_subfolder) @@ -161,9 +161,9 @@ def _configure_cmake(self): # Check if the system supports the given ssl library def _supports_ssl_library(self, library): - if library == CprConan.NO_SSL: + if library == CprConan._NO_SSL: return True - elif library == CprConan.AUTO_SSL: + elif library == CprConan._AUTO_SSL: return self._can_auto_ssl validators = { @@ -180,24 +180,24 @@ def _supports_ssl_library(self, library): # Get the configured ssl library def _get_ssl_library(self): - ssl_library = str(self.options.get_safe("ssl")) + ssl_library = str(self.options.get_safe("with_ssl")) if self.options.get_safe("with_openssl", False): - self.output.warn("with_openssl is deprecated. Please use the ssl option.") + self.output.warn("with_openssl is deprecated. Please use the with_ssl option.") return "openssl" elif self.options.get_safe("with_winssl", False): - self.output.warn("with_winssl is deprecated. Please use the ssl option.") + self.output.warn("with_winssl is deprecated. Please use the with_ssl option.") return "winssl" - elif not self._can_auto_ssl and ssl_library == CprConan.AUTO_SSL: + elif not self._can_auto_ssl and ssl_library == CprConan._AUTO_SSL: if self._supports_openssl: self.output.info("Auto SSL is not available below version 1.6.0. Falling back to openssl") return "openssl" elif not self._supports_openssl: self.output.info("Auto SSL is not available below version 1.6.0, and openssl not supported. Disabling SSL") - return CprConan.NO_SSL - elif ssl_library == CprConan.AUTO_SSL and tools.Version(self.version) in ["1.6.0", "1.6.1"] and tools.is_apple_os(self.settings.os): + return CprConan._NO_SSL + elif ssl_library == CprConan._AUTO_SSL and tools.Version(self.version) in ["1.6.0", "1.6.1"] and tools.is_apple_os(self.settings.os): # https://github.com/whoshuu/cpr/issues/546 self.output.info("Auto SSL is not available on macOS with version 1.6.0/1.6.1, and openssl not supported. Disabling SSL") - return CprConan.NO_SSL + return CprConan._NO_SSL return ssl_library @@ -206,7 +206,7 @@ def validate(self): "openssl": "OpenSSL is not supported on macOS or on CPR versions < 1.5.0", "darwinssl": "DarwinSSL is only supported on macOS and on CPR versions >= 1.6.1", "winssl": "WinSSL is only on Windows and on CPR versions >= 1.5.1", - CprConan.AUTO_SSL: "Automatic SSL selection is only available on CPR versions >= 1.6.0" + CprConan._AUTO_SSL: "Automatic SSL selection is only available on CPR versions >= 1.6.0" } if not self._uses_valid_abi_and_compiler: @@ -216,11 +216,11 @@ def validate(self): if not self._supports_ssl_library(ssl_library): raise ConanInvalidConfiguration( f"Invalid SSL selection for the given configuration: {SSL_FAILURE_MESSAGES[ssl_library]}" - if ssl_library not in (CprConan.AUTO_SSL, CprConan.NO_SSL) + if ssl_library not in (CprConan._AUTO_SSL, CprConan._NO_SSL) else f"Invalid value of ssl option, {ssl_library}" ) - if ssl_library not in (CprConan.AUTO_SSL, CprConan.NO_SSL) and ssl_library != self.options["libcurl"].with_ssl: + if ssl_library not in (CprConan._AUTO_SSL, CprConan._NO_SSL) and ssl_library != self.options["libcurl"].with_ssl: raise ConanInvalidConfiguration(f"cpr requires libcurl to be built with the option with_ssl='{self.options.get_safe('ssl')}'.") if self.settings.compiler == "Visual Studio" and self.options.shared and "MT" in self.settings.compiler.runtime: From 0c6ba8bc865b47384c9670cd600708898135cc12 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Wed, 28 Apr 2021 09:54:46 -0400 Subject: [PATCH 05/11] Use new deprecation form --- recipes/cpr/all/conanfile.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index f1593153b6a0a..9588a716d92bb 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -20,15 +20,15 @@ class CprConan(ConanFile): options = { "shared": [True, False], "fPIC": [True, False], - "with_openssl": [True, False], - "with_winssl": [True, False], + "with_openssl": [True, False, "deprecated"], + "with_winssl": [True, False, "deprecated"], "with_ssl": ["openssl", "darwinssl", "winssl", _AUTO_SSL, _NO_SSL] } default_options = { "shared": False, "fPIC": True, - "with_openssl": False, - "with_winssl": False, + "with_openssl": "deprecated", + "with_winssl": "deprecated", "with_ssl": _AUTO_SSL } @@ -178,14 +178,19 @@ def _supports_ssl_library(self, library): return validators[library] + def _print_deprecation_messages(self): + if self.options.get_safe("with_openssl") != "deprecated": + self.output.warn("with_openssl is deprecated. Please use the with_ssl option.") + elif self.options.get_safe("with_winssl") != "deprecated": + self.output.warn("with_winssl is deprecated. Please use the with_ssl option.") + # Get the configured ssl library def _get_ssl_library(self): ssl_library = str(self.options.get_safe("with_ssl")) - if self.options.get_safe("with_openssl", False): - self.output.warn("with_openssl is deprecated. Please use the with_ssl option.") + # These must check for True so that we don't take "deprecated" to be truthy + if self.options.get_safe("with_openssl") == True: return "openssl" - elif self.options.get_safe("with_winssl", False): - self.output.warn("with_winssl is deprecated. Please use the with_ssl option.") + elif self.options.get_safe("with_winssl") == True: return "winssl" elif not self._can_auto_ssl and ssl_library == CprConan._AUTO_SSL: if self._supports_openssl: @@ -209,6 +214,7 @@ def validate(self): CprConan._AUTO_SSL: "Automatic SSL selection is only available on CPR versions >= 1.6.0" } + self._print_deprecation_messages() if not self._uses_valid_abi_and_compiler: raise ConanInvalidConfiguration("Cannot compile cpr/1.6.0 with libstdc++ on clang < 9") From 4cdb5a6155dca36f8daf7d272b218aedfa021ba7 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Wed, 28 Apr 2021 15:46:12 -0400 Subject: [PATCH 06/11] Remove f-strings --- recipes/cpr/all/conanfile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 9588a716d92bb..3ef21c7bbda78 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -174,7 +174,7 @@ def _supports_ssl_library(self, library): if library not in validators: # This should never happen, as the options are validated by conan. - raise ValueError(f"Unknown SSL library: {library}") + raise ValueError("Unknown SSL library: {}".format(library)) return validators[library] @@ -221,13 +221,13 @@ def validate(self): ssl_library = self._get_ssl_library() if not self._supports_ssl_library(ssl_library): raise ConanInvalidConfiguration( - f"Invalid SSL selection for the given configuration: {SSL_FAILURE_MESSAGES[ssl_library]}" + "Invalid SSL selection for the given configuration: {}".format(SSL_FAILURE_MESSAGES[ssl_library]) if ssl_library not in (CprConan._AUTO_SSL, CprConan._NO_SSL) - else f"Invalid value of ssl option, {ssl_library}" + else "Invalid value of ssl option, {}".format(ssl_library) ) if ssl_library not in (CprConan._AUTO_SSL, CprConan._NO_SSL) and ssl_library != self.options["libcurl"].with_ssl: - raise ConanInvalidConfiguration(f"cpr requires libcurl to be built with the option with_ssl='{self.options.get_safe('ssl')}'.") + raise ConanInvalidConfiguration("cpr requires libcurl to be built with the option with_ssl='{}'.".format(self.options.get_safe('ssl'))) if self.settings.compiler == "Visual Studio" and self.options.shared and "MT" in self.settings.compiler.runtime: raise ConanInvalidConfiguration("Visual Studio build for shared library with MT runtime is not supported") From 2505699bac1cce86212d516aaf9047e748ead276 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Wed, 28 Apr 2021 16:17:15 -0400 Subject: [PATCH 07/11] Move overriding of options to configure_options --- recipes/cpr/all/conanfile.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 3ef21c7bbda78..e5663a5e9e61f 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -62,7 +62,12 @@ def _supports_darwinssl(self): @property def _can_auto_ssl(self): # https://github.com/whoshuu/cpr/releases/tag/1.6.0 - return not self._uses_old_cmake_options + return not self._uses_old_cmake_options and not ( + # https://github.com/whoshuu/cpr/issues/546 + tools.Version(self.version) in ["1.6.0", "1.6.1"] + and tools.is_apple_os(self.settings.os) + ) + @property def _uses_old_cmake_options(self): @@ -83,6 +88,15 @@ def config_options(self): if self.settings.os == "Windows": del self.options.fPIC + ssl_library = self._get_ssl_library() + if not self._can_auto_ssl and ssl_library == CprConan._AUTO_SSL: + if self._supports_openssl: + self.output.info("Auto SSL is not available below version 1.6.0. Falling back to openssl") + self.options.with_ssl = "openssl" + else: + self.output.info("Auto SSL is not available below version 1.6.0 (or below 1.6.2 on macOS), and openssl not supported. Disabling SSL") + self.options.with_ssl = CprConan._NO_SSL + def configure(self): SSL_CURL_LIBS = { "openssl": "openssl", @@ -169,7 +183,8 @@ def _supports_ssl_library(self, library): validators = { "openssl": self._supports_openssl, "darwinssl": self._supports_darwinssl, - "winssl": self._supports_winssl + "winssl": self._supports_winssl, + CprConan._AUTO_SSL: self._can_auto_ssl } if library not in validators: @@ -192,17 +207,6 @@ def _get_ssl_library(self): return "openssl" elif self.options.get_safe("with_winssl") == True: return "winssl" - elif not self._can_auto_ssl and ssl_library == CprConan._AUTO_SSL: - if self._supports_openssl: - self.output.info("Auto SSL is not available below version 1.6.0. Falling back to openssl") - return "openssl" - elif not self._supports_openssl: - self.output.info("Auto SSL is not available below version 1.6.0, and openssl not supported. Disabling SSL") - return CprConan._NO_SSL - elif ssl_library == CprConan._AUTO_SSL and tools.Version(self.version) in ["1.6.0", "1.6.1"] and tools.is_apple_os(self.settings.os): - # https://github.com/whoshuu/cpr/issues/546 - self.output.info("Auto SSL is not available on macOS with version 1.6.0/1.6.1, and openssl not supported. Disabling SSL") - return CprConan._NO_SSL return ssl_library @@ -211,7 +215,7 @@ def validate(self): "openssl": "OpenSSL is not supported on macOS or on CPR versions < 1.5.0", "darwinssl": "DarwinSSL is only supported on macOS and on CPR versions >= 1.6.1", "winssl": "WinSSL is only on Windows and on CPR versions >= 1.5.1", - CprConan._AUTO_SSL: "Automatic SSL selection is only available on CPR versions >= 1.6.0" + CprConan._AUTO_SSL: "Automatic SSL selection is only available on CPR versions >= 1.6.0 (and only >= 1.6.2 on macOS)" } self._print_deprecation_messages() @@ -222,7 +226,7 @@ def validate(self): if not self._supports_ssl_library(ssl_library): raise ConanInvalidConfiguration( "Invalid SSL selection for the given configuration: {}".format(SSL_FAILURE_MESSAGES[ssl_library]) - if ssl_library not in (CprConan._AUTO_SSL, CprConan._NO_SSL) + if ssl_library in SSL_FAILURE_MESSAGES else "Invalid value of ssl option, {}".format(ssl_library) ) From 8d7b600716e3533acc8750a4d5c85a04abeb70ba Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 7 May 2021 10:24:21 -0400 Subject: [PATCH 08/11] Remove stray typechecking import --- recipes/cpr/all/conanfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index e5663a5e9e61f..4b265ab412f07 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -1,4 +1,3 @@ -from typing import no_type_check from conans import ConanFile, CMake, tools from conans.errors import ConanInvalidConfiguration import os From c660f6ca01a08ba65b7363cd7266664f618bbe7a Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 7 May 2021 10:25:08 -0400 Subject: [PATCH 09/11] Remove unneeded error checking for ssl validators --- recipes/cpr/all/conanfile.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 4b265ab412f07..530a075556573 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -186,10 +186,7 @@ def _supports_ssl_library(self, library): CprConan._AUTO_SSL: self._can_auto_ssl } - if library not in validators: - # This should never happen, as the options are validated by conan. - raise ValueError("Unknown SSL library: {}".format(library)) - + # A KeyError should never happen, as the options are validated by conan. return validators[library] def _print_deprecation_messages(self): From 9509496dd3583339d53104a8b2e7546c7accc9f5 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 7 May 2021 10:30:00 -0400 Subject: [PATCH 10/11] Remove unneeded change of libcurl ssl --- recipes/cpr/all/conanfile.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/recipes/cpr/all/conanfile.py b/recipes/cpr/all/conanfile.py index 530a075556573..419aafd2738e0 100644 --- a/recipes/cpr/all/conanfile.py +++ b/recipes/cpr/all/conanfile.py @@ -97,12 +97,6 @@ def config_options(self): self.options.with_ssl = CprConan._NO_SSL def configure(self): - SSL_CURL_LIBS = { - "openssl": "openssl", - "darwinssl": "darwinssl", - "winssl": "schannel" - } - if self.options.shared: del self.options.fPIC if not self._supports_openssl: @@ -110,12 +104,6 @@ def configure(self): if not self._supports_winssl: del self.options.with_winssl - ssl_library = self._get_ssl_library() - # Make sure libcurl uses the same SSL implementation - # "auto" will be handled by cpr - if self._supports_ssl_library(ssl_library) and ssl_library in SSL_CURL_LIBS: - self.options["libcurl"].with_ssl = SSL_CURL_LIBS[ssl_library] - def source(self): tools.get(**self.conan_data["sources"][self.version]) From b99b4f68280550aa044eb792727c0c6c054b3f05 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 7 May 2021 10:31:10 -0400 Subject: [PATCH 11/11] Require CURL in 1.6 builds --- recipes/cpr/all/patches/006-fix-curl-components.patch | 2 +- recipes/cpr/all/patches/008-fix-curl-components.patch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/cpr/all/patches/006-fix-curl-components.patch b/recipes/cpr/all/patches/006-fix-curl-components.patch index c5bed3ff8966e..9f469f556bddc 100644 --- a/recipes/cpr/all/patches/006-fix-curl-components.patch +++ b/recipes/cpr/all/patches/006-fix-curl-components.patch @@ -20,7 +20,7 @@ - message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.") - endif() - endif() -+ find_package(CURL) ++ find_package(CURL REQUIRED) + if(CURL_FOUND) + message(STATUS "Curl found on this system.") else() diff --git a/recipes/cpr/all/patches/008-fix-curl-components.patch b/recipes/cpr/all/patches/008-fix-curl-components.patch index 3b91c2b61c447..04da489547e84 100644 --- a/recipes/cpr/all/patches/008-fix-curl-components.patch +++ b/recipes/cpr/all/patches/008-fix-curl-components.patch @@ -20,7 +20,7 @@ - message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.") - endif() - endif() -+ find_package(CURL) ++ find_package(CURL REQUIRED) + if(CURL_FOUND) + message(STATUS "Curl found on this system.") else()