Skip to content

Commit

Permalink
(conan-io#14686) msys2: Conan 2.0 compatibility tweaks
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and StellaSmith committed Feb 2, 2023
1 parent a95baa1 commit fb3f51b
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions recipes/msys2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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")):
Expand All @@ -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')

Expand All @@ -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):
Expand All @@ -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()

Expand All @@ -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
Expand All @@ -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"))

Expand All @@ -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)

Expand Down

0 comments on commit fb3f51b

Please sign in to comment.