Skip to content

Commit

Permalink
Use the more robust is_msvc check
Browse files Browse the repository at this point in the history
Contributes to CURA-11544
  • Loading branch information
jellespijker committed Jan 15, 2024
1 parent 73e0a37 commit ed4514e
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions recipes/cpython/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from conans import AutoToolsBuildEnvironment, ConanFile, MSBuild, tools
from conans.errors import ConanInvalidConfiguration
from conan.tools.microsoft import is_msvc

from io import StringIO
import os
import re
Expand Down Expand Up @@ -80,11 +82,11 @@ def _version_tuple(self):

@property
def _supports_modules(self):
return self.settings.compiler != "Visual Studio" or self.options.shared
return is_msvc(self) or self.options.shared

@property
def _version_suffix(self):
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
joiner = ""
else:
joiner = "."
Expand All @@ -101,7 +103,7 @@ def _is_py2(self):
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
del self.options.lto
del self.options.docstrings
del self.options.pymalloc
Expand Down Expand Up @@ -129,15 +131,15 @@ def configure(self):

del self.options.with_bsddb
del self.options.with_lzma
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
# The msbuild generator only works with Visual Studio
self.generators.append("MSBuildDeps")

def validate(self):
if self.options.shared:
if self.settings.compiler == "Visual Studio" and "MT" in self.settings.compiler.runtime:
if is_msvc(self) and "MT" in self.settings.compiler.runtime:
raise ConanInvalidConfiguration("cpython does not support MT(d) runtime when building a shared cpython library")
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
if self.options.optimizations:
raise ConanInvalidConfiguration("This recipe does not support optimized MSVC cpython builds (yet)")
# FIXME: should probably throw when cross building
Expand Down Expand Up @@ -170,7 +172,7 @@ def source(self):
def _with_libffi(self):
# cpython 3.7.x on MSVC uses an ancient libffi 2.00-beta (which is not available at cci, and is API/ABI incompatible with current 3.2+)
return self._supports_modules \
and (self.settings.compiler != "Visual Studio" or tools.Version(self._version_number_only) >= "3.8")
and (not is_msvc(self) or tools.Version(self._version_number_only) >= "3.8")

def requirements(self):
self.requires("zlib/1.2.11")
Expand Down Expand Up @@ -268,7 +270,7 @@ def _patch_sources(self):
if self._is_py3 and tools.Version(self._version_number_only) < "3.10":
tools.replace_in_file(os.path.join(self._source_subfolder, "setup.py"),
":libmpdec.so.2", "mpdec")
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
runtime_library = {
"MT": "MultiThreaded",
"MTd": "MultiThreadedDebug",
Expand Down Expand Up @@ -417,11 +419,11 @@ def build(self):
raise ConanInvalidConfiguration("cpython 3.9.0 (and newer) requires (at least) mpdecimal 2.5.0")

if self._with_libffi:
if tools.Version(self.deps_cpp_info["libffi"].version) >= "3.3" and self.settings.compiler == "Visual Studio" and "d" in str(self.settings.compiler.runtime):
if tools.Version(self.deps_cpp_info["libffi"].version) >= "3.3" and is_msvc(self) and "d" in str(self.settings.compiler.runtime):
raise ConanInvalidConfiguration("libffi versions >= 3.3 cause 'read access violations' when using a debug runtime (MTd/MDd)")

self._patch_sources()
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
self._msvc_build()
else:
autotools = self._configure_autotools()
Expand All @@ -446,7 +448,7 @@ def _msvc_install_subprefix(self):
return "bin"

def _copy_essential_dlls(self):
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
# Until MSVC builds support cross building, copy dll's of essential (shared) dependencies to python binary location.
# These dll's are required when running the layout tool using the newly built python executable.
dest_path = os.path.join(self.build_folder, self._msvc_artifacts_path)
Expand Down Expand Up @@ -527,7 +529,7 @@ def _msvc_package_copy(self):

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
if self._is_py2 or not self.options.shared:
self._msvc_package_copy()
else:
Expand Down Expand Up @@ -578,12 +580,12 @@ def _cpython_symlink(self):

@property
def _cpython_interpreter_name(self):
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
suffix = ""
else:
suffix = self._version_suffix
python = "python{}".format(suffix)
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
if self.settings.build_type == "Debug":
python += "_d"
if self.settings.os == "Windows":
Expand All @@ -607,7 +609,7 @@ def _abi_suffix(self):

@property
def _lib_name(self):
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
if self.settings.build_type == "Debug":
lib_ext = "_d"
else:
Expand Down Expand Up @@ -637,7 +639,7 @@ def package_info(self):

py_version = tools.Version(self._version_number_only)
# python component: "Build a C extension for Python"
if self.settings.compiler == "Visual Studio":
if is_msvc(self):
self.cpp_info.components["python"].includedirs = [os.path.join(self._msvc_install_subprefix, "include")]
libdir = os.path.join(self._msvc_install_subprefix, "libs")
else:
Expand Down Expand Up @@ -712,7 +714,7 @@ def package_info(self):
self.output.info("Setting PYTHON environment variable: {}".format(python))
self.env_info.PYTHON = python

if self.settings.compiler == "Visual Studio":
if is_msvc(self):
pythonhome = os.path.join(self.package_folder, "bin")
elif tools.is_apple_os(self.settings.os):
pythonhome = self.package_folder
Expand All @@ -721,10 +723,10 @@ def package_info(self):
pythonhome = os.path.join(self.package_folder, "lib", "python{}.{}".format(version.major, version.minor))
self.user_info.pythonhome = pythonhome

pythonhome_required = self.settings.compiler == "Visual Studio" or tools.is_apple_os(self.settings.os)
pythonhome_required = is_msvc(self) or tools.is_apple_os(self.settings.os)
self.user_info.module_requires_pythonhome = pythonhome_required

if self.settings.compiler == "Visual Studio":
if is_msvc(self):
if self.options.env_vars:
self.output.info("Setting PYTHONHOME environment variable: {}".format(pythonhome))
self.env_info.PYTHONHOME = pythonhome
Expand Down

0 comments on commit ed4514e

Please sign in to comment.