Skip to content

Commit

Permalink
(#7862) boost: change Boost.Math cppstd error message on Macos
Browse files Browse the repository at this point in the history
* boost: rewrite Boost.Math cppstd error message + double quotes

* Update conanfile.py

* Update conanfile.py

* Update recipes/boost/all/conanfile.py
  • Loading branch information
madebr authored Nov 7, 2021
1 parent 7dfdac5 commit cd6528d
Showing 1 changed file with 92 additions and 87 deletions.
179 changes: 92 additions & 87 deletions recipes/boost/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from conans import ConanFile
from conans import tools
from conans.tools import Version, cppstd_flag
from conans.errors import ConanException
from conans.errors import ConanException, ConanInvalidConfiguration

from conans.errors import ConanInvalidConfiguration
import glob
import os
import re
Expand Down Expand Up @@ -64,7 +63,7 @@ class BoostConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.boost.org"
license = "BSL-1.0"
topics = ("conan", "boost", "libraries", "cpp")
topics = ("libraries", "cpp")

_options = None

Expand Down Expand Up @@ -239,7 +238,7 @@ def _python_executable(self):
:return: path to the python interpreter executable, either set by option, or system default
"""
exe = self.options.python_executable if self.options.python_executable else sys.executable
return str(exe).replace('\\', '/')
return str(exe).replace("\\", "/")

@property
def _is_windows_platform(self):
Expand Down Expand Up @@ -387,9 +386,9 @@ def validate(self):
# Look also on the comments of the answer for more details
# * Although the 'context' and 'atomic' library does not mention anything about threading,
# when being build the compiler uses the -pthread flag, which makes it quite dangerous
for lib in ['locale', 'coroutine', 'wave', 'type_erasure', 'fiber', 'thread', 'context', 'atomic']:
if not self.options.get_safe('without_%s' % lib):
raise ConanInvalidConfiguration("Boost '%s' library requires multi threading" % lib)
for lib in ["locale", "coroutine", "wave", "type_erasure", "fiber", "thread", "context", "atomic"]:
if not self.options.get_safe("without_{}".format(lib)):
raise ConanInvalidConfiguration("Boost '{}' library requires multi threading".format(lib))

if self.settings.compiler == "Visual Studio" and self._shared:
if "MT" in str(self.settings.compiler.runtime):
Expand Down Expand Up @@ -434,15 +433,15 @@ def validate(self):
"This might cause some boost libraries not being built and conan components to fail.")

if tools.Version(self.version) >= "1.76.0":
# Starting from 1.76.0, Boost.Math requires a c++11 capable compiler
# Starting from 1.76.0, Boost.Math requires a compiler with c++ standard 11 or higher
if not self.options.without_math:
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
else:
min_compiler_version = self._min_compiler_version_default_cxx11
if min_compiler_version is not None:
if tools.Version(self.settings.compiler.version) < min_compiler_version:
raise ConanInvalidConfiguration("Boost.Math requires a C++11 capable compiler")
raise ConanInvalidConfiguration("Boost.Math requires (boost:)cppstd>=11 (current one is lower)")

def build_requirements(self):
if not self.options.header_only:
Expand Down Expand Up @@ -533,8 +532,8 @@ def _run_python_script(self, script):
:return: output of the python script execution, or None, if script has failed
"""
output = StringIO()
command = '"%s" -c "%s"' % (self._python_executable, script)
self.output.info('running %s' % command)
command = '"{}" -c "{}"'.format(self._python_executable, script)
self.output.info("running {}".format(command))
try:
self.run(command=command, output=output)
except ConanException:
Expand All @@ -557,7 +556,7 @@ def _get_python_path(self, name):
# https://docs.python.org/2.7/library/sysconfig.html
return self._run_python_script("from __future__ import print_function; "
"import sysconfig; "
"print(sysconfig.get_path('%s'))" % name)
"print(sysconfig.get_path('{}'))".format(name))

def _get_python_sc_var(self, name):
"""
Expand All @@ -567,7 +566,7 @@ def _get_python_sc_var(self, name):
"""
return self._run_python_script("from __future__ import print_function; "
"import sysconfig; "
"print(sysconfig.get_config_var('%s'))" % name)
"print(sysconfig.get_config_var('{}'))".format(name))

def _get_python_du_var(self, name):
"""
Expand All @@ -578,7 +577,7 @@ def _get_python_du_var(self, name):
"""
return self._run_python_script("from __future__ import print_function; "
"import distutils.sysconfig as du_sysconfig; "
"print(du_sysconfig.get_config_var('%s'))" % name)
"print(du_sysconfig.get_config_var('{}'))".format(name))

def _get_python_var(self, name):
"""
Expand All @@ -595,7 +594,7 @@ def _detect_python_version(self):
"""
return self._run_python_script("from __future__ import print_function; "
"import sys; "
"print('%s.%s' % (sys.version_info[0], sys.version_info[1]))")
"print('{}.{}'.format(sys.version_info[0], sys.version_info[1]))")


@property
Expand Down Expand Up @@ -632,10 +631,10 @@ def _python_includes(self):
attempt to find directory containing Python.h header file
:return: the directory with python includes
"""
include = self._get_python_path('include')
plat_include = self._get_python_path('platinclude')
include_py = self._get_python_var('INCLUDEPY')
include_dir = self._get_python_var('INCLUDEDIR')
include = self._get_python_path("include")
plat_include = self._get_python_path("platinclude")
include_py = self._get_python_var("INCLUDEPY")
include_dir = self._get_python_var("INCLUDEDIR")
python_inc = self._python_inc

candidates = [include,
Expand All @@ -646,10 +645,10 @@ def _python_includes(self):
for candidate in candidates:
if candidate:
python_h = os.path.join(candidate, 'Python.h')
self.output.info('checking %s' % python_h)
self.output.info("checking {}".format(python_h))
if os.path.isfile(python_h):
self.output.info('found Python.h: %s' % python_h)
return candidate.replace('\\', '/')
self.output.info("found Python.h: {}".format(python_h))
return candidate.replace("\\", "/")
raise Exception("couldn't locate Python.h - make sure you have installed python development files")

@property
Expand Down Expand Up @@ -692,25 +691,27 @@ def _python_libraries(self):
for candidate in candidates:
if candidate:
python_lib = os.path.join(libdir, candidate)
self.output.info('checking %s' % python_lib)
self.output.info("checking {}".format(python_lib))
if os.path.isfile(python_lib):
self.output.info('found python library: %s' % python_lib)
return python_lib.replace('\\', '/')
self.output.info("found python library: {}".format(python_lib))
return python_lib.replace("\\", "/")
raise ConanInvalidConfiguration("couldn't locate python libraries - make sure you have installed python development files")

def _clean(self):
src = os.path.join(self.source_folder, self._source_subfolder)
clean_dirs = [os.path.join(self.build_folder, "bin.v2"),
os.path.join(self.build_folder, "architecture"),
os.path.join(self.source_folder, self._bcp_dir),
os.path.join(src, "dist", "bin"),
os.path.join(src, "stage"),
os.path.join(src, "tools", "build", "src", "engine", "bootstrap"),
os.path.join(src, "tools", "build", "src", "engine", "bin.ntx86"),
os.path.join(src, "tools", "build", "src", "engine", "bin.ntx86_64")]
clean_dirs = [
os.path.join(self.build_folder, "bin.v2"),
os.path.join(self.build_folder, "architecture"),
os.path.join(self.source_folder, self._bcp_dir),
os.path.join(src, "dist", "bin"),
os.path.join(src, "stage"),
os.path.join(src, "tools", "build", "src", "engine", "bootstrap"),
os.path.join(src, "tools", "build", "src", "engine", "bin.ntx86"),
os.path.join(src, "tools", "build", "src", "engine", "bin.ntx86_64"),
]
for d in clean_dirs:
if os.path.isdir(d):
self.output.warn('removing "%s"' % d)
self.output.warn("removing '%s'".format(d))
shutil.rmtree(d)

@property
Expand All @@ -735,7 +736,7 @@ def _boost_build_dir(self):
return os.path.join(self.source_folder, self._source_subfolder, "tools", "build")

def _build_bcp(self):
folder = os.path.join(self.source_folder, self._source_subfolder, 'tools', 'bcp')
folder = os.path.join(self.source_folder, self._source_subfolder, "tools", "bcp")
with tools.vcvars(self.settings) if self._is_msvc else tools.no_op():
with tools.chdir(folder):
command = "%s -j%s --abbreviate-paths toolset=%s" % (self._b2_exe, tools.cpu_count(), self._toolset)
Expand All @@ -757,7 +758,7 @@ def _run_bcp(self):
for d in os.listdir(os.path.join(self._source_subfolder, "libs")):
if os.path.isdir(os.path.join(self._source_subfolder, "libs", d)):
libraries.add(d)
libraries = ' '.join(libraries)
libraries = " ".join(libraries)
command = "{bcp} {namespace} {alias} " \
"{boostdir} {libraries} {outdir}".format(bcp=self._bcp_exe,
namespace=namespace,
Expand Down Expand Up @@ -829,16 +830,18 @@ def build(self):

@property
def _b2_os(self):
return {"Windows": "windows",
"WindowsStore": "windows",
"Linux": "linux",
"Android": "android",
"Macos": "darwin",
"iOS": "iphone",
"watchOS": "iphone",
"tvOS": "appletv",
"FreeBSD": "freebsd",
"SunOS": "solaris"}.get(str(self.settings.os))
return {
"Windows": "windows",
"WindowsStore": "windows",
"Linux": "linux",
"Android": "android",
"Macos": "darwin",
"iOS": "iphone",
"watchOS": "iphone",
"tvOS": "appletv",
"FreeBSD": "freebsd",
"SunOS": "solaris",
}.get(str(self.settings.os))

@property
def _b2_address_model(self):
Expand All @@ -849,43 +852,45 @@ def _b2_address_model(self):

@property
def _b2_binary_format(self):
return {"Windows": "pe",
"WindowsStore": "pe",
"Linux": "elf",
"Android": "elf",
"Macos": "mach-o",
"iOS": "mach-o",
"watchOS": "mach-o",
"tvOS": "mach-o",
"FreeBSD": "elf",
"SunOS": "elf"}.get(str(self.settings.os))
return {
"Windows": "pe",
"WindowsStore": "pe",
"Linux": "elf",
"Android": "elf",
"Macos": "mach-o",
"iOS": "mach-o",
"watchOS": "mach-o",
"tvOS": "mach-o",
"FreeBSD": "elf",
"SunOS": "elf",
}.get(str(self.settings.os))

@property
def _b2_architecture(self):
if str(self.settings.arch).startswith('x86'):
return 'x86'
elif str(self.settings.arch).startswith('ppc'):
return 'power'
elif str(self.settings.arch).startswith('arm'):
return 'arm'
elif str(self.settings.arch).startswith('sparc'):
return 'sparc'
elif str(self.settings.arch).startswith('mips64'):
return 'mips64'
elif str(self.settings.arch).startswith('mips'):
return 'mips1'
if str(self.settings.arch).startswith("x86"):
return "x86"
elif str(self.settings.arch).startswith("ppc"):
return "power"
elif str(self.settings.arch).startswith("arm"):
return "arm"
elif str(self.settings.arch).startswith("sparc"):
return "sparc"
elif str(self.settings.arch).startswith("mips64"):
return "mips64"
elif str(self.settings.arch).startswith("mips"):
return "mips1"
else:
return None

@property
def _b2_abi(self):
if str(self.settings.arch).startswith('x86'):
if str(self.settings.arch).startswith("x86"):
return "ms" if str(self.settings.os) in ["Windows", "WindowsStore"] else "sysv"
elif str(self.settings.arch).startswith('ppc'):
elif str(self.settings.arch).startswith("ppc"):
return "sysv"
elif str(self.settings.arch).startswith('arm'):
elif str(self.settings.arch).startswith("arm"):
return "aapcs"
elif str(self.settings.arch).startswith('mips'):
elif str(self.settings.arch).startswith("mips"):
return "o32"
else:
return None
Expand Down Expand Up @@ -928,7 +933,7 @@ def _build_flags(self):
flags.append("abi=%s" % self._b2_abi)

flags.append("--layout=%s" % self.options.layout)
flags.append("--user-config=%s" % os.path.join(self._boost_build_dir, 'user-config.jam'))
flags.append("--user-config=%s" % os.path.join(self._boost_build_dir, "user-config.jam"))
flags.append("-sNO_ZLIB=%s" % ("0" if self._with_zlib else "1"))
flags.append("-sNO_BZIP2=%s" % ("0" if self._with_bzip2 else "1"))
flags.append("-sNO_LZMA=%s" % ("0" if self._with_lzma else "1"))
Expand Down Expand Up @@ -1090,12 +1095,12 @@ def _build_cross_flags(self):
flags = []
if not tools.cross_building(self):
return flags
arch = self.settings.get_safe('arch')
arch = self.settings.get_safe("arch")
self.output.info("Cross building, detecting compiler...")

if arch.startswith('arm'):
if 'hf' in arch:
flags.append('-mfloat-abi=hard')
if arch.startswith("arm"):
if "hf" in arch:
flags.append("-mfloat-abi=hard")
elif self.settings.os == "Emscripten":
pass
elif arch in ["x86", "x86_64"]:
Expand Down Expand Up @@ -1147,8 +1152,8 @@ def _create_user_config_jam(self, folder):
contents = ""
if self._zip_bzip2_requires_needed:
def create_library_config(deps_name, name):
includedir = '"%s"' % self.deps_cpp_info[deps_name].include_paths[0].replace('\\', '/')
libdir = '"%s"' % self.deps_cpp_info[deps_name].lib_paths[0].replace('\\', '/')
includedir = '"%s"' % self.deps_cpp_info[deps_name].include_paths[0].replace("\\", "/")
libdir = '"%s"' % self.deps_cpp_info[deps_name].lib_paths[0].replace("\\", "/")
lib = self.deps_cpp_info[deps_name].libs[0]
version = self.deps_cpp_info[deps_name].version
return "\nusing {name} : {version} : " \
Expand Down Expand Up @@ -1180,15 +1185,15 @@ def create_library_config(deps_name, name):

if not self.options.without_mpi:
# https://www.boost.org/doc/libs/1_72_0/doc/html/mpi/getting_started.html
contents += '\nusing mpi ;'
contents += "\nusing mpi ;"

# Specify here the toolset with the binary if present if don't empty parameter :
contents += '\nusing "%s" : %s : ' % (self._toolset, self._toolset_version)

if self._is_msvc:
contents += ' "%s"' % self._cxx.replace("\\", "/")
contents += ' "{}"'.format(self._cxx.replace("\\", "/"))
else:
contents += ' %s' % self._cxx.replace("\\", "/")
contents += " {}".format(self._cxx.replace("\\", "/"))

if tools.is_apple_os(self.settings.os):
if self.settings.compiler == "apple-clang":
Expand Down Expand Up @@ -1232,7 +1237,7 @@ def create_library_config(deps_name, name):
def _toolset_version(self):
if self._is_msvc:
toolset = tools.msvs_toolset(self)
match = re.match(r'v(\d+)(\d)$', toolset)
match = re.match(r"v(\d+)(\d)$", toolset)
if match:
return "%s.%s" % (match.group(1), match.group(2))
return ""
Expand Down Expand Up @@ -1491,12 +1496,12 @@ def filter_transform_module_libraries(names):
continue
new_name = add_libprefix(name.format(**libformatdata)) + libsuffix
if self.options.namespace != 'boost':
new_name = new_name.replace('boost_', str(self.options.namespace) + '_')
if name.startswith('boost_python') or name.startswith('boost_numpy'):
new_name = new_name.replace("boost_", str(self.options.namespace) + "_")
if name.startswith("boost_python") or name.startswith("boost_numpy"):
if self.options.python_buildid:
new_name += '-%s' % self.options.python_buildid
new_name += "-{}".format(self.options.python_buildid)
if self.options.buildid:
new_name += '-%s' % self.options.buildid
new_name += "-{}".format(self.options.buildid)
libs.append(new_name)
return libs

Expand Down

0 comments on commit cd6528d

Please sign in to comment.