From fb3f51b7f57005b2ef390e77670083e7afe0555c Mon Sep 17 00:00:00 2001 From: System-Arch <33330183+System-Arch@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:27:41 -0500 Subject: [PATCH] (#14686) msys2: Conan 2.0 compatibility tweaks * msys2: Conan 2.0 compatibility tweaks * Remove C++ settings in configure() method * Revamped packaging per #KB-H013: "DEFAULT PACKAGE LAYOUT" * Drop Python 2 support * Bumped required_conan_version to clear "failed" label * Added objdump to system_libs * @Spacelm says to ignore objdump hooks issue Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> --- recipes/msys2/all/conanfile.py | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/recipes/msys2/all/conanfile.py b/recipes/msys2/all/conanfile.py index 3025b93ffd61d1..2b2c35b0746fd0 100644 --- a/recipes/msys2/all/conanfile.py +++ b/recipes/msys2/all/conanfile.py @@ -1,21 +1,15 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration, ConanException -from conan.tools.files import chdir, get, replace_in_file +from conan.tools.files import chdir, get, replace_in_file, copy +from conan.tools.layout import basic_layout import fnmatch import os import shutil import subprocess import errno +import ctypes -try: - import ctypes -except ImportError: - pass -except ValueError: - pass - -required_conan_version = ">=1.47.0" - +required_conan_version = ">=1.55.0" class lock: def __init__(self): @@ -38,7 +32,6 @@ def close(self): __del__ = close - class MSYS2Conan(ConanFile): name = "msys2" description = "MSYS2 is a software distro and building platform for Windows" @@ -53,11 +46,13 @@ class MSYS2Conan(ConanFile): "exclude_files": ["ANY"], "packages": ["ANY"], "additional_packages": [None, "ANY"], + "no_kill": [True, False] } default_options = { "exclude_files": "*/link.exe", "packages": "base-devel,binutils,gcc", "additional_packages": None, + "no_kill": False, } short_paths = True @@ -68,9 +63,16 @@ def validate(self): if self.settings.arch != "x86_64": raise ConanInvalidConfiguration("Only Windows x64 supported") + 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 source(self): - # sources are different per configuration - do download in build - pass + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=False) # Preserve tarball root dir (msys64/) def _update_pacman(self): with chdir(self, os.path.join(self._msys_dir, "usr", "bin")): @@ -90,6 +92,8 @@ def _update_pacman(self): # https://github.com/msys2/MSYS2-packages/issues/1966 def _kill_pacman(self): + if self.options.no_kill: + return if (self.settings.os == "Windows"): taskkill_exe = os.path.join(os.environ.get('SystemRoot'), 'system32', 'taskkill.exe') @@ -98,7 +102,7 @@ def _kill_pacman(self): out = subprocess.PIPE err = subprocess.STDOUT else: - out = open(os.devnull, 'w') + out = open(os.devnull, 'w', encoding='UTF-8') err = subprocess.PIPE if os.path.exists(taskkill_exe): @@ -114,16 +118,14 @@ def _kill_pacman(self): proc.wait() except OSError as e: if e.errno == errno.ENOENT: - raise ConanException("Cannot kill pacman") + raise ConanException("Cannot kill pacman") from e @property def _msys_dir(self): - subdir = "msys64" - return os.path.join(self.package_folder, "bin", subdir) + subdir = "msys64" # top-level directoy in tarball + return os.path.join(self.source_folder, subdir) def build(self): - get(self, **self.conan_data["sources"][self.version], - destination=os.path.join(self.package_folder, "bin")) with lock(): self._do_build() @@ -150,7 +152,7 @@ def _do_build(self): if not os.path.isdir(tmp_dir): os.makedirs(tmp_dir) tmp_name = os.path.join(tmp_dir, 'dummy') - with open(tmp_name, 'a'): + with open(tmp_name, 'a', encoding='UTF-8'): os.utime(tmp_name, None) # Prepend the PKG_CONFIG_PATH environment variable with an eventual PKG_CONFIG_PATH environment variable @@ -161,13 +163,14 @@ def package(self): excludes = None if self.options.exclude_files: excludes = tuple(str(self.options.exclude_files).split(",")) - #self.copy("*", dst="bin", src=self._msys_dir, excludes=excludes) for exclude in excludes: for root, _, filenames in os.walk(self._msys_dir): for filename in filenames: fullname = os.path.join(root, filename) if fnmatch.fnmatch(fullname, exclude): os.unlink(fullname) + # See https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#kb-h013-default-package-layout + copy(self, "*", dst=os.path.join(self.package_folder, "bin", "msys64"), src=self._msys_dir, excludes=excludes) shutil.copytree(os.path.join(self._msys_dir, "usr", "share", "licenses"), os.path.join(self.package_folder, "licenses")) @@ -176,7 +179,7 @@ def package_info(self): self.cpp_info.includedirs = [] self.cpp_info.resdirs = [] - msys_root = self._msys_dir + msys_root = os.path.join(self.package_folder, "bin", "msys64") msys_bin = os.path.join(msys_root, "usr", "bin") self.cpp_info.bindirs.append(msys_bin)