diff options
author | Gagandeep Singh <gdp.1807@gmail.com> | 2021-11-02 11:28:17 +0530 |
---|---|---|
committer | Gagandeep Singh <gdp.1807@gmail.com> | 2021-11-02 11:28:17 +0530 |
commit | c04509e86e97a69a0b5fcbeebdbec66faad3dbe0 (patch) | |
tree | b5940db3ad46e55b88d566ec058007dc3c6b7e72 /numpy/distutils | |
parent | 56647dd47345a7fd24b4ee8d9d52025fcdc3b9ae (diff) | |
parent | fae6fa47a3cf9b9c64af2f5bd11a3b644b1763d2 (diff) | |
download | numpy-c04509e86e97a69a0b5fcbeebdbec66faad3dbe0.tar.gz |
resolved conflicts
Diffstat (limited to 'numpy/distutils')
-rw-r--r-- | numpy/distutils/ccompiler.py | 10 | ||||
-rw-r--r-- | numpy/distutils/ccompiler_opt.py | 33 | ||||
-rw-r--r-- | numpy/distutils/command/build_clib.py | 79 | ||||
-rw-r--r-- | numpy/distutils/command/build_ext.py | 59 | ||||
-rw-r--r-- | numpy/distutils/core.py | 2 | ||||
-rw-r--r-- | numpy/distutils/extension.py | 4 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/__init__.py | 3 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/gnu.py | 3 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/nag.py | 5 | ||||
-rw-r--r-- | numpy/distutils/mingw32ccompiler.py | 24 | ||||
-rw-r--r-- | numpy/distutils/misc_util.py | 19 | ||||
-rw-r--r-- | numpy/distutils/system_info.py | 12 | ||||
-rw-r--r-- | numpy/distutils/tests/test_ccompiler_opt.py | 6 | ||||
-rw-r--r-- | numpy/distutils/tests/test_system_info.py | 4 |
14 files changed, 174 insertions, 89 deletions
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py index 6d063ee4e..9c85d28b9 100644 --- a/numpy/distutils/ccompiler.py +++ b/numpy/distutils/ccompiler.py @@ -23,7 +23,8 @@ from numpy.distutils.exec_command import ( ) from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \ get_num_build_jobs, \ - _commandline_dep_string + _commandline_dep_string, \ + sanitize_cxx_flags # globals for parallel build management import threading @@ -258,9 +259,6 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None, If compilation fails. """ - # This method is effective only with Python >=2.3 distutils. - # Any changes here should be applied also to fcompiler.compile - # method to support pre Python 2.3 distutils. global _job_semaphore jobs = get_num_build_jobs() @@ -677,7 +675,9 @@ def CCompiler_cxx_compiler(self): return self cxx = copy(self) - cxx.compiler_so = [cxx.compiler_cxx[0]] + cxx.compiler_so[1:] + cxx.compiler_cxx = cxx.compiler_cxx + cxx.compiler_so = [cxx.compiler_cxx[0]] + \ + sanitize_cxx_flags(cxx.compiler_so[1:]) if sys.platform.startswith('aix') and 'ld_so_aix' in cxx.linker_so[0]: # AIX needs the ld_so_aix script included with Python cxx.linker_so = [cxx.linker_so[0], cxx.compiler_cxx[0]] \ diff --git a/numpy/distutils/ccompiler_opt.py b/numpy/distutils/ccompiler_opt.py index e7fd494d3..d7df386fe 100644 --- a/numpy/distutils/ccompiler_opt.py +++ b/numpy/distutils/ccompiler_opt.py @@ -8,7 +8,14 @@ the sources with proper compiler's flags. instead only focuses on the compiler side, but it creates abstract C headers that can be used later for the final runtime dispatching process.""" -import sys, io, os, re, textwrap, pprint, inspect, atexit, subprocess +import atexit +import inspect +import os +import pprint +import re +import subprocess +import textwrap + class _Config: """An abstract class holds all configurable attributes of `CCompilerOpt`, @@ -188,7 +195,8 @@ class _Config: # native usually works only with x86 native = '-march=native', opt = '-O3', - werror = '-Werror' + werror = '-Werror', + cxx = '-std=c++11', ), clang = dict( native = '-march=native', @@ -198,22 +206,26 @@ class _Config: # cases `-Werror` gets skipped during the availability test due to # "unused arguments" warnings. # see https://github.com/numpy/numpy/issues/19624 - werror = '-Werror-implicit-function-declaration -Werror' + werror = '-Werror=switch -Werror', + cxx = '-std=c++11', ), icc = dict( native = '-xHost', opt = '-O3', - werror = '-Werror' + werror = '-Werror', + cxx = '-std=c++11', ), iccw = dict( native = '/QxHost', opt = '/O3', - werror = '/Werror' + werror = '/Werror', + cxx = '-std=c++11', ), msvc = dict( native = None, opt = '/O2', - werror = '/WX' + werror = '/WX', + cxx = '-std=c++11', ) ) conf_min_features = dict( @@ -406,8 +418,8 @@ class _Config: AVX512_ICL = dict(flags="/Qx:ICELAKE-CLIENT") ) if on_x86 and self.cc_is_msvc: return dict( - SSE = dict(flags="/arch:SSE"), - SSE2 = dict(flags="/arch:SSE2"), + SSE = dict(flags="/arch:SSE") if self.cc_on_x86 else {}, + SSE2 = dict(flags="/arch:SSE2") if self.cc_on_x86 else {}, SSE3 = {}, SSSE3 = {}, SSE41 = {}, @@ -516,7 +528,8 @@ class _Config: def __init__(self): if self.conf_tmp_path is None: - import tempfile, shutil + import shutil + import tempfile tmp = tempfile.mkdtemp() def rm_temp(): try: @@ -555,6 +568,7 @@ class _Distutils: flags = kwargs.pop("extra_postargs", []) + flags if not ccompiler: ccompiler = self._ccompiler + return ccompiler.compile(sources, extra_postargs=flags, **kwargs) def dist_test(self, source, flags, macros=[]): @@ -696,7 +710,6 @@ class _Distutils: ) @staticmethod def _dist_test_spawn(cmd, display=None): - from distutils.errors import CompileError try: o = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True) diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py index 0e31a7dee..45201f98f 100644 --- a/numpy/distutils/command/build_clib.py +++ b/numpy/distutils/command/build_clib.py @@ -185,6 +185,30 @@ class build_clib(old_build_clib): for (lib_name, build_info) in libraries: self.build_a_library(build_info, lib_name, libraries) + def assemble_flags(self, in_flags): + """ Assemble flags from flag list + + Parameters + ---------- + in_flags : None or sequence + None corresponds to empty list. Sequence elements can be strings + or callables that return lists of strings. Callable takes `self` as + single parameter. + + Returns + ------- + out_flags : list + """ + if in_flags is None: + return [] + out_flags = [] + for in_flag in in_flags: + if callable(in_flag): + out_flags += in_flag(self) + else: + out_flags.append(in_flag) + return out_flags + def build_a_library(self, build_info, lib_name, libraries): # default compilers compiler = self.compiler @@ -263,7 +287,13 @@ class build_clib(old_build_clib): include_dirs = build_info.get('include_dirs') if include_dirs is None: include_dirs = [] - extra_postargs = build_info.get('extra_compiler_args') or [] + # Flags can be strings, or callables that return a list of strings. + extra_postargs = self.assemble_flags( + build_info.get('extra_compiler_args')) + extra_cflags = self.assemble_flags( + build_info.get('extra_cflags')) + extra_cxxflags = self.assemble_flags( + build_info.get('extra_cxxflags')) include_dirs.extend(get_numpy_include_dirs()) # where compiled F90 module files are: @@ -315,38 +345,45 @@ class build_clib(old_build_clib): macros=macros + copt_macros, include_dirs=include_dirs, debug=self.debug, - extra_postargs=extra_postargs, + extra_postargs=extra_postargs + extra_cxxflags, ccompiler=cxx_compiler ) if copt_c_sources: log.info("compiling C dispatch-able sources") - objects += self.compiler_opt.try_dispatch(copt_c_sources, - output_dir=self.build_temp, - src_dir=copt_build_src, - macros=macros + copt_macros, - include_dirs=include_dirs, - debug=self.debug, - extra_postargs=extra_postargs) + objects += self.compiler_opt.try_dispatch( + copt_c_sources, + output_dir=self.build_temp, + src_dir=copt_build_src, + macros=macros + copt_macros, + include_dirs=include_dirs, + debug=self.debug, + extra_postargs=extra_postargs + extra_cflags) if c_sources: log.info("compiling C sources") - objects += compiler.compile(c_sources, - output_dir=self.build_temp, - macros=macros + copt_macros, - include_dirs=include_dirs, - debug=self.debug, - extra_postargs=extra_postargs + copt_baseline_flags) + objects += compiler.compile( + c_sources, + output_dir=self.build_temp, + macros=macros + copt_macros, + include_dirs=include_dirs, + debug=self.debug, + extra_postargs=(extra_postargs + + copt_baseline_flags + + extra_cflags)) if cxx_sources: log.info("compiling C++ sources") cxx_compiler = compiler.cxx_compiler() - cxx_objects = cxx_compiler.compile(cxx_sources, - output_dir=self.build_temp, - macros=macros + copt_macros, - include_dirs=include_dirs, - debug=self.debug, - extra_postargs=extra_postargs + copt_baseline_flags) + cxx_objects = cxx_compiler.compile( + cxx_sources, + output_dir=self.build_temp, + macros=macros + copt_macros, + include_dirs=include_dirs, + debug=self.debug, + extra_postargs=(extra_postargs + + copt_baseline_flags + + extra_cxxflags)) objects.extend(cxx_objects) if f_sources or fmodule_sources: diff --git a/numpy/distutils/command/build_ext.py b/numpy/distutils/command/build_ext.py index 84ec8aa2c..7040a2411 100644 --- a/numpy/distutils/command/build_ext.py +++ b/numpy/distutils/command/build_ext.py @@ -243,7 +243,8 @@ class build_ext (old_build_ext): if l and l != ext_language and ext.language: log.warn('resetting extension %r language from %r to %r.' % (ext.name, l, ext_language)) - ext.language = ext_language + if not ext.language: + ext.language = ext_language # global language all_languages.update(ext_languages) @@ -376,6 +377,9 @@ class build_ext (old_build_ext): log.info("building '%s' extension", ext.name) extra_args = ext.extra_compile_args or [] + extra_cflags = ext.extra_c_compile_args or [] + extra_cxxflags = ext.extra_cxx_compile_args or [] + macros = ext.define_macros[:] for undef in ext.undef_macros: macros.append((undef,)) @@ -462,38 +466,43 @@ class build_ext (old_build_ext): macros=macros + copt_macros, include_dirs=include_dirs, debug=self.debug, - extra_postargs=extra_args, + extra_postargs=extra_args + extra_cxxflags, ccompiler=cxx_compiler, **kws ) if copt_c_sources: log.info("compiling C dispatch-able sources") - c_objects += self.compiler_opt.try_dispatch(copt_c_sources, - output_dir=output_dir, - src_dir=copt_build_src, - macros=macros + copt_macros, - include_dirs=include_dirs, - debug=self.debug, - extra_postargs=extra_args, - **kws) + c_objects += self.compiler_opt.try_dispatch( + copt_c_sources, + output_dir=output_dir, + src_dir=copt_build_src, + macros=macros + copt_macros, + include_dirs=include_dirs, + debug=self.debug, + extra_postargs=extra_args + extra_cflags, + **kws) if c_sources: log.info("compiling C sources") - c_objects += self.compiler.compile(c_sources, - output_dir=output_dir, - macros=macros + copt_macros, - include_dirs=include_dirs, - debug=self.debug, - extra_postargs=extra_args + copt_baseline_flags, - **kws) + c_objects += self.compiler.compile( + c_sources, + output_dir=output_dir, + macros=macros + copt_macros, + include_dirs=include_dirs, + debug=self.debug, + extra_postargs=(extra_args + copt_baseline_flags + + extra_cflags), + **kws) if cxx_sources: log.info("compiling C++ sources") - c_objects += cxx_compiler.compile(cxx_sources, - output_dir=output_dir, - macros=macros + copt_macros, - include_dirs=include_dirs, - debug=self.debug, - extra_postargs=extra_args + copt_baseline_flags, - **kws) + c_objects += cxx_compiler.compile( + cxx_sources, + output_dir=output_dir, + macros=macros + copt_macros, + include_dirs=include_dirs, + debug=self.debug, + extra_postargs=(extra_args + copt_baseline_flags + + extra_cxxflags), + **kws) extra_postargs = [] f_objects = [] @@ -602,7 +611,7 @@ class build_ext (old_build_ext): # Expand possible fake static libraries to objects; # make sure to iterate over a copy of the list as # "fake" libraries will be removed as they are - # enountered + # encountered for lib in libraries[:]: for libdir in library_dirs: fake_lib = os.path.join(libdir, lib + '.fobjects') diff --git a/numpy/distutils/core.py b/numpy/distutils/core.py index d5551f349..c4a14e599 100644 --- a/numpy/distutils/core.py +++ b/numpy/distutils/core.py @@ -19,7 +19,7 @@ import warnings import distutils.core import distutils.dist -from numpy.distutils.extension import Extension +from numpy.distutils.extension import Extension # noqa: F401 from numpy.distutils.numpy_distribution import NumpyDistribution from numpy.distutils.command import config, config_compiler, \ build, build_py, build_ext, build_clib, build_src, build_scripts, \ diff --git a/numpy/distutils/extension.py b/numpy/distutils/extension.py index c90b5d725..3ede013e0 100644 --- a/numpy/distutils/extension.py +++ b/numpy/distutils/extension.py @@ -47,6 +47,8 @@ class Extension(old_Extension): language=None, f2py_options=None, module_dirs=None, + extra_c_compile_args=None, + extra_cxx_compile_args=None, extra_f77_compile_args=None, extra_f90_compile_args=None,): @@ -83,6 +85,8 @@ class Extension(old_Extension): # numpy_distutils features self.f2py_options = f2py_options or [] self.module_dirs = module_dirs or [] + self.extra_c_compile_args = extra_c_compile_args or [] + self.extra_cxx_compile_args = extra_cxx_compile_args or [] self.extra_f77_compile_args = extra_f77_compile_args or [] self.extra_f90_compile_args = extra_f90_compile_args or [] diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py index d7579e976..c333517c0 100644 --- a/numpy/distutils/fcompiler/__init__.py +++ b/numpy/distutils/fcompiler/__init__.py @@ -745,7 +745,8 @@ _default_compilers = ( ('cygwin.*', ('gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95')), ('linux.*', ('gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu')), - ('darwin.*', ('gnu95', 'nag', 'absoft', 'ibm', 'intel', 'gnu', 'g95', 'pg')), + ('darwin.*', ('gnu95', 'nag', 'nagfor', 'absoft', 'ibm', 'intel', 'gnu', + 'g95', 'pg')), ('sunos.*', ('sun', 'gnu', 'gnu95', 'g95')), ('irix.*', ('mips', 'gnu', 'gnu95',)), ('aix.*', ('ibm', 'gnu', 'gnu95',)), diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py index 02372f5e6..39178071d 100644 --- a/numpy/distutils/fcompiler/gnu.py +++ b/numpy/distutils/fcompiler/gnu.py @@ -113,7 +113,7 @@ class GnuFCompiler(FCompiler): # If MACOSX_DEPLOYMENT_TARGET is set, we simply trust the value # and leave it alone. But, distutils will complain if the # environment's value is different from the one in the Python - # Makefile used to build Python. We let disutils handle this + # Makefile used to build Python. We let distutils handle this # error checking. if not target: # If MACOSX_DEPLOYMENT_TARGET is not set in the environment, @@ -535,7 +535,6 @@ def _can_target(cmd, arch): os.remove(output) finally: os.remove(filename) - return False if __name__ == '__main__': diff --git a/numpy/distutils/fcompiler/nag.py b/numpy/distutils/fcompiler/nag.py index 7df8ffe2c..939201f44 100644 --- a/numpy/distutils/fcompiler/nag.py +++ b/numpy/distutils/fcompiler/nag.py @@ -64,6 +64,11 @@ class NAGFORCompiler(BaseNAGFCompiler): 'ranlib' : ["ranlib"] } + def get_flags_linker_so(self): + if sys.platform == 'darwin': + return ['-unsharedrts', + '-Wl,-bundle,-flat_namespace,-undefined,suppress'] + return BaseNAGFCompiler.get_flags_linker_so(self) def get_flags_debug(self): version = self.get_version() if version and version > '6.1': diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py index 4681d403b..82d296434 100644 --- a/numpy/distutils/mingw32ccompiler.py +++ b/numpy/distutils/mingw32ccompiler.py @@ -547,12 +547,12 @@ if sys.platform == 'win32': # Value from msvcrt.CRT_ASSEMBLY_VERSION under Python 3.3.0 # on Windows XP: _MSVCRVER_TO_FULLVER['100'] = "10.0.30319.460" - # Python 3.7 uses 1415, but get_build_version returns 140 ?? - _MSVCRVER_TO_FULLVER['140'] = "14.15.26726.0" - if hasattr(msvcrt, "CRT_ASSEMBLY_VERSION"): - major, minor, rest = msvcrt.CRT_ASSEMBLY_VERSION.split(".", 2) - _MSVCRVER_TO_FULLVER[major + minor] = msvcrt.CRT_ASSEMBLY_VERSION - del major, minor, rest + crt_ver = getattr(msvcrt, 'CRT_ASSEMBLY_VERSION', None) + if crt_ver is not None: # Available at least back to Python 3.3 + maj, min = re.match(r'(\d+)\.(\d)', crt_ver).groups() + _MSVCRVER_TO_FULLVER[maj + min] = crt_ver + del maj, min + del crt_ver except ImportError: # If we are here, means python was not built with MSVC. Not sure what # to do in that case: manifest building will fail, but it should not be @@ -647,11 +647,9 @@ def generate_manifest(config): if msver is not None: if msver >= 8: check_embedded_msvcr_match_linked(msver) - ma = int(msver) - mi = int((msver - ma) * 10) + ma_str, mi_str = str(msver).split('.') # Write the manifest file - manxml = msvc_manifest_xml(ma, mi) - man = open(manifest_name(config), "w") - config.temp_files.append(manifest_name(config)) - man.write(manxml) - man.close() + manxml = msvc_manifest_xml(int(ma_str), int(mi_str)) + with open(manifest_name(config), "w") as man: + config.temp_files.append(manifest_name(config)) + man.write(manxml) diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index a903f3ea3..f0f9b4bd7 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -11,6 +11,7 @@ import multiprocessing import textwrap import importlib.util from threading import local as tlocal +from functools import reduce import distutils from distutils.errors import DistutilsError @@ -43,7 +44,7 @@ __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict', 'dot_join', 'get_frame', 'minrelpath', 'njoin', 'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language', 'get_build_architecture', 'get_info', 'get_pkg_info', - 'get_num_build_jobs'] + 'get_num_build_jobs', 'sanitize_cxx_flags'] class InstallableLib: """ @@ -128,8 +129,8 @@ def quote_args(args): def allpath(name): "Convert a /-separated pathname to one using the OS's path separator." - splitted = name.split('/') - return os.path.join(*splitted) + split = name.split('/') + return os.path.join(*split) def rel_path(path, parent_path): """Return path relative to parent_path.""" @@ -2478,3 +2479,15 @@ def get_build_architecture(): # systems, so delay the import to here. from distutils.msvccompiler import get_build_architecture return get_build_architecture() + + +_cxx_ignore_flags = {'-Werror=implicit-function-declaration'} + + +def sanitize_cxx_flags(cxxflags): + ''' + Some flags are valid for C but not C++. Prune them. + ''' + return [flag for flag in cxxflags if flag not in _cxx_ignore_flags] + + diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index 8467e1c19..7f41bb07e 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -387,11 +387,10 @@ def get_standard_file(fname): f = __file__ except NameError: f = sys.argv[0] - else: - sysfile = os.path.join(os.path.split(os.path.abspath(f))[0], - fname) - if os.path.isfile(sysfile): - filenames.append(sysfile) + sysfile = os.path.join(os.path.split(os.path.abspath(f))[0], + fname) + if os.path.isfile(sysfile): + filenames.append(sysfile) # Home directory # And look for the user config file @@ -414,7 +413,8 @@ def get_standard_file(fname): def _parse_env_order(base_order, env): """ Parse an environment variable `env` by splitting with "," and only returning elements from `base_order` - This method will sequence the environment variable and check for their invidual elements in `base_order`. + This method will sequence the environment variable and check for their + individual elements in `base_order`. The items in the environment variable may be negated via '^item' or '!itema,itemb'. It must start with ^/! to negate all options. diff --git a/numpy/distutils/tests/test_ccompiler_opt.py b/numpy/distutils/tests/test_ccompiler_opt.py index 9c54ed66b..1b27ab07c 100644 --- a/numpy/distutils/tests/test_ccompiler_opt.py +++ b/numpy/distutils/tests/test_ccompiler_opt.py @@ -434,7 +434,8 @@ class _Test_CCompilerOpt: self.expect_flags( "sse sse2 vsx vsx2 neon neon_fp16", x86_gcc="-msse -msse2", x86_icc="-msse -msse2", - x86_iccw="/arch:SSE2", x86_msvc="/arch:SSE2", + x86_iccw="/arch:SSE2", + x86_msvc="/arch:SSE2" if self.march() == "x86" else "", ppc64_gcc= "-mcpu=power8", ppc64_clang="-maltivec -mvsx -mpower8-vector", armhf_gcc="-mfpu=neon-fp16 -mfp16-format=ieee", @@ -636,7 +637,8 @@ class _Test_CCompilerOpt: x86_gcc="avx512f avx2 sse42 sse41 sse2", x86_icc="avx512f avx2 sse42 sse41 sse2", x86_iccw="avx512f avx2 sse42 sse41 sse2", - x86_msvc="avx512f avx2 sse2", + x86_msvc="avx512f avx2 sse2" + if self.march() == 'x86' else "avx512f avx2", ppc64="vsx3 vsx2", armhf="asimddp asimd neon_vfpv4 neon", # neon, neon_vfpv4, asimd implies each other diff --git a/numpy/distutils/tests/test_system_info.py b/numpy/distutils/tests/test_system_info.py index b722281ad..8c26271af 100644 --- a/numpy/distutils/tests/test_system_info.py +++ b/numpy/distutils/tests/test_system_info.py @@ -254,6 +254,10 @@ class TestSystemInfoReading: finally: os.chdir(previousDir) + HAS_MKL = "mkl_rt" in mkl_info().calc_libraries_info().get("libraries", []) + + @pytest.mark.xfail(HAS_MKL, reason=("`[DEFAULT]` override doesn't work if " + "numpy is built with MKL support")) def test_overrides(self): previousDir = os.getcwd() cfg = os.path.join(self._dir1, 'site.cfg') |