def build_extensions(self):
# Numpy bug: if an extension has a library only consisting of f77
# files, the extension language will always be f77 and no f90
# compiler will be initialized
need_f90_compiler = self._f90_compiler is None and \
any(any(f90_ext_match(s) for s in _.sources)
for _ in self.extensions)
if need_f90_compiler:
self._f90_compiler = new_fcompiler(compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
requiref90=True,
c_compiler=self.compiler)
fcompiler = self._f90_compiler
if fcompiler:
fcompiler.customize(self.distribution)
if fcompiler and fcompiler.get_version():
fcompiler.customize_cmd(self)
fcompiler.show_customization()
else:
ctype = fcompiler.compiler_type if fcompiler \
else self.fcompiler
self.warn('f90_compiler=%s is not available.' % ctype)
for fc in self._f77_compiler, self._f90_compiler:
if isinstance(fc,
numpy.distutils.fcompiler.gnu.Gnu95FCompiler):
flags = F77_COMPILE_ARGS_GFORTRAN + F77_COMPILE_OPT_GFORTRAN
if self.debug:
flags += F77_COMPILE_DEBUG_GFORTRAN
if F77_OPENMP:
flags += ['-openmp']
fc.executables['compiler_f77'] += flags
flags = F90_COMPILE_ARGS_GFORTRAN + F90_COMPILE_OPT_GFORTRAN
if self.debug:
flags += F90_COMPILE_DEBUG_GFORTRAN
if F90_OPENMP:
flags += ['-openmp']
fc.executables['compiler_f90'] += flags
fc.libraries += [LIBRARY_OPENMP_GFORTRAN]
elif isinstance(fc,
numpy.distutils.fcompiler.intel.IntelFCompiler):
flags = F77_COMPILE_ARGS_IFORT + F77_COMPILE_OPT_IFORT
if self.debug:
flags += F77_COMPILE_DEBUG_IFORT
if F77_OPENMP:
flags += ['-openmp']
fc.executables['compiler_f77'] += flags
flags = F90_COMPILE_ARGS_IFORT + F90_COMPILE_OPT_IFORT
if self.debug:
flags += F90_COMPILE_DEBUG_IFORT
if F90_OPENMP:
flags += ['-openmp']
fc.executables['compiler_f90'] += flags
fc.libraries += [LIBRARY_OPENMP_IFORT]
elif fc is not None:
raise RuntimeError(
"Unhandled compiler: '{}'.".format(fcompiler))
build_ext.build_extensions(self)
def run(self):
if not self.libraries:
return
# Make sure that library sources are complete.
languages = []
# Make sure that extension sources are complete.
self.run_command("build_src")
for (lib_name, build_info) in self.libraries:
l = build_info.get("language", None)
if l and l not in languages:
languages.append(l)
from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler, dry_run=self.dry_run, force=self.force)
self.compiler.customize(self.distribution, need_cxx=self.have_cxx_sources())
libraries = self.libraries
self.libraries = None
self.compiler.customize_cmd(self)
self.libraries = libraries
self.compiler.show_customization()
if self.have_f_sources():
from numpy.distutils.fcompiler import new_fcompiler
self._f_compiler = new_fcompiler(
compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
requiref90="f90" in languages,
c_compiler=self.compiler,
)
if self._f_compiler is not None:
self._f_compiler.customize(self.distribution)
libraries = self.libraries
self.libraries = None
self._f_compiler.customize_cmd(self)
self.libraries = libraries
self._f_compiler.show_customization()
else:
self._f_compiler = None
self.build_libraries(self.libraries)
if self.inplace:
for l in self.distribution.installed_libraries:
libname = self.compiler.library_filename(l.name)
source = os.path.join(self.build_clib, libname)
target = os.path.join(l.target_dir, libname)
self.mkpath(l.target_dir)
shutil.copy(source, target)
def _init_fcompiler(self, compiler_type):
self.fcompiler = new_fcompiler(
compiler=compiler_type, verbose=self.verbose, dry_run=self.dry_run, force=self.force
)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
self.scons_fcompiler = dist2sconsfc(self.fcompiler)
self.scons_fcompiler_path = protect_path(get_f77_tool_path(self.fcompiler))
开发者ID:illume,项目名称:numpy3k,代码行数:9,代码来源:scons.py
示例5: _check_compiler
def _check_compiler(self):
old_config._check_compiler(self)
from numpy.distutils.fcompiler import FCompiler, new_fcompiler
if sys.platform == "win32" and self.compiler.compiler_type == "msvc":
# XXX: hack to circumvent a python 2.6 bug with msvc9compiler:
# initialize call query_vcvarsall, which throws an IOError, and
# causes an error along the way without much information. We try to
# catch it here, hoping it is early enough, and print an helpful
# message instead of Error: None.
if not self.compiler.initialized:
try:
self.compiler.initialize()
except IOError:
e = get_exception()
msg = """\
Could not initialize compiler instance: do you have Visual Studio
installed? If you are trying to build with MinGW, please use "python setup.py
build -c mingw32" instead. If you have Visual Studio installed, check it is
correctly installed, and the right version (VS 2008 for python 2.6, 2.7 and 3.2,
VS 2010 for >= 3.3).
Original exception was: %s, and the Compiler class was %s
============================================================================""" % (
e,
self.compiler.__class__.__name__,
)
print(
"""\
============================================================================"""
)
raise distutils.errors.DistutilsPlatformError(msg)
# After MSVC is initialized, add an explicit /MANIFEST to linker
# flags. See issues gh-4245 and gh-4101 for details. Also
# relevant are issues 4431 and 16296 on the Python bug tracker.
from distutils import msvc9compiler
if msvc9compiler.get_build_version() >= 10:
for ldflags in [self.compiler.ldflags_shared, self.compiler.ldflags_shared_debug]:
if "/MANIFEST" not in ldflags:
ldflags.append("/MANIFEST")
if "/DEBUG" not in ldflags:
ldflags.append("/DEBUG")
if "/pdb:None" in ldflags:
ldflags.remove("/pdb:None")
if not isinstance(self.fcompiler, FCompiler):
self.fcompiler = new_fcompiler(
compiler=self.fcompiler, dry_run=self.dry_run, force=1, c_compiler=self.compiler
)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
if self.fcompiler.get_version():
self.fcompiler.customize_cmd(self)
self.fcompiler.show_customization()
def run(self):
if not self.libraries:
return
# Make sure that library sources are complete.
languages = []
for (lib_name, build_info) in self.libraries:
if not all_strings(build_info.get('sources',[])):
self.run_command('build_src')
l = build_info.get('language',None)
if l and l not in languages: languages.append(l)
from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler,
dry_run=self.dry_run,
force=self.force)
self.compiler.customize(self.distribution,
need_cxx=self.have_cxx_sources())
libraries = self.libraries
self.libraries = None
self.compiler.customize_cmd(self)
self.libraries = libraries
self.compiler.show_customization()
if self.have_f_sources():
from numpy.distutils.fcompiler import new_fcompiler
self.fcompiler = new_fcompiler(compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
requiref90='f90' in languages,
c_compiler=self.compiler)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
libraries = self.libraries
self.libraries = None
self.fcompiler.customize_cmd(self)
self.libraries = libraries
self.fcompiler.show_customization()
self.build_libraries(self.libraries)
def _check_compiler(self):
old_config._check_compiler(self)
from numpy.distutils.fcompiler import FCompiler, new_fcompiler
if not isinstance(self.fcompiler, FCompiler):
self.fcompiler = new_fcompiler(compiler=self.fcompiler,
dry_run=self.dry_run,
force=1,
requiref90=True,
c_compiler=self.compiler)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
if self.fcompiler.get_version():
self.fcompiler.customize_cmd(self)
self.fcompiler.show_customization()
else:
self.warn('f90_compiler=%s is not available.' %
self.fcompiler.compiler_type)
self.fcompiler = None
def run(self):
if not self.executables:
return
# Make sure that library sources are complete.
languages = []
for exe in self.executables:
if not all_strings(exe.sources):
self.run_command("build_src")
l = exe.language
if l and l not in languages:
languages.append(l)
## Are the following lines unique for executables?
from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler, dry_run=self.dry_run, force=self.force)
self.compiler.customize(self.distribution, need_cxx=self.have_cxx_sources())
self.compiler.customize_cmd(self)
self.compiler.show_customization()
if have_numpy and self.have_f_sources():
from numpy.distutils.fcompiler import new_fcompiler
self.fcompiler = new_fcompiler(
compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
requiref90="f90" in languages,
c_compiler=self.compiler,
)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
self.fcompiler.customize_cmd(self)
self.fcompiler.show_customization()
for exe in self.executables:
build_target(self, exe, exe.name, EXECUTABLE)
"""
def get_fcompiler(self):
"""Get an fcompiler (including some hacks) or print error message if not found."""
fcompiler = FC.new_fcompiler(compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
c_compiler=self.compiler)
if fcompiler is None:
raise DistutilsError('Could not find Fortran compiler. See setup.cfg to specify one.')
fcompiler.customize(self.distribution)
fcompiler.customize_cmd(self)
fcompiler.show_customization()
#Hack because sometimes the executable linker is missing
if not fcompiler.linker_exe:
fcompiler.linker_exe = fcompiler.linker_so[:1]
return fcompiler
def show_fcompilers(dist=None):
"""Print list of available compilers (used by the "--help-fcompiler"
option to "config_fc").
"""
from numpy.distutils import fcompiler, log
if dist is None:
from distutils.dist import Distribution
from numpy.distutils.command.config_compiler import config_fc
dist = Distribution()
dist.script_name = os.path.basename(sys.argv[0])
dist.script_args = ['config_fc'] + sys.argv[1:]
try:
dist.script_args.remove('--help-fcompiler')
except ValueError:
pass
dist.cmdclass['config_fc'] = config_fc
dist.parse_config_files()
dist.parse_command_line()
compilers = {}
compilers_na = []
compilers_ni = []
if not fcompiler.fcompiler_class:
fcompiler.load_all_fcompiler_classes()
platform_compilers = fcompiler.available_fcompilers_for_platform()
for compiler in platform_compilers:
v = None
log.set_verbosity(-2)
try:
c = fcompiler.new_fcompiler(compiler=compiler, verbose=dist.verbose)
c.customize(dist)
v = c.get_version()
except (fcompiler.DistutilsModuleError, fcompiler.CompilerNotFound), e:
log.debug("show_fcompilers: %s not found" % (compiler,))
log.debug(repr(e))
if v is None:
compilers_na.append(("fcompiler="+compiler, None,
fcompiler.fcompiler_class[compiler][2]))
else:
c.dump_properties()
compilers[compiler] = c
def _check_compiler(self):
old_config._check_compiler(self)
from numpy.distutils.fcompiler import FCompiler, new_fcompiler
if sys.platform == "win32" and self.compiler.compiler_type == "msvc":
# XXX: hack to circumvent a python 2.6 bug with msvc9compiler:
# initialize call query_vcvarsall, which throws an IOError, and
# causes an error along the way without much information. We try to
# catch it here, hoping it is early enough, and print an helpful
# message instead of Error: None.
if not self.compiler.initialized:
try:
self.compiler.initialize()
except IOError:
e = get_exception()
msg = """\
Could not initialize compiler instance: do you have Visual Studio
installed ? If you are trying to build with mingw, please use python setup.py
build -c mingw32 instead ). If you have Visual Studio installed, check it is
correctly installed, and the right version (VS 2008 for python 2.6, VS 2003 for
2.5, etc...). Original exception was: %s, and the Compiler
class was %s
============================================================================""" % (
e,
self.compiler.__class__.__name__,
)
print(
"""\
============================================================================"""
)
raise distutils.errors.DistutilsPlatformError(msg)
if not isinstance(self.fcompiler, FCompiler):
self.fcompiler = new_fcompiler(
compiler=self.fcompiler, dry_run=self.dry_run, force=1, c_compiler=self.compiler
)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
if self.fcompiler.get_version():
self.fcompiler.customize_cmd(self)
self.fcompiler.show_customization()
def finalize_options(self):
old_build_ext.finalize_options(self)
if self.distribution.has_scons_scripts():
self.sconscripts = self.distribution.get_scons_scripts()
self.pre_hooks = self.distribution.get_scons_pre_hooks()
self.post_hooks = self.distribution.get_scons_post_hooks()
self.pkg_names = self.distribution.get_scons_parent_names()
else:
self.sconscripts = []
self.pre_hooks = []
self.post_hooks = []
self.pkg_names = []
# To avoid trouble, just don't do anything if no sconscripts are used.
# This is useful when for example f2py uses numpy.distutils, because
# f2py does not pass compiler information to scons command, and the
# compilation setup below can crash in some situation.
if len(self.sconscripts) > 0:
# Try to get the same compiler than the ones used by distutils: this is
# non trivial because distutils and scons have totally different
# conventions on this one (distutils uses PATH from user's environment,
# whereas scons uses standard locations). The way we do it is once we
# got the c compiler used, we use numpy.distutils function to get the
# full path, and add the path to the env['PATH'] variable in env
# instance (this is done in numpy.distutils.scons module).
# XXX: The logic to bypass distutils is ... not so logic.
compiler_type = self.compiler
if compiler_type == 'msvc':
self._bypass_distutils_cc = True
from numpy.distutils.ccompiler import new_compiler
try:
distutils_compiler = new_compiler(compiler=compiler_type,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
distutils_compiler.customize(self.distribution)
# This initialization seems necessary, sometimes, for find_executable to work...
if hasattr(distutils_compiler, 'initialize'):
distutils_compiler.initialize()
self.scons_compiler = dist2sconscc(distutils_compiler)
self.scons_compiler_path = protect_path(get_tool_path(distutils_compiler))
except DistutilsPlatformError, e:
if not self._bypass_distutils_cc:
raise e
else:
self.scons_compiler = compiler_type
# We do the same for the fortran compiler ...
fcompiler_type = self.fcompiler
from numpy.distutils.fcompiler import new_fcompiler
self.fcompiler = new_fcompiler(compiler = fcompiler_type,
verbose = self.verbose,
dry_run = self.dry_run,
force = self.force)
if self.fcompiler is not None:
self.fcompiler.customize(self.distribution)
# And the C++ compiler
cxxcompiler = new_compiler(compiler = compiler_type,
verbose = self.verbose,
dry_run = self.dry_run,
force = self.force)
if cxxcompiler is not None:
cxxcompiler.customize(self.distribution, need_cxx = 1)
cxxcompiler.customize_cmd(self)
self.cxxcompiler = cxxcompiler.cxx_compiler()
try:
get_cxx_tool_path(self.cxxcompiler)
except DistutilsSetupError:
self.cxxcompiler = None
if self.package_list:
self.package_list = parse_package_list(self.package_list)
def run(self):
if not self.extensions:
return
# Make sure that extension sources are complete.
self.run_command('build_src')
if self.distribution.has_c_libraries():
if self.inplace:
if self.distribution.have_run.get('build_clib'):
log.warn('build_clib already run, it is too late to '
'ensure in-place build of build_clib')
build_clib = self.distribution.get_command_obj(
'build_clib')
else:
build_clib = self.distribution.get_command_obj(
'build_clib')
build_clib.inplace = 1
build_clib.ensure_finalized()
build_clib.run()
self.distribution.have_run['build_clib'] = 1
else:
self.run_command('build_clib')
build_clib = self.get_finalized_command('build_clib')
self.library_dirs.append(build_clib.build_clib)
else:
build_clib = None
# Not including C libraries to the list of
# extension libraries automatically to prevent
# bogus linking commands. Extensions must
# explicitly specify the C libraries that they use.
from distutils.ccompiler import new_compiler
from numpy.distutils.fcompiler import new_fcompiler
compiler_type = self.compiler
# Initialize C compiler:
self.compiler = new_compiler(compiler=compiler_type,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
self.compiler.customize(self.distribution)
self.compiler.customize_cmd(self)
self.compiler.show_customization()
# Setup directory for storing generated extra DLL files on Windows
self.extra_dll_dir = os.path.join(self.build_temp, '.libs')
if not os.path.isdir(self.extra_dll_dir):
os.makedirs(self.extra_dll_dir)
# Create mapping of libraries built by build_clib:
clibs = {}
if build_clib is not None:
for libname, build_info in build_clib.libraries or []:
if libname in clibs and clibs[libname] != build_info:
log.warn('library %r defined more than once,'
' overwriting build_info\n%s... \nwith\n%s...'
% (libname, repr(clibs[libname])[:300], repr(build_info)[:300]))
clibs[libname] = build_info
# .. and distribution libraries:
for libname, build_info in self.distribution.libraries or []:
if libname in clibs:
# build_clib libraries have a precedence before distribution ones
continue
clibs[libname] = build_info
# Determine if C++/Fortran 77/Fortran 90 compilers are needed.
# Update extension libraries, library_dirs, and macros.
all_languages = set()
for ext in self.extensions:
ext_languages = set()
c_libs = []
c_lib_dirs = []
macros = []
for libname in ext.libraries:
if libname in clibs:
binfo = clibs[libname]
c_libs += binfo.get('libraries', [])
c_lib_dirs += binfo.get('library_dirs', [])
for m in binfo.get('macros', []):
if m not in macros:
macros.append(m)
for l in clibs.get(libname, {}).get('source_languages', []):
ext_languages.add(l)
if c_libs:
new_c_libs = ext.libraries + c_libs
log.info('updating extension %r libraries from %r to %r'
% (ext.name, ext.libraries, new_c_libs))
ext.libraries = new_c_libs
ext.library_dirs = ext.library_dirs + c_lib_dirs
if macros:
log.info('extending extension %r defined_macros with %r'
% (ext.name, macros))
ext.define_macros = ext.define_macros + macros
# determine extension languages
if has_f_sources(ext.sources):
#.........这里部分代码省略.........
def run(self):
if not self.extensions:
return
# Make sure that extension sources are complete.
self.run_command('build_src')
if self.distribution.has_c_libraries():
if self.inplace:
if self.distribution.have_run.get('build_clib'):
log.warn('build_clib already run, it is too late to ' \
'ensure in-place build of build_clib')
build_clib = self.distribution.get_command_obj('build_clib')
else:
build_clib = self.distribution.get_command_obj('build_clib')
build_clib.inplace = 1
build_clib.ensure_finalized()
build_clib.run()
self.distribution.have_run['build_clib'] = 1
else:
self.run_command('build_clib')
build_clib = self.get_finalized_command('build_clib')
self.library_dirs.append(build_clib.build_clib)
else:
build_clib = None
# Not including C libraries to the list of
# extension libraries automatically to prevent
# bogus linking commands. Extensions must
# explicitly specify the C libraries that they use.
from distutils.ccompiler import new_compiler
from numpy.distutils.fcompiler import new_fcompiler
compiler_type = self.compiler
# Initialize C compiler:
self.compiler = new_compiler(compiler=compiler_type,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
self.compiler.customize(self.distribution)
self.compiler.customize_cmd(self)
self.compiler.show_customization()
# Create mapping of libraries built by build_clib:
clibs = {}
if build_clib is not None:
for libname, build_info in build_clib.libraries or []:
if libname in clibs and clibs[libname] != build_info:
log.warn('library %r defined more than once,'\
' overwriting build_info\n%s... \nwith\n%s...' \
% (libname, repr(clibs[libname])[:300], repr(build_info)[:300]))
clibs[libname] = build_info
# .. and distribution libraries:
for libname, build_info in self.distribution.libraries or []:
if libname in clibs:
# build_clib libraries have a precedence before distribution ones
continue
clibs[libname] = build_info
# Determine if C++/Fortran 77/Fortran 90 compilers are needed.
# Update extension libraries, library_dirs, and macros.
all_languages = set()
for ext in self.extensions:
ext_languages = set()
c_libs = []
c_lib_dirs = []
macros = []
for libname in ext.libraries:
if libname in clibs:
binfo = clibs[libname]
c_libs += binfo.get('libraries', [])
c_lib_dirs += binfo.get('library_dirs', [])
for m in binfo.get('macros', []):
if m not in macros:
macros.append(m)
for l in clibs.get(libname, {}).get('source_languages', []):
ext_languages.add(l)
if c_libs:
new_c_libs = ext.libraries + c_libs
log.info('updating extension %r libraries from %r to %r'
% (ext.name, ext.libraries, new_c_libs))
ext.libraries = new_c_libs
ext.library_dirs = ext.library_dirs + c_lib_dirs
if macros:
log.info('extending extension %r defined_macros with %r'
% (ext.name, macros))
ext.define_macros = ext.define_macros + macros
# determine extension languages
if has_f_sources(ext.sources):
ext_languages.add('f77')
if has_cxx_sources(ext.sources):
ext_languages.add('c++')
l = ext.language or self.compiler.detect_language(ext.sources)
if l:
ext_languages.add(l)
# reset language attribute for choosing proper linker
#.........这里部分代码省略.........
请发表评论