From 1bf613867f0fa01df30c7aabd56422eb8c337b54 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:46:46 +0100 Subject: [PATCH] (#14906) openssl 1.x: fix Mingw build regression * fix the win_bash logic mainly for MinGW * bump zlib & strawberryperl * move layout() after configure() * add VirtualBuildEnv since there might be tool requires * fix openssl installation with MinGW also properly split nmake & make logic in package() --- recipes/openssl/1.x.x/conanfile.py | 125 +++++++++++++++-------------- 1 file changed, 64 insertions(+), 61 deletions(-) diff --git a/recipes/openssl/1.x.x/conanfile.py b/recipes/openssl/1.x.x/conanfile.py index 1b16b3a2fb4f8..9dafdd8695067 100644 --- a/recipes/openssl/1.x.x/conanfile.py +++ b/recipes/openssl/1.x.x/conanfile.py @@ -1,13 +1,16 @@ from conan import ConanFile, conan_version -from conan.tools.env import Environment +from conan.errors import ConanInvalidConfiguration +from conan.tools.apple import is_apple_os, XCRun from conan.tools.build import cross_building -from conan.tools.layout import basic_layout +from conan.tools.env import Environment, VirtualBuildEnv +from conan.tools.files import ( + apply_conandata_patches, chdir, copy, export_conandata_patches, + get, load, rename, replace_in_file, rm, rmdir, save +) from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +from conan.tools.layout import basic_layout from conan.tools.microsoft import is_msvc, msvc_runtime_flag, unix_path -from conan.tools.apple import is_apple_os, XCRun from conan.tools.scm import Version -from conan.errors import ConanInvalidConfiguration -from conan.tools.files import chdir, copy, rename, rmdir, load, save, get, apply_conandata_patches, export_conandata_patches, replace_in_file from contextlib import contextmanager from functools import total_ordering import fnmatch @@ -220,9 +223,12 @@ def configure(self): self.settings.rm_safe("compiler.libcxx") self.settings.rm_safe("compiler.cppstd") + def layout(self): + basic_layout(self, src_folder="src") + def requirements(self): if self._full_version < "1.1.0" and not self.options.get_safe("no_zlib"): - self.requires("zlib/1.2.12") + self.requires("zlib/1.2.13") def validate(self): if self.settings.os == "Emscripten": @@ -231,21 +237,22 @@ def validate(self): def build_requirements(self): if self._settings_build.os == "Windows": - if not self.win_bash: - self.tool_requires("strawberryperl/5.30.0.1") if not self.options.no_asm: self.tool_requires("nasm/2.15.05") - if self.win_bash and not os.getenv("CONAN_BASH_PATH") and not self._use_nmake: - self.build_requires("msys2/cci.latest") - - def layout(self): - basic_layout(self, src_folder="src") + if self._use_nmake: + self.tool_requires("strawberryperl/5.32.1.1") + else: + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") def source(self): get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def generate(self): + VirtualBuildEnv(self).generate() + tc = AutotoolsToolchain(self) # workaround for random error: size too large (archive member extends past the end of the file) # /Library/Developer/CommandLineTools/usr/bin/ar: internal ranlib command failed @@ -262,12 +269,12 @@ def generate(self): env.define("PERL", self._perl) tc.generate(env) gen_info = {} - gen_info["CFLAGS"] = tc.cflags + gen_info["CFLAGS"] = tc.cflags gen_info["CXXFLAGS"] = tc.cxxflags gen_info["DEFINES"] = tc.defines gen_info["LDFLAGS"] = tc.ldflags # Support for self.dependencies in build() method is currently restricted to `generate()` and `validate()` - # See https://github.com/conan-io/conan/issues/12411 for more details + # See https://github.com/conan-io/conan/issues/12411 for more details if self._full_version < "1.1.0" and not self.options.get_safe("no_zlib"): zlib_cpp_info = self.dependencies["zlib"].cpp_info gen_info["zlib_include_path"] = zlib_cpp_info.includedirs[0] @@ -278,7 +285,7 @@ def generate(self): save(self, "gen_info.conf", json.dumps(gen_info)) tc = AutotoolsDeps(self) tc.generate() - + @property def _target_prefix(self): if self._full_version < "1.1.0" and self.settings.build_type == "Debug": @@ -672,7 +679,7 @@ def _create_targets(self): @property def _perl(self): - if self._settings_build.os == "Windows" and not self.win_bash: + if self._use_nmake: # enforce strawberry perl, otherwise wrong perl could be used (from Git bash, MSYS, etc.) build_deps = (dependency.ref.name for require, dependency in self.dependencies.build.items()) if "strawberryperl" in build_deps: @@ -749,7 +756,7 @@ def build(self): replace_in_file(self, self._nmake_makefile, 'INSTALLTOP=\\', 'INSTALLTOP=/') self.run(f'nmake /F {self._nmake_makefile}') - + def _patch_install_name(self): if is_apple_os(self) and self.options.shared: old_str = '-install_name $(INSTALLTOP)/$(LIBDIR)/' @@ -769,59 +776,55 @@ def _replace_runtime_in_file(self, filename): def package(self): copy(self, "*LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"), keep_path=False) - autotools = Autotools(self) - args = [] - if self._full_version >= "1.1.0": - target = "install_sw" - args.append(f"DESTDIR={self.package_folder}") - else: # 1.0.2 support - # Note: 1.0.2 should not be used according to the OpenSSL Project - # See https://www.openssl.org/source/ - if not self._use_nmake: + if self._use_nmake: + args = [] + if self._full_version >= "1.1.0": target = "install_sw" - args.append(f"INSTALL_PREFIX={self.package_folder}") - else: + args.append(f"DESTDIR={self.package_folder}") + else: # 1.0.2 support target = "install" args.append(f"INSTALLTOP={self.package_folder}") openssldir = self.options.openssldir or self._get_default_openssl_dir() args.append(f"OPENSSLDIR={os.path.join(self.package_folder, openssldir)}") - with chdir(self, self.source_folder): - if not self._use_nmake: - autotools.make(target=target, args=args) - else: + with chdir(self, self.source_folder): if self._full_version >= "1.1.0": - self.run(f'nmake /F Makefile {target} {" ".join(args)}') - else: # nmake 1.0.2 support - # Note: 1.0.2 should not be used according to the OpenSSL Project - # See https://www.openssl.org/source/ - self.run(f'nmake /F {self._nmake_makefile} {target} {" ".join(args)}') - - for root, _, files in os.walk(self.package_folder): - for filename in files: - if fnmatch.fnmatch(filename, "*.pdb"): - os.unlink(os.path.join(self.package_folder, root, filename)) - if self._use_nmake: - if self.settings.build_type == 'Debug' and self._full_version >= "1.1.0": - with chdir(self, os.path.join(self.package_folder, 'lib')): + self.run(f'nmake -f Makefile {target} {" ".join(args)}') + else: # 1.0.2 support + self.run(f'nmake -f {self._nmake_makefile} {target} {" ".join(args)}') + rm(self, "*.pdb", self.package_folder, recursive=True) + if self.settings.build_type == "Debug" and self._full_version >= "1.1.0": + with chdir(self, os.path.join(self.package_folder, "lib")): rename(self, "libssl.lib", "libssld.lib") rename(self, "libcrypto.lib", "libcryptod.lib") - # Old OpenSSL version family has issues with permissions. - # See https://github.com/conan-io/conan/issues/5831 - if self._full_version < "1.1.0" and self.options.shared and self.settings.os in ("Android", "FreeBSD", "Linux"): - with chdir(self, os.path.join(self.package_folder, "lib")): - os.chmod("libssl.so.1.0.0", 0o755) - os.chmod("libcrypto.so.1.0.0", 0o755) + else: + autotools = Autotools(self) + args = [] + target = "install_sw" + if self._full_version >= "1.1.0": + args.append(f"DESTDIR={unix_path(self, self.package_folder)}") + else: # 1.0.2 support + args.append(f"INSTALL_PREFIX={unix_path(self, self.package_folder)}") - if self.options.shared: - libdir = os.path.join(self.package_folder, "lib") - for file in os.listdir(libdir): - if self._is_mingw and file.endswith(".dll.a"): - continue - if file.endswith(".a"): - os.unlink(os.path.join(libdir, file)) - - rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + with chdir(self, self.source_folder): + autotools.make(target=target, args=args) + + # Old OpenSSL version family has issues with permissions. + # See https://github.com/conan-io/conan/issues/5831 + if self._full_version < "1.1.0" and self.options.shared and self.settings.os in ("Android", "FreeBSD", "Linux"): + with chdir(self, os.path.join(self.package_folder, "lib")): + os.chmod("libssl.so.1.0.0", 0o755) + os.chmod("libcrypto.so.1.0.0", 0o755) + + if self.options.shared: + libdir = os.path.join(self.package_folder, "lib") + for file in os.listdir(libdir): + if self._is_mingw and file.endswith(".dll.a"): + continue + if file.endswith(".a"): + os.unlink(os.path.join(libdir, file)) + + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) self._create_cmake_module_variables( os.path.join(self.package_folder, self._module_file_rel_path)