Exemplo n.º 1
0
def show_sys_vars():
	print('os.name = %s, sys.platform = %s' % (os.name, sys.platform))

	from distutils import util, ccompiler
	print('platform = %s' % util.get_platform())
	print('compiler = %s' % ccompiler.get_default_compiler())

	from SCons.Environment import Environment
	env = Environment()
	vars = [
		'CC',
		'CXX',
		'PLATFORM',
		'MSVC_VERSION',
		'TARGET',
		'TARGET_ARCH',
		'TARGET_OS',
		'MSVS',
		'MSVS_VERSION',
		'MSVS_ARCH',
		'TOOLS',
		'HOST_ARCH',
		'HOST_OS',
		'MSVC_BATCH',
		'MSVC_USE_SCRIPT',
	]
	for var in vars:
		print('%s = %r' % (var, env.subst('$' + var)))
Exemplo n.º 2
0
def findcc(pathstring):
    list = []
    from distutils import ccompiler    
    yourcompiler = ccompiler.get_default_compiler()
    if sys.platform == 'sunos5"' or 'irix6':
        for a in pathstring:
            if  os.path.exists('%s/cc' %a) or os.path.exists('%s/CC' %a):
                list.append('%s' %a)    
        if list == []:
                print "YOU DO NOT HAVE A C-COMPILER"
                sys.exit()
    if (sys.platform == 'cygwin') or (os.name == 'nt'):
     	for a in pathstring:
            if  os.path.exists('%s/cc' %a):
                list.append('%s' %a)    
        if list == []:
                print "YOU DO NOT HAVE A C-COMPILER"
                sys.exit()		

    if (sys.platform == 'linux2') or (sys.platform == 'darwin'):
        for a in pathstring:
            if  os.path.exists('%s/gcc' %a) or os.path.exists('%s/g++' %a):
                list.append('%s' %a)    
        	
	    if list == []:
                print "YOU DO NOT HAVE A C-COMPILER"
                sys.exit()
Exemplo n.º 3
0
    def finalize_options(self):

        build_ext.finalize_options(self)

        if self.compiler is None:
            compiler = get_default_compiler()
        else:
            compiler = self.compiler

        if compiler == "msvc":
            # Add msvc specific hacks

            if (sys.version_info.major, sys.version_info.minor) < (3, 3):
                # The check above is a nasty hack. We're using the python
                # version as a proxy for the MSVC version. 2008 doesn't
                # have stdint.h, so is needed. 2010 does.
                #
                # We need to add the path to msvc includes
                include_dirs.append(os.path.join(os.getcwd(), "include", "msvc_2008"))

            # We need to prepend lib to all the library names
            _libraries = []
            for each_lib in self.libraries:
                _libraries.append("lib" + each_lib)

            self.libraries = _libraries
Exemplo n.º 4
0
def getRevison():
    compiler = get_default_compiler()
    if compiler == 'unix':
	res = os.popen('svn info |grep Revision: |cut -c11-')
	return res.read().strip()
    elif compiler == 'msvc':
	return os.popen("run.bat").readlines()[-1].strip()
Exemplo n.º 5
0
def getCompilerInfo(cxxCompiler):
    """
  Identify compiler
  """

    if cxxCompiler is None:
        cxxCompiler = ccompiler.get_default_compiler()

    if "clang" in cxxCompiler:
        cxxCompiler = "Clang"
    elif "gnu" in cxxCompiler:
        cxxCompiler = "GNU"
    # TODO: There is a problem here, because on OS X ccompiler.get_default_compiler()
    # returns "unix", not "clang" or "gnu". So we have to handle "unix" and we lose
    # the ability to decide which compiler is used.
    elif "unix" in cxxCompiler:
        cxxCompiler = "unix"
    elif "msvc" in cxxCompiler:
        cxxCompiler = "MSVC"
    elif "mingw" in cxxCompiler:
        cxxCompiler = "MinGW"
    else:
        raise Exception("C++ compiler '%s' is unsupported!" % cxxCompiler)

    print "CXX Compiler: {}".format(cxxCompiler)
    return cxxCompiler
 def compiler_type(self):
     compiler = self.compiler
     if compiler is None:
         return get_default_compiler()
     elif isinstance(compiler, str):
         return compiler
     else:
         return compiler.compiler_type
Exemplo n.º 7
0
    def finalize_options(self):

        build_ext.finalize_options(self)

        if self.compiler is None:
            compiler = get_default_compiler()
        else:
            compiler = self.compiler
Exemplo n.º 8
0
def detect_version(basedir, compiler=None, **compiler_attrs):
    """Compile, link & execute a test program, in empty directory `basedir`.

    The C compiler will be updated with any keywords given via setattr.

    Parameters
    ----------

    basedir : path
        The location where the test program will be compiled and run
    compiler : str
        The distutils compiler key (e.g. 'unix', 'msvc', or 'mingw32')
    **compiler_attrs : dict
        Any extra compiler attributes, which will be set via ``setattr(cc)``.

    Returns
    -------

    A dict of properties for zmq compilation, with the following two keys:

    vers : tuple
        The ZMQ version as a tuple of ints, e.g. (2,2,0)
    settings : dict
        The compiler options used to compile the test function, e.g. `include_dirs`,
        `library_dirs`, `libs`, etc.
    """
    if compiler is None:
        compiler = get_default_compiler()
    cfile = pjoin(basedir, 'vers.cpp')
    shutil.copy(pjoin(os.path.dirname(__file__), 'vers.cpp'), cfile)

    # check if we need to link against Realtime Extensions library
    if sys.platform.startswith('linux'):
        cc = ccompiler.new_compiler(compiler=compiler)
        cc.output_dir = basedir
        if not cc.has_function('timer_create'):
            if 'libraries' not in compiler_attrs:
                compiler_attrs['libraries'] = []
            compiler_attrs['libraries'].append('rt')

    cc = get_compiler(compiler=compiler, **compiler_attrs)
    efile = test_compilation(cfile, compiler=cc)
    patch_lib_paths(efile, cc.library_dirs)

    rc, so, se = get_output_error([efile])
    if rc:
        msg = "Error running version detection script:\n%s\n%s" % (so,se)
        logging.error(msg)
        raise IOError(msg)

    handlers = {'vers':  lambda val: tuple(int(v) for v in val.split('.'))}

    props = {}
    for line in (x for x in so.split('\n') if x):
        key, val = line.split(':')
        props[key] = handlers[key](val)

    return props
Exemplo n.º 9
0
    def finalize_options(self):
        build_ext.finalize_options(self)
        if self.compiler is None:
            compiler = get_default_compiler()
        else:
            compiler = self.compiler

        if compiler == 'msvc':
            include_dirs.append('compat/win32')
Exemplo n.º 10
0
 def compiler_type(self):
     if self.compiler:
         return self.compiler
     compiler = self.distribution.get_command_obj("build_ext").compiler
     if compiler is None:
         return get_default_compiler()
     elif isinstance(compiler, str):
         return compiler
     else:
         return compiler.compiler_type
Exemplo n.º 11
0
def adjust_compiler():
    """
    This function detects broken compilers and switches to another.  If
    the environment variable CC is explicitly set, or a compiler is
    specified on the commandline, no override is performed -- the purpose
    here is to only override a default compiler.

    The specific compilers with problems are:

        * The default compiler in XCode-4.2, llvm-gcc-4.2,
          segfaults when compiling wcslib.

    The set of broken compilers can be updated by changing the
    compiler_mapping variable.  It is a list of 2-tuples where the
    first in the pair is a regular expression matching the version
    of the broken compiler, and the second is the compiler to change
    to.
    """

    global _adjusted_compiler
    if _adjusted_compiler:
        return

    # Whatever the result of this function is, it only needs to be run once
    _adjusted_compiler = True

    if "CC" in os.environ:
        return

    if get_distutils_option("compiler", ["build", "build_ext", "build_clib"]) is not None:
        return

    from distutils import ccompiler, sysconfig
    import subprocess
    import re

    compiler_mapping = [(b"i686-apple-darwin[0-9]*-llvm-gcc-4.2", "clang")]

    compiler_type = ccompiler.get_default_compiler()

    if compiler_type == "unix":

        # We have to get the compiler this way, as this is the one that is
        # used if os.environ['CC'] is not set. It is actually read in from
        # the Python Makefile. Note that this is not necessarily the same
        # compiler as returned by ccompiler.new_compiler()
        c_compiler = sysconfig.get_config_var("CC")

        process = subprocess.Popen(shlex.split(c_compiler) + ["--version"], stdout=subprocess.PIPE)
        output = process.communicate()[0].strip()
        version = output.split()[0]
        for broken, fixed in compiler_mapping:
            if re.match(broken, version):
                os.environ["CC"] = fixed
                break
Exemplo n.º 12
0
	def __init__(self):
		env = _Environment()
		self.arch = env['TARGET_ARCH']
		self.platform = sys.platform
		self.compiler = ccompiler.get_default_compiler()
		self.compiler_version = StrictVersion('0.0')
		if self.compiler == 'msvc':
			self.compiler_version = StrictVersion(env['MSVC_VERSION'])
			os.environ['PATH'] = env['ENV']['PATH']
			os.environ['INCLUDE'] = env['ENV']['INCLUDE']
			os.environ['LIB'] = env['ENV']['LIB']
			os.environ['LIBPATH'] = env['ENV']['LIBPATH']
Exemplo n.º 13
0
def setupLibMSEED():
    """
    Prepare building of C extension libmseed.
    """
    macros = []
    extra_link_args = []
    extra_compile_args = []
    src_obspy = os.path.join('obspy', 'mseed', 'src') + os.sep
    src = os.path.join('obspy', 'mseed', 'src', 'libmseed') + os.sep
    # get symbols for libmseed
    lines = open(src + 'libmseed.def', 'r').readlines()[2:]
    symbols = [s.strip() for s in lines if s.strip() != '']
    # get symbols for obspy-readbuffer.c
    lines = open(src_obspy + 'obspy-readbuffer.def', 'r').readlines()[2:]
    symbols += [s.strip() for s in lines if s.strip() != '']

    # system specific settings
    if IS_WINDOWS:
        # needed by libmseed lmplatform.h
        macros.append(('WIN32', '1'))
        # disable some warnings for MSVC
        macros.append(('_CRT_SECURE_NO_WARNINGS', '1'))
        if 'msvc' in sys.argv or \
            ('-c' not in sys.argv and get_default_compiler() == 'msvc'):
            if platform.architecture()[0] == '32bit':
                # Workaround Win32 and MSVC - see issue #64
                extra_compile_args.append("/fp:strict")

    # create library name
    if IS_DEVELOP:
        lib_name = 'libmseed-%s-%s-py%s' % (
            platform.system(), platform.architecture()[0],
            ''.join([str(i) for i in platform.python_version_tuple()[:2]]))
    else:
        lib_name = 'libmseed'

    # setup C extension
    lib = MyExtension(lib_name,
                      define_macros=macros,
                      libraries=[],
                      sources=[src + 'fileutils.c', src + 'genutils.c',
                               src + 'gswap.c', src + 'lmplatform.c',
                               src + 'lookup.c', src + 'msrutils.c',
                               src + 'pack.c', src + 'packdata.c',
                               src + 'traceutils.c', src + 'tracelist.c',
                               src + 'unpack.c', src + 'unpackdata.c',
                               src + 'selection.c', src + 'logging.c',
                               src + 'parseutils.c',
                               src_obspy + 'obspy-readbuffer.c'],
                      export_symbols=symbols,
                      extra_link_args=extra_link_args,
                      extra_compile_args=extra_compile_args)
    return lib
Exemplo n.º 14
0
def get_compiler_and_args():
    '''
    Returns the computed compiler and compilation flags
    '''
    compiler = prefs['codegen.cpp.compiler']
    if compiler == '':
        compiler = get_default_compiler()
    extra_compile_args = prefs['codegen.cpp.extra_compile_args']
    if extra_compile_args is None:
        if compiler in ('gcc', 'unix'):
            extra_compile_args = prefs['codegen.cpp.extra_compile_args_gcc']
        if compiler == 'msvc':
            extra_compile_args = prefs['codegen.cpp.extra_compile_args_msvc']
    return compiler, extra_compile_args
Exemplo n.º 15
0
    def finalize_options(self):

        build_ext.finalize_options(self)

        if self.compiler is None:
            compiler = get_default_compiler()
        else:
            compiler = self.compiler

        if compiler == 'msvc':
            # Add msvc specific hacks
            
            if (sys.version_info.major, sys.version_info.minor) < (3, 3):
                # The check above is a nasty hack. We're using the python
                # version as a proxy for the MSVC version. 2008 doesn't
                # have stdint.h, so is needed. 2010 does.
                #
                # We need to add the path to msvc includes

                msvc_2008_path = (
                    os.path.join(os.getcwd(), 'include', 'msvc_2008'))

                if self.include_dirs is not None:
                    self.include_dirs.append(msvc_2008_path)

                else:
                    self.include_dirs = [msvc_2008_path]

            elif (sys.version_info.major, sys.version_info.minor) < (3, 5):
                # Actually, it seems that appveyor doesn't have a stdint that
                # works, so even for 2010 we use our own (hacked) version
                # of stdint.
                # This should be pretty safe in whatever case.
                msvc_2010_path = (
                    os.path.join(os.getcwd(), 'include', 'msvc_2010'))

                if self.include_dirs is not None:
                    self.include_dirs.append(msvc_2010_path)

                else:
                    self.include_dirs = [msvc_2010_path]

            # We need to prepend lib to all the library names
            _libraries = []
            for each_lib in self.libraries:
                _libraries.append('lib' + each_lib)

            self.libraries = _libraries
Exemplo n.º 16
0
    def get_compiler_name(self):
        """Return the name of the C compiler used to compile extensions.

        If a compiler was not explicitly set (on the command line, for
        example), fall back on the default compiler.
        """
        if self.compiler:
            # distutils doesn't keep the type of self.compiler uniform; we
            # compensate:
            if isinstance(self.compiler, str):
                name = self.compiler
            else:
                name = self.compiler.compiler_type
        else:
            name = get_default_compiler()
        return name
Exemplo n.º 17
0
        def _check_cython_sources(self, extension):
            """
            Where relevant, make sure that the .c files associated with .pyx
            modules are present (if building without Cython installed).
            """

            # Determine the compiler we'll be using
            if self.compiler is None:
                compiler = get_default_compiler()
            else:
                compiler = self.compiler

            # Replace .pyx with C-equivalents, unless c files are missing
            for jdx, src in enumerate(extension.sources):
                base, ext = os.path.splitext(src)
                pyxfn = base + '.pyx'
                cfn = base + '.c'
                cppfn = base + '.cpp'


                if not os.path.isfile(pyxfn):
                    continue

                if self.uses_cython:
                    extension.sources[jdx] = pyxfn
                else:
                    if os.path.isfile(cfn):
                        extension.sources[jdx] = cfn
                    elif os.path.isfile(cppfn):
                        extension.sources[jdx] = cppfn
                    else:
                        msg = (
                            'Could not find C/C++ file {0}.(c/cpp) for Cython '
                            'file {1} when building extension {2}. Cython '
                            'must be installed to build from a git '
                            'checkout.'.format(base, pyxfn, extension.name))
                        raise IOError(errno.ENOENT, msg, cfn)

                # Current versions of Cython use deprecated Numpy API features
                # the use of which produces a few warnings when compiling.
                # These additional flags should squelch those warnings.
                # TODO: Feel free to remove this if/when a Cython update
                # removes use of the deprecated Numpy API
                if compiler == 'unix':
                    extension.extra_compile_args.extend([
                        '-Wp,-w', '-Wno-unused-function'])
Exemplo n.º 18
0
def get_compiler_option():
    """ Determines the compiler that will be used to build extension modules.

    Returns
    -------
    compiler : str
        The compiler option specified for the build, build_ext, or build_clib
        command; or the default compiler for the platform if none was
        specified.

    """

    compiler = get_distutils_build_option('compiler')
    if compiler is None:
        return ccompiler.get_default_compiler()

    return compiler
Exemplo n.º 19
0
    def finalize_options(self):
        build_ext.finalize_options(self)
        self.set_undefined_options('build', ('static','static'))

        self.include_dirs = self.include_dirs or []
        self.library_dirs = self.library_dirs or []
        self.define = self.define or []
        self.libraries = self.libraries or []

        extra_compile_args = []
        extra_link_args = []

        compiler = self.compiler or get_default_compiler()

        if compiler == 'msvc':
            try:
                QL_INSTALL_DIR = os.environ['QL_DIR']
                self.include_dirs += [QL_INSTALL_DIR]
                self.library_dirs += [os.path.join(QL_INSTALL_DIR, 'lib')]
            except KeyError, e:
                print 'warning: unable to detect QuantLib installation'

            if os.environ.has_key('INCLUDE'):
                dirs = [dir for dir in os.environ['INCLUDE'].split(';')]
                self.include_dirs += dirs
            if os.environ.has_key('LIB'):
                dirs = [dir for dir in os.environ['LIB'].split(';')]
                self.library_dirs += dirs

            self.define += [('__WIN32__', None), ('WIN32', None),
                            ('NDEBUG', None), ('_WINDOWS', None),
                            ('NOMINMAX', None)]
            extra_compile_args = ['/GR', '/FD', '/Zm250', '/EHsc' ]
            extra_link_args = ['/subsystem:windows', '/machine:I386']

            if self.debug:
                if self.static:
                    extra_compile_args.append('/MTd')
                else:
                    extra_compile_args.append('/MDd')
            else:
                if self.static:
                    extra_compile_args.append('/MT')
                else:
                    extra_compile_args.append('/MD')
Exemplo n.º 20
0
def show_compiler():
    from distutils.core import Distribution
    dist = Distribution()
    dist.parse_config_files()
    opt = dist.command_options
    try:
        fn, compiler_name = opt["build"]["compiler"]
    except:
        from distutils.ccompiler import get_default_compiler
        fn = "default"
        compiler_name = get_default_compiler()

    from distutils import ccompiler
    version = ""
    if compiler_name == "msvc":
        compiler = ccompiler.new_compiler(compiler=compiler_name)
        version = str(compiler._MSVCCompiler__version)
    print "{} {} defined by {}".format(compiler_name, version, fn)
Exemplo n.º 21
0
    def test_customize_compiler(self):

        # not testing if default compiler is not unix
        if get_default_compiler() != 'unix':
            return

        os.environ['AR'] = 'xxx'

        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        comp = compiler()
        sysconfig.customize_compiler(comp)
        self.assertEquals(comp.exes['archiver'], 'xxx')
Exemplo n.º 22
0
    def test_customize_compiler(self):

        # not testing if default compiler is not unix
        if get_default_compiler() != "unix":
            return

        self.environ["AR"] = "my_ar"
        self.environ["ARFLAGS"] = "-arflags"

        # make sure AR gets caught
        class compiler:
            compiler_type = "unix"

            def set_executables(self, **kw):
                self.exes = kw

        comp = compiler()
        sysconfig.customize_compiler(comp)
        self.assertEquals(comp.exes["archiver"], "my_ar -arflags")
Exemplo n.º 23
0
    def test_customize_compiler(self):

        # not testing if default compiler is not unix
        if get_default_compiler() != 'unix':
            return

        os.environ['AR'] = 'my_ar'
        os.environ['ARFLAGS'] = '-arflags'

        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        comp = compiler()
        customize_compiler(comp)
        self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
Exemplo n.º 24
0
    def setup_compiler(self):
        self.compiler = self.compiler or get_default_compiler()
        self.extra_compile_args = []
        self.extra_link_args = []
        if self.compiler == 'msvc':
            distutils.msvc9compiler.VERSION = 11.0
            self.extra_compile_args.append('/EHsc')
            if self._debug:
                self.extra_compile_args.extend(['/Zi'])
                #self.extra_compile_args.extend(['/Od'])
                #self.extra_compile_args.extend(['/UNDEBUG'])
                self.extra_link_args.extend(['/DEBUG'])
                self.extra_compile_args.extend(['/GF', '/GL', '/GT', '/Gy'])
                self.extra_link_args.extend(['/OPT:REF', '/OPT:ICF', '/LTCG'])
            else:
                self.extra_compile_args.extend(['/GF', '/GL', '/GT', '/Gy'])
                self.extra_link_args.extend(['/OPT:REF', '/OPT:ICF', '/LTCG'])

        for ext_module in self.distribution.ext_modules:
            ext_module.extra_compile_args.extend(self.extra_compile_args)
            ext_module.extra_link_args.extend(self.extra_link_args)
Exemplo n.º 25
0
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
    def setUp(self):
        super(SysconfigTestCase, self).setUp()
        self.makefile = None

    def tearDown(self):
        if self.makefile is not None:
            os.unlink(self.makefile)
        self.cleanup_testfn()
        super(SysconfigTestCase, self).tearDown()

    def cleanup_testfn(self):
        path = test.test_support.TESTFN
        if os.path.isfile(path):
            os.remove(path)
        elif os.path.isdir(path):
            shutil.rmtree(path)

    def test_get_python_lib(self):
        lib_dir = sysconfig.get_python_lib()
        # XXX doesn't work on Linux when Python was never installed before
        #self.assertTrue(os.path.isdir(lib_dir), lib_dir)
        # test for pythonxx.lib?
        self.assertNotEqual(sysconfig.get_python_lib(),
                            sysconfig.get_python_lib(prefix=TESTFN))
        _sysconfig = __import__('sysconfig')
        res = sysconfig.get_python_lib(True, True)
        self.assertEqual(_sysconfig.get_path('platstdlib'), res)

    def test_get_python_inc(self):
        inc_dir = sysconfig.get_python_inc()
        # This is not much of a test.  We make sure Python.h exists
        # in the directory returned by get_python_inc() but we don't know
        # it is the correct file.
        self.assertTrue(os.path.isdir(inc_dir), inc_dir)
        python_h = os.path.join(inc_dir, "Python.h")
        self.assertTrue(os.path.isfile(python_h), python_h)

    def customize_compiler(self):
        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        sysconfig_vars = {
            'AR': 'sc_ar',
            'CC': 'sc_cc',
            'CXX': 'sc_cxx',
            'ARFLAGS': '--sc-arflags',
            'CFLAGS': '--sc-cflags',
            'CCSHARED': '--sc-ccshared',
            'LDSHARED': 'sc_ldshared',
            'SO': 'sc_shutil_suffix',
        }

        comp = compiler()
        old_vars = dict(sysconfig._config_vars)
        try:
            # On macOS, disable _osx_support.customize_compiler()
            sysconfig._config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'

            for key, value in sysconfig_vars.items():
                sysconfig._config_vars[key] = value
            sysconfig.customize_compiler(comp)
        finally:
            sysconfig._config_vars.clear()
            sysconfig._config_vars.update(old_vars)

        return comp

    @unittest.skipUnless(get_default_compiler() == 'unix',
                         'not testing if default compiler is not unix')
    def test_customize_compiler(self):
        # Make sure that sysconfig._config_vars is initialized
        sysconfig.get_config_vars()

        os.environ['AR'] = 'env_ar'
        os.environ['CC'] = 'env_cc'
        os.environ['CPP'] = 'env_cpp'
        os.environ['CXX'] = 'env_cxx --env-cxx-flags'
        os.environ['LDSHARED'] = 'env_ldshared'
        os.environ['LDFLAGS'] = '--env-ldflags'
        os.environ['ARFLAGS'] = '--env-arflags'
        os.environ['CFLAGS'] = '--env-cflags'
        os.environ['CPPFLAGS'] = '--env-cppflags'

        comp = self.customize_compiler()
        self.assertEqual(comp.exes['archiver'], 'env_ar --env-arflags')
        self.assertEqual(comp.exes['preprocessor'], 'env_cpp --env-cppflags')
        self.assertEqual(comp.exes['compiler'],
                         'env_cc --sc-cflags --env-cflags --env-cppflags')
        self.assertEqual(comp.exes['compiler_so'],
                         ('env_cc --sc-cflags '
                          '--env-cflags '
                          '--env-cppflags --sc-ccshared'))
        self.assertEqual(comp.exes['compiler_cxx'], 'env_cxx --env-cxx-flags')
        self.assertEqual(comp.exes['linker_exe'], 'env_cc')
        self.assertEqual(comp.exes['linker_so'],
                         ('env_ldshared --env-ldflags --env-cflags'
                          ' --env-cppflags'))
        self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')

        del os.environ['AR']
        del os.environ['CC']
        del os.environ['CPP']
        del os.environ['CXX']
        del os.environ['LDSHARED']
        del os.environ['LDFLAGS']
        del os.environ['ARFLAGS']
        del os.environ['CFLAGS']
        del os.environ['CPPFLAGS']

        comp = self.customize_compiler()
        self.assertEqual(comp.exes['archiver'], 'sc_ar --sc-arflags')
        self.assertEqual(comp.exes['preprocessor'], 'sc_cc -E')
        self.assertEqual(comp.exes['compiler'], 'sc_cc --sc-cflags')
        self.assertEqual(comp.exes['compiler_so'],
                         'sc_cc --sc-cflags --sc-ccshared')
        self.assertEqual(comp.exes['compiler_cxx'], 'sc_cxx')
        self.assertEqual(comp.exes['linker_exe'], 'sc_cc')
        self.assertEqual(comp.exes['linker_so'], 'sc_ldshared')
        self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')

    def test_parse_makefile_base(self):
        self.makefile = test.test_support.TESTFN
        fd = open(self.makefile, 'w')
        try:
            fd.write(r"CONFIG_ARGS=  '--arg1=optarg1' 'ENV=LIB'" '\n')
            fd.write('VAR=$OTHER\nOTHER=foo')
        finally:
            fd.close()
        d = sysconfig.parse_makefile(self.makefile)
        self.assertEqual(d, {
            'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
            'OTHER': 'foo'
        })

    def test_parse_makefile_literal_dollar(self):
        self.makefile = test.test_support.TESTFN
        fd = open(self.makefile, 'w')
        try:
            fd.write(r"CONFIG_ARGS=  '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
            fd.write('VAR=$OTHER\nOTHER=foo')
        finally:
            fd.close()
        d = sysconfig.parse_makefile(self.makefile)
        self.assertEqual(d, {
            'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
            'OTHER': 'foo'
        })

    def test_sysconfig_module(self):
        import sysconfig as global_sysconfig
        self.assertEqual(global_sysconfig.get_config_var('CFLAGS'),
                         sysconfig.get_config_var('CFLAGS'))
        self.assertEqual(global_sysconfig.get_config_var('LDFLAGS'),
                         sysconfig.get_config_var('LDFLAGS'))

    @unittest.skipIf(sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'),
                     'compiler flags customized')
    def test_sysconfig_compiler_vars(self):
        # On OS X, binary installers support extension module building on
        # various levels of the operating system with differing Xcode
        # configurations.  This requires customization of some of the
        # compiler configuration directives to suit the environment on
        # the installed machine.  Some of these customizations may require
        # running external programs and, so, are deferred until needed by
        # the first extension module build.  With Python 3.3, only
        # the Distutils version of sysconfig is used for extension module
        # builds, which happens earlier in the Distutils tests.  This may
        # cause the following tests to fail since no tests have caused
        # the global version of sysconfig to call the customization yet.
        # The solution for now is to simply skip this test in this case.
        # The longer-term solution is to only have one version of sysconfig.

        import sysconfig as global_sysconfig
        if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
            self.skipTest('compiler flags customized')
        self.assertEqual(global_sysconfig.get_config_var('LDSHARED'),
                         sysconfig.get_config_var('LDSHARED'))
        self.assertEqual(global_sysconfig.get_config_var('CC'),
                         sysconfig.get_config_var('CC'))

    def test_customize_compiler_before_get_config_vars(self):
        # Issue #21923: test that a Distribution compiler
        # instance can be called without an explicit call to
        # get_config_vars().
        with open(TESTFN, 'w') as f:
            f.writelines(
                textwrap.dedent('''\
                from distutils.core import Distribution
                config = Distribution().get_command_obj('config')
                # try_compile may pass or it may fail if no compiler
                # is found but it should not raise an exception.
                rc = config.try_compile('int x;')
                '''))
        p = subprocess.Popen([str(sys.executable), TESTFN],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             universal_newlines=True)
        outs, errs = p.communicate()
        self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)
Exemplo n.º 26
0
    SUP_EXTERNAL = 1
    sys.argv.remove("--external")
    # You should add external library by option: --libraries zstd
    # And probably include paths by option: --include-dirs /usr/include/zstd
    # And probably library paths by option: --library-dirs /usr/lib/i386-linux-gnu
    if "--libraries" not in sys.argv:
        # Add something default
        ext_libraries = ["zstd"]

EXTRA_OPT = 0
if "--extra-optimization" in sys.argv:
    # Support legacy output format functions
    EXTRA_OPT = 1
    sys.argv.remove("--extra-optimization")

if ccompiler.get_default_compiler() == "msvc":
    extra_compile_args = ["/Wall"]
    if EXTRA_OPT:
        extra_compile_args.insert(0, "/O2")
    else:
        extra_compile_args.insert(0, "/Ot")
else:
    extra_compile_args = [
        "-std=c99", "-Wall", "-DFORTIFY_SOURCE=2", "-fstack-protector"
    ]
    if EXTRA_OPT:
        extra_compile_args.insert(0, "-march=native")
        extra_compile_args.insert(0, "-O3")
    else:
        extra_compile_args.insert(0, "-O2")
Exemplo n.º 27
0
                "UnsharpMask", "XbmDecode", "XbmEncode", "ZipDecode",
                "ZipEncode", "TiffDecode", "Jpeg2KDecode", "Jpeg2KEncode",
                "BoxBlur", "QuantPngQuant", "codec_fd")

DEBUG = False


class DependencyException(Exception):
    pass


class RequiredDependencyException(Exception):
    pass


PLATFORM_MINGW = 'mingw' in ccompiler.get_default_compiler()
PLATFORM_PYPY = hasattr(sys, 'pypy_version_info')


def _dbg(s, tp=None):
    if DEBUG:
        if tp:
            print(s % tp)
            return
        print(s)


def _add_directory(path, subdir, where=None):
    if subdir is None:
        return
    subdir = os.path.realpath(subdir)
Exemplo n.º 28
0
def setupLibMSEED():
    """
    Prepare building of C extension libmseed.
    """

    # hack to prevent build_ext to append __init__ to the export symbols
    class finallist(list):
        def append(self, object):
            return

    class MyExtension(Extension):
        def __init__(self, *args, **kwargs):
            Extension.__init__(self, *args, **kwargs)
            self.export_symbols = finallist(self.export_symbols)

    macros = []
    extra_link_args = []
    extra_compile_args = []
    src_obspy = os.path.join('obspy', 'mseed', 'src') + os.sep
    src = os.path.join('obspy', 'mseed', 'src', 'libmseed') + os.sep
    # get symbols for libmseed
    lines = open(src + 'libmseed.def', 'r').readlines()[2:]
    symbols = [s.strip() for s in lines if s.strip() != '']
    # get symbols for obspy-readbuffer.c
    lines = open(src_obspy + 'obspy-readbuffer.def', 'r').readlines()[2:]
    symbols += [s.strip() for s in lines if s.strip() != '']

    # system specific settings
    if platform.system() == "Windows":
        # needed by libmseed lmplatform.h
        macros.append(('WIN32', '1'))
        # disable some warnings for MSVC
        macros.append(('_CRT_SECURE_NO_WARNINGS', '1'))
        if 'msvc' in sys.argv or \
            ('-c' not in sys.argv and get_default_compiler() == 'msvc'):
            if platform.architecture()[0] == '32bit':
                # Workaround Win32 and MSVC - see issue #64
                extra_compile_args.append("/fp:strict")

    # create library name
    if 'develop' in sys.argv:
        lib_name = 'libmseed-%s-%s-py%s' % (
            platform.system(), platform.architecture()[0], ''.join(
                [str(i) for i in platform.python_version_tuple()[:2]]))
    else:
        lib_name = 'libmseed'

    # setup C extension
    lib = MyExtension(
        lib_name,
        define_macros=macros,
        libraries=[],
        sources=[
            src + 'fileutils.c', src + 'genutils.c', src + 'gswap.c',
            src + 'lmplatform.c', src + 'lookup.c', src + 'msrutils.c',
            src + 'pack.c', src + 'packdata.c', src + 'traceutils.c',
            src + 'tracelist.c', src + 'unpack.c', src + 'unpackdata.c',
            src + 'selection.c', src + 'logging.c', src + 'parseutils.c',
            src_obspy + 'obspy-readbuffer.c'
        ],
        export_symbols=symbols,
        extra_link_args=extra_link_args,
        extra_compile_args=extra_compile_args)
    return lib
Exemplo n.º 29
0
if os.path.exists("MANIFEST"):
    os.remove("MANIFEST")

with open("README.md") as file:
    long_description = file.read()

CPP14_CONFIG = defaultdict(lambda: ["-std=c++14"], {
    "unix": ["-std=c++14"],
    "msvc": ["/std:c++14"]
})
CPP03_CONFIG = defaultdict(lambda: ["-std=c++03"], {
    "unix": ["-std=c++03"],
    "msvc": ["/std:c++03"]
})

_COMPILER = get_default_compiler()

omp_args, _ = check_for_openmp()

if os.name == "nt":
    std_libs = []
else:
    std_libs = ["m"]

CPP14_FLAG = CPP14_CONFIG[_COMPILER]
CPP03_FLAG = CPP03_CONFIG[_COMPILER]

cythonize_aliases = {
    "LIB_DIR":
    "yt/utilities/lib/",
    "LIB_DIR_EWAH": ["yt/utilities/lib/", "yt/utilities/lib/ewahboolarray/"],
Exemplo n.º 30
0
# local script imports:
from buildutils import (
    discover_settings, v_str, save_config, load_config, detect_zmq,
    warn, fatal, debug, line, copy_and_patch_libzmq, localpath,
    fetch_uuid, fetch_libzmq, stage_platform_hpp,
    bundled_version, customize_mingw,
    )

#-----------------------------------------------------------------------------
# Flags
#-----------------------------------------------------------------------------

# ignore unused-function and strict-aliasing warnings, of which there
# will be many from the Cython generated code:
# note that this is only for gcc-style compilers
if get_default_compiler() in ('unix', 'mingw32'):
    ignore_common_warnings=True
else:
    ignore_common_warnings=False

# the minimum zeromq version this will work against:
min_zmq = (2,1,4)

# set dylib ext:
if sys.platform.startswith('win'):
    lib_ext = '.dll'
elif sys.platform == 'darwin':
    lib_ext = '.dylib'
else:
    lib_ext = '.so'
Exemplo n.º 31
0
import os
from distutils import ccompiler

from cffi import FFI


_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__)))
_ASSIMP_CPP = os.path.join(_ROOT, "assimp.cpp")
_ASSIMP_H = os.path.join(_ROOT, "assimp.h")


_LIB_ASSIMP = None
_LIB_IRRXML = None
_LIB_ZLIB = None

if ccompiler.get_default_compiler() == "unix":
    # Default libs path for Unix systems
    _LIB_ASSIMP = os.path.join(_ROOT, "..", "..", "assimp", "build", "lib", "libassimp.a")  # noqa
    _LIB_IRRXML = os.path.join(_ROOT, "..", "..", "assimp", "build", "lib", "libIrrXML.a")  # noqa
    _LIB_ZLIB = os.path.join(_ROOT, "..", "..", "assimp", "build", "lib", "libzlibstatic.a")  # noqa
elif ccompiler.get_default_compiler() == "msvc":
    # Default libs path for Windows
    _LIB_ASSIMP = os.path.join(_ROOT, "..", "..", "assimp", "build", "lib", "Release", "assimp.lib")  # noqa
    _LIB_IRRXML = os.path.join(_ROOT, "..", "..", "assimp", "build", "lib", "Release", "IrrXML.lib")  # noqa
    _LIB_ZLIB = os.path.join(_ROOT, "..", "..", "assimp", "build", "lib", "Release", "zlibstatic.lib")  # noqa

# Allow to override path through env vars
if "YOGA_BUILD_LIB_ASSIMP" in os.environ:
    _LIB_ASSIMP = os.environ["YOGA_BUILD_LIB_ASSIMP"]
if "YOGA_BUILD_LIB_IRRXML" in os.environ:
    _LIB_IRRXML = os.environ["YOGA_BUILD_LIB_IRRXML"]
Exemplo n.º 32
0
    def finalize_options(self):

        build_ext.finalize_options(self)

        if self.compiler is None:
            compiler = get_default_compiler()
        else:
            compiler = self.compiler

        cfg_vars = sysconfig.get_config_vars()
        # Hack around OSX setting a -m flag
        if "macosx" in get_build_platform() and "CFLAGS" in cfg_vars:
            print("System C-flags:")
            print(cfg_vars["CFLAGS"])
            cflags = []
            for flag in cfg_vars["CFLAGS"].split():
                if flag in ["-m", "-isysroot"]:
                    continue
                # Remove sdk links
                if flag.endswith(".sdk"):
                    continue
                cflags.append(flag)
            cfg_vars["CFLAGS"] = " ".join(cflags)
            print("Editted C-flags:")
            print(cfg_vars["CFLAGS"])
        # Remove unsupported C-flags
        unsupported_flags = [
            "-fuse-linker-plugin", "-ffat-lto-objects", "-flto-partition=none"
        ]
        for key in ["CFLAGS", "LDFLAGS", "LDSHARED"]:
            if key in cfg_vars:
                print("System {0}:".format(key))
                print(cfg_vars[key])
                flags = []
                for flag in cfg_vars[key].split():
                    if flag in unsupported_flags:
                        continue
                    flags.append(flag)
                cfg_vars[key] = " ".join(flags)
                print("Editted {0}:".format(key))
                print(cfg_vars[key])

        if compiler == 'msvc':
            # Add msvc specific hacks

            # Sort linking issues with init exported symbols
            def _get_export_symbols(self, ext):
                return ext.export_symbols

            build_ext.get_export_symbols = _get_export_symbols

            if (sys.version_info.major, sys.version_info.minor) < (3, 3):
                # The check above is a nasty hack. We're using the python
                # version as a proxy for the MSVC version. 2008 doesn't
                # have stdint.h, so is needed. 2010 does.
                #
                # We need to add the path to msvc includes

                msvc_2008_path = (os.path.join(os.getcwd(), 'include',
                                               'msvc_2008'))

                if self.include_dirs is not None:
                    self.include_dirs.append(msvc_2008_path)

                else:
                    self.include_dirs = [msvc_2008_path]

            elif (sys.version_info.major, sys.version_info.minor) < (3, 5):
                # Actually, it seems that appveyor doesn't have a stdint that
                # works, so even for 2010 we use our own (hacked) version
                # of stdint.
                # This should be pretty safe in whatever case.
                msvc_2010_path = (os.path.join(os.getcwd(), 'include',
                                               'msvc_2010'))

                if self.include_dirs is not None:
                    self.include_dirs.append(msvc_2010_path)

                else:
                    self.include_dirs = [msvc_2010_path]

            # We need to prepend lib to all the library names
            _libraries = []
            for each_lib in self.libraries:
                _libraries.append('lib' + each_lib)

            self.libraries = _libraries
Exemplo n.º 33
0
    "UnpackYCC", "UnsharpMask", "XbmDecode", "XbmEncode", "ZipDecode",
    "ZipEncode", "TiffDecode", "Jpeg2KDecode", "Jpeg2KEncode", "BoxBlur",
    "QuantPngQuant", "codec_fd")

DEBUG = False


class DependencyException(Exception):
    pass


class RequiredDependencyException(Exception):
    pass


PLATFORM_MINGW = 'mingw' in ccompiler.get_default_compiler()
PLATFORM_PYPY = hasattr(sys, 'pypy_version_info')


def _dbg(s, tp=None):
    if DEBUG:
        if tp:
            print(s % tp)
            return
        print(s)


def _find_library_dirs_ldconfig():
    # Based on ctypes.util from Python 2

    if sys.platform.startswith("linux") or sys.platform.startswith("gnu"):
Exemplo n.º 34
0
                               source_name)
    module_suffix = iset if iset else "ref"

    return Extension(
        "nanolib._work_{}".format(module_suffix),
        include_dirs=[source_path],
        sources=[os.path.join("src", "nanolib-work-module", "work.c")] +
        SOURCE_FILES[source_name],
        extra_compile_args=get_compile_args(iset, build_platform))


EXTENSIONS_TO_BUILD = []

_machine = platform.machine()

_is_unix_compiler = get_default_compiler() == "unix"

# https://stackoverflow.com/a/45125525
_is_arm = _machine.startswith("arm")
_is_aarch64 = _machine.startswith("aarch64")
# 'AMD64' only appears on Windows
_is_x86 = _machine.startswith("x86") or _machine in ("i386", "i686", "AMD64")

if _is_x86:
    EXTENSIONS_TO_BUILD = [
        create_work_extension("sse", "avx", "x86"),
        create_work_extension("sse", "sse4_1", "x86"),
        create_work_extension("sse", "ssse3", "x86"),
        create_work_extension("sse", "sse2", "x86"),
        create_work_extension("ref", None, "x86")
    ]
Exemplo n.º 35
0
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
    def setUp(self):
        super(SysconfigTestCase, self).setUp()
        self.makefile = None

    def tearDown(self):
        if self.makefile is not None:
            os.unlink(self.makefile)
        self.cleanup_testfn()
        super(SysconfigTestCase, self).tearDown()

    def cleanup_testfn(self):
        if os.path.isfile(TESTFN):
            os.remove(TESTFN)
        elif os.path.isdir(TESTFN):
            shutil.rmtree(TESTFN)

    def test_get_config_h_filename(self):
        config_h = sysconfig.get_config_h_filename()
        self.assertTrue(os.path.isfile(config_h), config_h)

    def test_get_python_lib(self):
        # XXX doesn't work on Linux when Python was never installed before
        #self.assertTrue(os.path.isdir(lib_dir), lib_dir)
        # test for pythonxx.lib?
        self.assertNotEqual(sysconfig.get_python_lib(),
                            sysconfig.get_python_lib(prefix=TESTFN))

    def test_get_python_inc(self):
        inc_dir = sysconfig.get_python_inc()
        # This is not much of a test.  We make sure Python.h exists
        # in the directory returned by get_python_inc() but we don't know
        # it is the correct file.
        self.assertTrue(os.path.isdir(inc_dir), inc_dir)
        python_h = os.path.join(inc_dir, "Python.h")
        self.assertTrue(os.path.isfile(python_h), python_h)

    def test_get_config_vars(self):
        cvars = sysconfig.get_config_vars()
        self.assertIsInstance(cvars, dict)
        self.assertTrue(cvars)

    def test_srcdir(self):
        # See Issues #15322, #15364.
        srcdir = sysconfig.get_config_var('srcdir')

        self.assertTrue(os.path.isabs(srcdir), srcdir)
        self.assertTrue(os.path.isdir(srcdir), srcdir)

        if sysconfig.python_build:
            # The python executable has not been installed so srcdir
            # should be a full source checkout.
            Python_h = os.path.join(srcdir, 'Include', 'Python.h')
            self.assertTrue(os.path.exists(Python_h), Python_h)
            self.assertTrue(sysconfig._is_python_source_dir(srcdir))
        elif os.name == 'posix':
            self.assertEqual(
                os.path.dirname(sysconfig.get_makefile_filename()), srcdir)

    def test_srcdir_independent_of_cwd(self):
        # srcdir should be independent of the current working directory
        # See Issues #15322, #15364.
        srcdir = sysconfig.get_config_var('srcdir')
        cwd = os.getcwd()
        try:
            os.chdir('..')
            srcdir2 = sysconfig.get_config_var('srcdir')
        finally:
            os.chdir(cwd)
        self.assertEqual(srcdir, srcdir2)

    @unittest.skipUnless(get_default_compiler() == 'unix',
                         'not testing if default compiler is not unix')
    def test_customize_compiler(self):
        os.environ['AR'] = 'my_ar'
        os.environ['ARFLAGS'] = '-arflags'

        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        comp = compiler()
        sysconfig.customize_compiler(comp)
        self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')

    def test_parse_makefile_base(self):
        self.makefile = TESTFN
        fd = open(self.makefile, 'w')
        try:
            fd.write(r"CONFIG_ARGS=  '--arg1=optarg1' 'ENV=LIB'" '\n')
            fd.write('VAR=$OTHER\nOTHER=foo')
        finally:
            fd.close()
        d = sysconfig.parse_makefile(self.makefile)
        self.assertEqual(d, {
            'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
            'OTHER': 'foo'
        })

    def test_parse_makefile_literal_dollar(self):
        self.makefile = TESTFN
        fd = open(self.makefile, 'w')
        try:
            fd.write(r"CONFIG_ARGS=  '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
            fd.write('VAR=$OTHER\nOTHER=foo')
        finally:
            fd.close()
        d = sysconfig.parse_makefile(self.makefile)
        self.assertEqual(d, {
            'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
            'OTHER': 'foo'
        })

    def test_sysconfig_module(self):
        import sysconfig as global_sysconfig
        self.assertEqual(global_sysconfig.get_config_var('CFLAGS'),
                         sysconfig.get_config_var('CFLAGS'))
        self.assertEqual(global_sysconfig.get_config_var('LDFLAGS'),
                         sysconfig.get_config_var('LDFLAGS'))

    @unittest.skipIf(sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'),
                     'compiler flags customized')
    def test_sysconfig_compiler_vars(self):
        # On OS X, binary installers support extension module building on
        # various levels of the operating system with differing Xcode
        # configurations.  This requires customization of some of the
        # compiler configuration directives to suit the environment on
        # the installed machine.  Some of these customizations may require
        # running external programs and, so, are deferred until needed by
        # the first extension module build.  With Python 3.3, only
        # the Distutils version of sysconfig is used for extension module
        # builds, which happens earlier in the Distutils tests.  This may
        # cause the following tests to fail since no tests have caused
        # the global version of sysconfig to call the customization yet.
        # The solution for now is to simply skip this test in this case.
        # The longer-term solution is to only have one version of sysconfig.

        import sysconfig as global_sysconfig
        if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
            self.skipTest('compiler flags customized')
        self.assertEqual(global_sysconfig.get_config_var('LDSHARED'),
                         sysconfig.get_config_var('LDSHARED'))
        self.assertEqual(global_sysconfig.get_config_var('CC'),
                         sysconfig.get_config_var('CC'))

    @unittest.skipIf(
        sysconfig.get_config_var('EXT_SUFFIX') is None,
        'EXT_SUFFIX required for this test')
    def test_SO_deprecation(self):
        self.assertWarns(DeprecationWarning, sysconfig.get_config_var, 'SO')

    @unittest.skipIf(
        sysconfig.get_config_var('EXT_SUFFIX') is None,
        'EXT_SUFFIX required for this test')
    def test_SO_value(self):
        with check_warnings(('', DeprecationWarning)):
            self.assertEqual(sysconfig.get_config_var('SO'),
                             sysconfig.get_config_var('EXT_SUFFIX'))

    @unittest.skipIf(
        sysconfig.get_config_var('EXT_SUFFIX') is None,
        'EXT_SUFFIX required for this test')
    def test_SO_in_vars(self):
        vars = sysconfig.get_config_vars()
        self.assertIsNotNone(vars['SO'])
        self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
Exemplo n.º 36
0
        def _adjust_compiler(self):
            """
            This function detects broken compilers and switches to another.  If
            the environment variable CC is explicitly set, or a compiler is
            specified on the commandline, no override is performed -- the
            purpose here is to only override a default compiler.

            The specific compilers with problems are:

                * The default compiler in XCode-4.2, llvm-gcc-4.2,
                  segfaults when compiling wcslib.

            The set of broken compilers can be updated by changing the
            compiler_mapping variable.  It is a list of 2-tuples where the
            first in the pair is a regular expression matching the version of
            the broken compiler, and the second is the compiler to change to.
            """
            if 'CC' in os.environ:
                # Check that CC is not set to llvm-gcc-4.2
                c_compiler = os.environ['CC']

                try:
                    version = get_compiler_version(c_compiler)
                except OSError:
                    msg = textwrap.dedent("""
                        The C compiler set by the CC environment variable:

                            {compiler:s}

                        cannot be found or executed.
                        """.format(compiler=c_compiler))
                    log.warn(msg)
                    sys.exit(1)

                for broken, fixed in self._broken_compiler_mapping:
                    if re.match(broken, version):
                        msg = textwrap.dedent(
                            """Compiler specified by CC environment variable
                            ({compiler:s}:{version:s}) will fail to compile
                            {pkg:s}.

                            Please set CC={fixed:s} and try again.
                            You can do this, for example, by running:

                                CC={fixed:s} python setup.py <command>

                            where <command> is the command you ran.
                            """.format(compiler=c_compiler,
                                       version=version,
                                       pkg=self.package_name,
                                       fixed=fixed))
                        log.warn(msg)
                        sys.exit(1)

                # If C compiler is set via CC, and isn't broken, we are good to go. We
                # should definitely not try accessing the compiler specified by
                # ``sysconfig.get_config_var('CC')`` lower down, because this may fail
                # if the compiler used to compile Python is missing (and maybe this is
                # why the user is setting CC). For example, the official Python 2.7.3
                # MacOS X binary was compiled with gcc-4.2, which is no longer available
                # in XCode 4.
                return

            if self.compiler is not None:
                # At this point, self.compiler will be set only if a compiler
                # was specified in the command-line or via setup.cfg, in which
                # case we don't do anything
                return

            compiler_type = ccompiler.get_default_compiler()

            if compiler_type == 'unix':
                # We have to get the compiler this way, as this is the one that is
                # used if os.environ['CC'] is not set. It is actually read in from
                # the Python Makefile. Note that this is not necessarily the same
                # compiler as returned by ccompiler.new_compiler()
                c_compiler = sysconfig.get_config_var('CC')

                try:
                    version = get_compiler_version(c_compiler)
                except OSError:
                    msg = textwrap.dedent("""
                        The C compiler used to compile Python {compiler:s}, and
                        which is normally used to compile C extensions, is not
                        available. You can explicitly specify which compiler to
                        use by setting the CC environment variable, for example:

                            CC=gcc python setup.py <command>

                        or if you are using MacOS X, you can try:

                            CC=clang python setup.py <command>
                        """.format(compiler=c_compiler))
                    log.warn(msg)
                    sys.exit(1)

                for broken, fixed in self._broken_compiler_mapping:
                    if re.match(broken, version):
                        os.environ['CC'] = fixed
                        break
Exemplo n.º 37
0
def adjust_compiler():
    """
    This function detects broken compilers and switches to another.  If
    the environment variable CC is explicitly set, or a compiler is
    specified on the commandline, no override is performed -- the purpose
    here is to only override a default compiler.

    The specific compilers with problems are:

        * The default compiler in XCode-4.2, llvm-gcc-4.2,
          segfaults when compiling wcslib.

    The set of broken compilers can be updated by changing the
    compiler_mapping variable.  It is a list of 2-tuples where the
    first in the pair is a regular expression matching the version
    of the broken compiler, and the second is the compiler to change
    to.
    """

    from distutils import ccompiler, sysconfig
    import re

    compiler_mapping = [
        (b'i686-apple-darwin[0-9]*-llvm-gcc-4.2', 'clang')
        ]

    global _adjusted_compiler
    if _adjusted_compiler:
        return

    # Whatever the result of this function is, it only needs to be run once
    _adjusted_compiler = True

    if 'CC' in os.environ:

        # Check that CC is not set to llvm-gcc-4.2
        c_compiler = os.environ['CC']

        version = get_compiler_version(c_compiler)

        for broken, fixed in compiler_mapping:
            if re.match(broken, version):
                print("Compiler specified by CC environment variable ({0:s}: {1:s}) will fail to compile Astropy. Please set CC={2:s} and try again. You can do this for example by doing:\n\n    CC={2:s} python setup.py <command>\n\nwhere <command> is the command you ran.".format(c_compiler, version, fixed))
                sys.exit(1)

    if get_distutils_build_option('compiler'):
        return

    compiler_type = ccompiler.get_default_compiler()

    if compiler_type == 'unix':

        # We have to get the compiler this way, as this is the one that is
        # used if os.environ['CC'] is not set. It is actually read in from
        # the Python Makefile. Note that this is not necessarily the same
        # compiler as returned by ccompiler.new_compiler()
        c_compiler = sysconfig.get_config_var('CC')

        version = get_compiler_version(c_compiler)

        for broken, fixed in compiler_mapping:
            if re.match(broken, version):
                os.environ['CC'] = fixed
                break
Exemplo n.º 38
0
    def finalize_options(self):

        build_ext.finalize_options(self)

        if self.compiler is None:
            compiler = get_default_compiler()
        else:
            compiler = self.compiler

        # Hack around OSX setting a -m flag
        cfg_vars = sysconfig.get_config_vars()
        if "macosx" in get_build_platform() and "CFLAGS" in cfg_vars:
            print("System C-flags:")
            print(cfg_vars["CFLAGS"])
            cflags = list(set(cfg_vars["CFLAGS"].split()))
            if "-m" in cflags:
                cflags.remove("-m")
            if "-isysroot" in cflags:
                cflags.remove("-isysroot")
            # Remove sdk links
            sdk_flags = []
            for cflag in cflags:
                if cflag.endswith(".sdk"):
                    sdk_flags.append(cflag)
            for cflag in sdk_flags:
                cflags.remove(cflag)
            cflags = list(set(cflags))
            cfg_vars["CFLAGS"] = " ".join(cflags)
            print("Editted C-flags:")
            print(cfg_vars["CFLAGS"])
            os.environ["CFLAGS"] = " ".join(cflags)
        if compiler == 'msvc':
            # Add msvc specific hacks

            # Sort linking issues with init exported symbols
            def _get_export_symbols(self, ext):
                return ext.export_symbols

            build_ext.get_export_symbols = _get_export_symbols

            if (sys.version_info.major, sys.version_info.minor) < (3, 3):
                # The check above is a nasty hack. We're using the python
                # version as a proxy for the MSVC version. 2008 doesn't
                # have stdint.h, so is needed. 2010 does.
                #
                # We need to add the path to msvc includes

                msvc_2008_path = (
                    os.path.join(os.getcwd(), 'include', 'msvc_2008'))

                if self.include_dirs is not None:
                    self.include_dirs.append(msvc_2008_path)

                else:
                    self.include_dirs = [msvc_2008_path]

            elif (sys.version_info.major, sys.version_info.minor) < (3, 5):
                # Actually, it seems that appveyor doesn't have a stdint that
                # works, so even for 2010 we use our own (hacked) version
                # of stdint.
                # This should be pretty safe in whatever case.
                msvc_2010_path = (
                    os.path.join(os.getcwd(), 'include', 'msvc_2010'))

                if self.include_dirs is not None:
                    self.include_dirs.append(msvc_2010_path)

                else:
                    self.include_dirs = [msvc_2010_path]

            # We need to prepend lib to all the library names
            _libraries = []
            for each_lib in self.libraries:
                _libraries.append('lib' + each_lib)

            self.libraries = _libraries
Exemplo n.º 39
0
        plat = get_platname_32bit()
    sys.argv.extend(["--plat-name", plat])

ext_modules = [
    Extension(
        'cdiffer',
        sources=['src/cdiffer.cpp'],
        language="c++",
        include_dirs=["src"],
        extra_compile_args=[
            "/std:c++14" if os.name == "nt" else "-std=c++14",
            # "/IC:/usr/lib/boost",
        ]
    )]

if any("--debug" in x or "-g" in x for x in sys.argv) and get_default_compiler() == "msvc":
    ext_modules = [
        Extension(
            'cdiffer',
            sources=['src/cdiffer.cpp'],
            # Reason is Debuging Error "Access violation executing location 0x00000000" when using mwArray in Visual-C++
            undef_macros=["_DEBUG"],
            extra_compile_args=[
                # Reason https://docs.microsoft.com/ja-jp/cpp/build/reference/ltcg-link-time-code-generation?view=msvc-160
                "/GL",
                "/Wall", "/wd", "4514", "/wd 4820", "/wd 5045", "/wd 4100", "/wd 4191", "/wd 4710",
                # Reason unicode string crash #
                "/source-charset:utf-8",
                # Reason IDE warning link crash #
                "/FC",
                "/std:c++14",
Exemplo n.º 40
0
                          for file in all_cython_files])
snappy_ext_files.add('cython' + os.sep + 'SnapPy.c', cy_source_mod_time)
hp_snappy_ext_files.add('cython' + os.sep + 'SnapPyHP.cpp', cy_source_mod_time)
                         
for file in code:
    snappy_ext_files.add(file)
    hp_file = 'quad_double' + replace_ext(file, 'cpp')[len('kernel'):]
    assert os.path.exists(hp_file)
    hp_snappy_ext_files.add(hp_file, modtime(file))

for hp_file in hp_qd_code:
    hp_snappy_ext_files.add(hp_file)

# The compiler we will be using

cc = get_default_compiler()
for arg in sys.argv:
    if arg.startswith('--compiler='):
        cc = arg.split('=')[1]

# The SnapPy extension
snappy_extra_compile_args = []
snappy_extra_link_args = []
if sys.platform == 'win32':
    if cc == 'msvc':
        snappy_extra_compile_args.append('/EHsc')
        # Uncomment to get debugging symbols for msvc.
        # snappy_extra_compile_args += ['/DDEBUG', '/Zi',
        #                              '/FdSnapPy.cp37-win_amd64.pdb']
    else:
        if sys.version_info.major == 2:
Exemplo n.º 41
0
# Import the version string.
# Any .py files that are used at install time must be registered in
# obspy.core.tests.test_util_misc.UtilMiscTestCase.test_no_obspy_imports!
UTIL_PATH = os.path.join(SETUP_DIRECTORY, "obspy", "core", "util")
sys.path.insert(0, UTIL_PATH)
from version import get_git_version  # @UnresolvedImport
sys.path.pop(0)

LOCAL_PATH = os.path.join(SETUP_DIRECTORY, "setup.py")
DOCSTRING = __doc__.split("\n")

# check for MSVC
if platform.system() == "Windows" and ('msvc' in sys.argv
                                       or '-c' not in sys.argv
                                       and get_default_compiler() == 'msvc'):
    IS_MSVC = True
else:
    IS_MSVC = False

# Use system libraries? Set later...
EXTERNAL_EVALRESP = False
EXTERNAL_LIBMSEED = False

# Hard dependencies needed to install/run ObsPy.
INSTALL_REQUIRES = [
    'numpy>=1.15.0',
    'scipy>=1.0.0',
    'matplotlib>=3.2.0',
    'lxml',
    'setuptools',
Exemplo n.º 42
0
    "QuantPngQuant",
    "codec_fd",
)

DEBUG = False


class DependencyException(Exception):
    pass


class RequiredDependencyException(Exception):
    pass


PLATFORM_MINGW = "mingw" in ccompiler.get_default_compiler()
PLATFORM_PYPY = hasattr(sys, "pypy_version_info")


def _dbg(s, tp=None):
    if DEBUG:
        if tp:
            print(s % tp)
            return
        print(s)


def _find_library_dirs_ldconfig():
    # Based on ctypes.util from Python 2

    if sys.platform.startswith("linux") or sys.platform.startswith("gnu"):
Exemplo n.º 43
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from distutils.core import setup, Extension
from distutils.ccompiler import get_default_compiler

# get the version from the source
CLIENT_VERSION = "unknown"
exec(open('mlat/client/version.py').read())

more_warnings = False
extra_compile_args = []
if more_warnings and get_default_compiler() == 'unix':
    # let's assume this is GCC
    extra_compile_args.append('-Wpointer-arith')

modes_ext = Extension(
    '_modes',
    sources=['_modes.c', 'modes_reader.c', 'modes_message.c', 'modes_crc.c'],
    extra_compile_args=extra_compile_args)

setup(name='MlatClient',
      version=CLIENT_VERSION,
      description='Multilateration client package',
      author='Oliver Jowett',
      author_email='*****@*****.**',
      packages=['mlat', 'mlat.client', 'flightaware', 'flightaware.client'],
      ext_modules=[modes_ext],
Exemplo n.º 44
0
    os.remove("MANIFEST")

with open("README.md") as file:
    long_description = file.read()

if check_for_openmp():
    omp_args = ["-fopenmp"]
else:
    omp_args = []

if os.name == "nt":
    std_libs = []
else:
    std_libs = ["m"]

if get_default_compiler() == "msvc":
    CPP14_FLAG = ["/std:c++14"]
else:
    CPP14_FLAG = ["--std=c++14"]

cythonize_aliases = {
    "LIB_DIR":
    "yt/utilities/lib/",
    "LIB_DIR_EWAH": ["yt/utilities/lib/", "yt/utilities/lib/ewahboolarray/"],
    "LIB_DIR_GEOM": ["yt/utilities/lib/", "yt/geometry/"],
    "LIB_DIR_GEOM_ARTIO": [
        "yt/utilities/lib/",
        "yt/geometry/",
        "yt/frontends/artio/artio_headers/",
    ],
    "STD_LIBS":
    def run(self):
        """Implementation of the run() function.

        See class ditutils.cmd.Command for background.
        """
        # At this point, 'self.compiler' is None or a string,  but this
        # will change while running the corresponding distutils command
        self.compiler_name = self.compiler
        if self.compiler_name is None:
            # Then try to get the default compiler name
            from distutils.ccompiler import get_default_compiler
            self.compiler_name = get_default_compiler()

        # Now process all extensions in the given order
        for ext in self.extensions[:]:
            if isinstance(ext, CustomBuildStep):
                # Then we execute a sequence of subprocesses or a functions
                print("\nExecuting custom build step '%s'" % ext.name)
                for args in ext.function_list:
                    if isinstance(args[0], str):
                        # Then execute a subprocess
                        print(" ".join(map(str, args)))
                        if subprocess.call(list(map(str, args))) != 0:
                            err = "Subprocess %s failed"
                            raise ValueError(err % args[0])
                    else:
                        # Then execute a python function
                        args[0](*(args[1:]))
            elif isinstance(ext, SharedExtension):
                # Then we build a shared librry using method
                # self.build_shared_extension()

                # Evaluate extra_compile_args and extra_link_args to a string
                ext.extra_compile_args = self.eval_extra_args(
                    ext.extra_compile_args)
                ext.extra_link_args = self.eval_extra_args(ext.extra_link_args)
                print("\nBuilding shared library '%s'" % ext.name)
                self.build_shared_extension(ext)
            elif isinstance(ext, str):
                # A string is taken as a comment
                pass
            else:
                # A standard Extension is build in the same way as in the
                # base class. We rely on the fact that setuptools always
                # builds the python extension in the build directory,
                # even if the 'inplace' option has not been set.

                # Evaluate extra_compile_args and extra_link_args to a string
                ext.extra_compile_args = self.eval_extra_args(
                    ext.extra_compile_args)
                ext.extra_link_args = self.eval_extra_args(ext.extra_link_args)
                # Save the old value of self.compiler because the self.run()
                # method appears to change it so that it self.run() method
                # cannot be applied twice.
                compiler = self.compiler
                extensions = self.extensions
                self.extensions = [ext]  # Build one extension only
                inplace = self.inplace
                self.inplace = True  # Always bild inplace
                force = self.force
                self.force = True  # Always force building
                # Run the corresponding mathod of the base class
                super(BuildExtCmd, self).run()
                # Restore old attributes
                self.extensions = extensions
                self.inplace = inplace
                self.force = True
                self.compiler = compiler
Exemplo n.º 46
0
    def finalize_options(self):
        build_ext.finalize_options(self)
        self.set_undefined_options('build', ('static','static'))

        self.include_dirs = self.include_dirs or []
        self.library_dirs = self.library_dirs or []
        self.define = self.define or []
        self.libraries = self.libraries or []

        extra_compile_args = []
        extra_link_args = []

        compiler = self.compiler or get_default_compiler()

        if compiler == 'msvc':
            try:
                QL_INSTALL_DIR = os.environ['QL_DIR']
                self.include_dirs += [QL_INSTALL_DIR]
                self.library_dirs += [os.path.join(QL_INSTALL_DIR, 'lib')]
            except KeyError:
                print('warning: unable to detect QuantLib installation')

            if 'INCLUDE' in os.environ:
                dirs = [dir for dir in os.environ['INCLUDE'].split(';')]
                self.include_dirs += [ d for d in dirs if d.strip() ]
            if 'LIB' in os.environ:
                dirs = [dir for dir in os.environ['LIB'].split(';')]
                self.library_dirs += [ d for d in dirs if d.strip() ]
            dbit = round(math.log(sys.maxsize, 2) + 1)
            if dbit == 64:
                machinetype = '/machine:x64'
            else:
                machinetype = '/machine:x86'
            self.define += [('__WIN32__', None), ('WIN32', None),
                            ('NDEBUG', None), ('_WINDOWS', None),
                            ('NOMINMAX', None)]
            extra_compile_args = ['/GR', '/FD', '/Zm250', '/EHsc', '/bigobj' ]
            extra_link_args = ['/subsystem:windows', machinetype]

            if self.debug:
                if self.static:
                    extra_compile_args.append('/MTd')
                else:
                    extra_compile_args.append('/MDd')
            else:
                if self.static:
                    extra_compile_args.append('/MT')
                else:
                    extra_compile_args.append('/MD')

        elif compiler == 'unix':
            ql_compile_args = \
                os.popen('quantlib-config --cflags').read()[:-1].split()
            ql_link_args = \
                os.popen('quantlib-config --libs').read()[:-1].split()
            self.define += [ (arg[2:],None) for arg in ql_compile_args
                             if arg.startswith('-D') ]
            self.include_dirs += [ arg[2:] for arg in ql_compile_args
                                   if arg.startswith('-I') ]
            self.library_dirs += [ arg[2:] for arg in ql_link_args
                                   if arg.startswith('-L') ]
            self.libraries += [ arg[2:] for arg in ql_link_args
                                if arg.startswith('-l') ]

            extra_compile_args = [ arg for arg in ql_compile_args
                                   if not arg.startswith('-D')
                                   if not arg.startswith('-I') ] \
                                   + [ '-Wno-unused' ]
            if 'CXXFLAGS' in os.environ:
                extra_compile_args += os.environ['CXXFLAGS'].split()

            extra_link_args = [ arg for arg in ql_link_args
                                if not arg.startswith('-L')
                                if not arg.startswith('-l') ]

        else:
            pass

        for ext in self.extensions:
            ext.extra_compile_args = ext.extra_compile_args or []
            ext.extra_compile_args += extra_compile_args

            ext.extra_link_args = ext.extra_link_args or []
            ext.extra_link_args += extra_link_args
Exemplo n.º 47
0
def compile_c_module(cfiles, modbasename, eci, tmpdir=None):
    #try:
    #    from distutils.log import set_threshold
    #    set_threshold(10000)
    #except ImportError:
    #    print "ERROR IMPORTING"
    #    pass
    cfiles = [py.path.local(f) for f in cfiles]
    if tmpdir is None:
        tmpdir = udir.join("module_cache").ensure(dir=1)
    num = 0
    cfiles += eci.separate_module_files
    include_dirs = list(eci.include_dirs)
    include_dirs.append(py.path.local(pypydir).join('translator', 'c'))
    library_dirs = list(eci.library_dirs)
    if sys.platform == 'darwin':  # support Fink & Darwinports
        for s in ('/sw/', '/opt/local/'):
            if s + 'include' not in include_dirs and \
               os.path.exists(s + 'include'):
                include_dirs.append(s + 'include')
            if s + 'lib' not in library_dirs and \
               os.path.exists(s + 'lib'):
                library_dirs.append(s + 'lib')

    num = 0
    modname = modbasename
    while 1:
        if not tmpdir.join(modname + so_ext).check():
            break
        num += 1
        modname = '%s_%d' % (modbasename, num)

    lastdir = tmpdir.chdir()
    libraries = eci.libraries
    ensure_correct_math()
    try:
        if debug: print "modname", modname
        c = stdoutcapture.Capture(mixed_out_err=True)
        try:
            try:
                if compiler_command():
                    # GCC-ish options only
                    from distutils import sysconfig
                    gcv = sysconfig.get_config_vars()
                    cmd = compiler_command().replace('%s',
                                                     str(tmpdir.join(modname)))
                    for dir in [gcv['INCLUDEPY']] + list(include_dirs):
                        cmd += ' -I%s' % dir
                    for dir in library_dirs:
                        cmd += ' -L%s' % dir
                    os.system(cmd)
                else:
                    from distutils.dist import Distribution
                    from distutils.extension import Extension
                    from distutils.ccompiler import get_default_compiler
                    saved_environ = os.environ.items()
                    try:
                        # distutils.core.setup() is really meant for end-user
                        # interactive usage, because it eats most exceptions and
                        # turn them into SystemExits.  Instead, we directly
                        # instantiate a Distribution, which also allows us to
                        # ignore unwanted features like config files.
                        extra_compile_args = []
                        # ensure correct math on windows
                        if sys.platform == 'win32':
                            extra_compile_args.append(
                                '/Op')  # get extra precision
                        if get_default_compiler() == 'unix':
                            old_version = False
                            try:
                                g = os.popen('gcc --version', 'r')
                                verinfo = g.read()
                                g.close()
                            except (OSError, IOError):
                                pass
                            else:
                                old_version = verinfo.startswith('2')
                            if not old_version:
                                extra_compile_args.extend([
                                    "-Wno-unused-label", "-Wno-unused-variable"
                                ])
                        attrs = {
                            'name':
                            "testmodule",
                            'ext_modules': [
                                Extension(
                                    modname,
                                    [str(cfile) for cfile in cfiles],
                                    include_dirs=include_dirs,
                                    library_dirs=library_dirs,
                                    extra_compile_args=extra_compile_args,
                                    libraries=list(libraries),
                                )
                            ],
                            'script_name':
                            'setup.py',
                            'script_args':
                            ['-q', 'build_ext', '--inplace', '--force'],
                        }
                        dist = Distribution(attrs)
                        if not dist.parse_command_line():
                            raise ValueError, "distutils cmdline parse error"
                        dist.run_commands()
                    finally:
                        for key, value in saved_environ:
                            if os.environ.get(key) != value:
                                os.environ[key] = value
            finally:
                foutput, foutput = c.done()
                data = foutput.read()
                if data:
                    fdump = open("%s.errors" % modname, "w")
                    fdump.write(data)
                    fdump.close()
            # XXX do we need to do some check on fout/ferr?
            # XXX not a nice way to import a module
        except:
            print >> sys.stderr, data
            raise
    finally:
        lastdir.chdir()
    return str(tmpdir.join(modname) + so_ext)
Exemplo n.º 48
0
 def get_compiler(self):
     return self.compiler or get_default_compiler()
Exemplo n.º 49
0
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
    def setUp(self):
        super(SysconfigTestCase, self).setUp()
        self.makefile = None

    def tearDown(self):
        if self.makefile is not None:
            os.unlink(self.makefile)
        self.cleanup_testfn()
        super(SysconfigTestCase, self).tearDown()

    def cleanup_testfn(self):
        if os.path.isfile(TESTFN):
            os.remove(TESTFN)
        elif os.path.isdir(TESTFN):
            shutil.rmtree(TESTFN)

    def test_get_config_h_filename(self):
        config_h = sysconfig.get_config_h_filename()
        self.assertTrue(os.path.isfile(config_h), config_h)

    def test_get_python_lib(self):
        # XXX doesn't work on Linux when Python was never installed before
        #self.assertTrue(os.path.isdir(lib_dir), lib_dir)
        # test for pythonxx.lib?
        self.assertNotEqual(sysconfig.get_python_lib(),
                            sysconfig.get_python_lib(prefix=TESTFN))

    def test_get_config_vars(self):
        cvars = sysconfig.get_config_vars()
        self.assertIsInstance(cvars, dict)
        self.assertTrue(cvars)

    def test_srcdir(self):
        # See Issues #15322, #15364.
        srcdir = sysconfig.get_config_var('srcdir')

        self.assertTrue(os.path.isabs(srcdir), srcdir)
        self.assertTrue(os.path.isdir(srcdir), srcdir)

        if sysconfig.python_build:
            # The python executable has not been installed so srcdir
            # should be a full source checkout.
            Python_h = os.path.join(srcdir, 'Include', 'Python.h')
            self.assertTrue(os.path.exists(Python_h), Python_h)
            self.assertTrue(sysconfig._is_python_source_dir(srcdir))
        elif os.name == 'posix':
            self.assertEqual(
                os.path.dirname(sysconfig.get_makefile_filename()),
                srcdir)

    def test_srcdir_independent_of_cwd(self):
        # srcdir should be independent of the current working directory
        # See Issues #15322, #15364.
        srcdir = sysconfig.get_config_var('srcdir')
        cwd = os.getcwd()
        try:
            os.chdir('..')
            srcdir2 = sysconfig.get_config_var('srcdir')
        finally:
            os.chdir(cwd)
        self.assertEqual(srcdir, srcdir2)

    def customize_compiler(self):
        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        sysconfig_vars = {
            'AR': 'sc_ar',
            'CC': 'sc_cc',
            'CXX': 'sc_cxx',
            'ARFLAGS': '--sc-arflags',
            'CFLAGS': '--sc-cflags',
            'CCSHARED': '--sc-ccshared',
            'LDSHARED': 'sc_ldshared',
            'SHLIB_SUFFIX': 'sc_shutil_suffix',

            # On macOS, disable _osx_support.customize_compiler()
            'CUSTOMIZED_OSX_COMPILER': 'True',
        }

        comp = compiler()
        with contextlib.ExitStack() as cm:
            for key, value in sysconfig_vars.items():
                cm.enter_context(swap_item(sysconfig._config_vars, key, value))
            sysconfig.customize_compiler(comp)

        return comp

    @unittest.skipUnless(get_default_compiler() == 'unix',
                         'not testing if default compiler is not unix')
    def test_customize_compiler(self):
        # Make sure that sysconfig._config_vars is initialized
        sysconfig.get_config_vars()

        os.environ['AR'] = 'env_ar'
        os.environ['CC'] = 'env_cc'
        os.environ['CPP'] = 'env_cpp'
        os.environ['CXX'] = 'env_cxx --env-cxx-flags'
        os.environ['LDSHARED'] = 'env_ldshared'
        os.environ['LDFLAGS'] = '--env-ldflags'
        os.environ['ARFLAGS'] = '--env-arflags'
        os.environ['CFLAGS'] = '--env-cflags'
        os.environ['CPPFLAGS'] = '--env-cppflags'

        comp = self.customize_compiler()
        self.assertEqual(comp.exes['archiver'],
                         'env_ar --env-arflags')
        self.assertEqual(comp.exes['preprocessor'],
                         'env_cpp --env-cppflags')
        self.assertEqual(comp.exes['compiler'],
                         'env_cc --sc-cflags --env-cflags --env-cppflags')
        self.assertEqual(comp.exes['compiler_so'],
                         ('env_cc --sc-cflags '
                          '--env-cflags ''--env-cppflags --sc-ccshared'))
        self.assertEqual(comp.exes['compiler_cxx'],
                         'env_cxx --env-cxx-flags')
        self.assertEqual(comp.exes['linker_exe'],
                         'env_cc')
        self.assertEqual(comp.exes['linker_so'],
                         ('env_ldshared --env-ldflags --env-cflags'
                          ' --env-cppflags'))
        self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')

        del os.environ['AR']
        del os.environ['CC']
        del os.environ['CPP']
        del os.environ['CXX']
        del os.environ['LDSHARED']
        del os.environ['LDFLAGS']
        del os.environ['ARFLAGS']
        del os.environ['CFLAGS']
        del os.environ['CPPFLAGS']

        comp = self.customize_compiler()
        self.assertEqual(comp.exes['archiver'],
                         'sc_ar --sc-arflags')
        self.assertEqual(comp.exes['preprocessor'],
                         'sc_cc -E')
        self.assertEqual(comp.exes['compiler'],
                         'sc_cc --sc-cflags')
        self.assertEqual(comp.exes['compiler_so'],
                         'sc_cc --sc-cflags --sc-ccshared')
        self.assertEqual(comp.exes['compiler_cxx'],
                         'sc_cxx')
        self.assertEqual(comp.exes['linker_exe'],
                         'sc_cc')
        self.assertEqual(comp.exes['linker_so'],
                         'sc_ldshared')
        self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')

    def test_parse_makefile_base(self):
        self.makefile = TESTFN
        fd = open(self.makefile, 'w')
        try:
            fd.write(r"CONFIG_ARGS=  '--arg1=optarg1' 'ENV=LIB'" '\n')
            fd.write('VAR=$OTHER\nOTHER=foo')
        finally:
            fd.close()
        d = sysconfig.parse_makefile(self.makefile)
        self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
                             'OTHER': 'foo'})

    def test_parse_makefile_literal_dollar(self):
        self.makefile = TESTFN
        fd = open(self.makefile, 'w')
        try:
            fd.write(r"CONFIG_ARGS=  '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
            fd.write('VAR=$OTHER\nOTHER=foo')
        finally:
            fd.close()
        d = sysconfig.parse_makefile(self.makefile)
        self.assertEqual(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
                             'OTHER': 'foo'})


    def test_sysconfig_module(self):
        import sysconfig as global_sysconfig
        self.assertEqual(global_sysconfig.get_config_var('CFLAGS'),
                         sysconfig.get_config_var('CFLAGS'))
        self.assertEqual(global_sysconfig.get_config_var('LDFLAGS'),
                         sysconfig.get_config_var('LDFLAGS'))

    @unittest.skipIf(sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'),
                     'compiler flags customized')
    def test_sysconfig_compiler_vars(self):
        # On OS X, binary installers support extension module building on
        # various levels of the operating system with differing Xcode
        # configurations.  This requires customization of some of the
        # compiler configuration directives to suit the environment on
        # the installed machine.  Some of these customizations may require
        # running external programs and, so, are deferred until needed by
        # the first extension module build.  With Python 3.3, only
        # the Distutils version of sysconfig is used for extension module
        # builds, which happens earlier in the Distutils tests.  This may
        # cause the following tests to fail since no tests have caused
        # the global version of sysconfig to call the customization yet.
        # The solution for now is to simply skip this test in this case.
        # The longer-term solution is to only have one version of sysconfig.

        import sysconfig as global_sysconfig
        if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
            self.skipTest('compiler flags customized')
        self.assertEqual(global_sysconfig.get_config_var('LDSHARED'),
                         sysconfig.get_config_var('LDSHARED'))
        self.assertEqual(global_sysconfig.get_config_var('CC'),
                         sysconfig.get_config_var('CC'))

    @requires_subprocess()
    def test_customize_compiler_before_get_config_vars(self):
        # Issue #21923: test that a Distribution compiler
        # instance can be called without an explicit call to
        # get_config_vars().
        with open(TESTFN, 'w') as f:
            f.writelines(textwrap.dedent('''\
                from distutils.core import Distribution
                config = Distribution().get_command_obj('config')
                # try_compile may pass or it may fail if no compiler
                # is found but it should not raise an exception.
                rc = config.try_compile('int x;')
                '''))
        p = subprocess.Popen([str(sys.executable), TESTFN],
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                universal_newlines=True)
        outs, errs = p.communicate()
        self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)
Exemplo n.º 50
0
Arquivo: setup.py Projeto: cajal/cmt
import os
import sys
import numpy

sys.path.append('./code')

from distutils.core import setup, Extension
from distutils.ccompiler import CCompiler, get_default_compiler
from utils import parallelCCompiler
from numpy.distutils.intelccompiler import IntelCCompiler
from numpy import any

INTEL_PATH = '/opt/intel/'

# heuristic for figuring out which compiler is being used (icc, gcc)
if any(['intel' in arg for arg in sys.argv]) or 'intel' in get_default_compiler():
	# icc-specific options
	include_dirs=[
		os.path.join(INTEL_PATH, 'mkl/include')]
	library_dirs=[
		os.path.join(INTEL_PATH, 'mkl/lib'),
		os.path.join(INTEL_PATH, 'lib')]
	libraries = [
		'mkl_intel_lp64',
		'mkl_intel_thread',
		'mkl_core',
		'mkl_def',
		'iomp5']
	extra_compile_args = [
		'-DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS',
		'-DEIGEN_USE_MKL_ALL',
Exemplo n.º 51
0
from __future__ import division
#from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import

import os, sys
from os.path import join

# We require Python v2.7 or newer
if sys.version_info[:2] < (2, 7):
    raise RuntimeError("This requires Python v2.7 or newer")

# Prepare for compiling the source code
from distutils.ccompiler import get_default_compiler
import numpy
compiler_name = get_default_compiler(
)  # TODO: this isn't the compiler that will necessarily be used, but is a good guess...
compiler_opt = {
    'msvc': [
        '/D_SCL_SECURE_NO_WARNINGS', '/EHsc', '/O2',
        '/DNPY_NO_DEPRECATED_API=7', '/bigobj', '/openmp'
    ],
    # TODO: older versions of gcc need -std=c++0x instead of -std=c++11
    'unix': ['-std=c++11', '-O3', '-DNPY_NO_DEPRECATED_API=7',
             '-fopenmp'],  # gcc/clang (whatever is system default)
    'mingw32': ['-std=c++11', '-O3', '-DNPY_NO_DEPRECATED_API=7', '-fopenmp'],
    'cygwin': ['-std=c++11', '-O3', '-DNPY_NO_DEPRECATED_API=7', '-fopenmp'],
}
linker_opt = {
    'msvc': [],
    'unix': ['-fopenmp'],  # gcc/clang (whatever is system default)
    'mingw32': ['-fopenmp'],
Exemplo n.º 52
0
 def get_compiler(self):
     """Return the C compiler used for building the extension."""
     return self.compiler or get_default_compiler()
Exemplo n.º 53
0
ccompiler = None
for arg in sys.argv[1:]:
    if arg.startswith('--compiler='):
        defcomp = list(getattr(cc, '_default_compilers'))
        val = arg.split('=', 1)[1]
        for i, compspec in enumerate(defcomp):
            if compspec[0] == os.name:
                defcomp[i] = (os.name, val)
                sys.argv.remove(arg)
                cc._default_compilers = tuple(defcomp)
                ccompiler = val
                break

# Obtain C compiler ID if unspecified
if ccompiler is None:
    ccompiler = cc.get_default_compiler()

# Prevent linking against MSVCRxx.dll on Windows when compiled with mingw32
if win_platform:

    class IntWithLstrip(int):
        def lstrip(self, _=None):
            return self

    dummy_msvc_runtime_library = False
    save_msvc_runtime_version = numpy.distutils.misc_util.msvc_runtime_version

    def msvc_runtime_version_override():
        if dummy_msvc_runtime_library:
            return
        return save_msvc_runtime_version()
Exemplo n.º 54
0
class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
    def test_set_executables(self):
        class MyCCompiler(CCompiler):
            executables = {'compiler': '', 'compiler_cxx': '', 'linker': ''}

        compiler = MyCCompiler()

        # set executable as list
        compiler.set_executables(compiler=['env', 'OMPI_MPICC=clang', 'mpicc'])
        self.assertEqual(compiler.compiler,
                         ['env', 'OMPI_MPICC=clang', 'mpicc'])

        # set executable as string
        compiler.set_executables(compiler_cxx='env OMPI_MPICXX=clang++ mpicxx')
        self.assertEqual(compiler.compiler_cxx,
                         ['env', 'OMPI_MPICXX=clang++', 'mpicxx'])

        # set executable as unicode string
        compiler.set_executables(linker=u'env OMPI_MPICXX=clang++ mpiCC')
        self.assertEqual(compiler.linker,
                         [u'env', u'OMPI_MPICXX=clang++', u'mpiCC'])

    def test_gen_lib_options(self):
        compiler = FakeCompiler()
        libdirs = ['lib1', 'lib2']
        runlibdirs = ['runlib1']
        libs = [os.path.join('dir', 'name'), 'name2']

        opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)
        wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found', '-lname2']
        self.assertEqual(opts, wanted)

    def test_debug_print(self):
        class MyCCompiler(CCompiler):
            executables = {}

        compiler = MyCCompiler()
        with captured_stdout() as stdout:
            compiler.debug_print('xxx')
        stdout.seek(0)
        self.assertEqual(stdout.read(), '')

        debug.DEBUG = True
        try:
            with captured_stdout() as stdout:
                compiler.debug_print('xxx')
            stdout.seek(0)
            self.assertEqual(stdout.read(), 'xxx\n')
        finally:
            debug.DEBUG = False

    @unittest.skipUnless(get_default_compiler() == 'unix',
                         'not testing if default compiler is not unix')
    def test_customize_compiler(self):
        os.environ['AR'] = 'my_ar'
        os.environ['ARFLAGS'] = '-arflags'

        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        comp = compiler()
        customize_compiler(comp)
        self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
Exemplo n.º 55
0
    os.chdir(build_dir)
    return ret_code

if sys.platform != 'darwin' and sys.platform != 'win32':
    build_dependency('s2n')
build_dependency('aws-c-common')
build_dependency('aws-c-io')
build_dependency('aws-c-mqtt')
build_dependency('aws-c-cal')
build_dependency('aws-c-http')

os.chdir(current_dir)

from distutils.ccompiler import get_default_compiler
compiler_type = get_default_compiler()

aws_c_libs = ['aws-c-mqtt', 'aws-c-io', 'aws-c-common', 'aws-c-cal', 'aws-c-http']

def get_from_env(key):
    try:
        return os.environ[key]
    except:
        return ""

# fetch the CFLAGS/LDFLAGS from env
cflags = get_from_env('CFLAGS').split()
ldflags = get_from_env('LDFLAGS').split()

include_dirs = [path.join(dep_install_path, 'include')]
libraries = list(aws_c_libs)
 def get_compiler(self):
     return self.compiler or get_default_compiler()
Exemplo n.º 57
0
import os
import distutils.ccompiler as dist_ccomp
import distutils.command.build as dist_build
#
from setuptools import setup, Extension
from setuptools.command.install import install


def rename_files(dirpath, fromsuf, tosuf):
    for fn in os.listdir(dirpath):
        if fn.endswith(fromsuf):
            os.rename(dirpath + fn, dirpath + fn[:-len(fromsuf)] + tosuf)


if dist_ccomp.get_default_compiler() == 'msvc':
    # MSVC requires C files to be actually C++ in order to compile them with
    # support for "modern" C features
    print('compiling C extensions with MSVC: renaming .c to .cc')
    rename_files('./C_alg/', '.c', '.cc')
    rename_files('./C_py/', '.c', '.cc')
    pycomp128 = Extension('pycomp128',
                          sources=['C_py/pycomp128.cc', 'C_alg/comp128.cc'])
    pykasumi = Extension('pykasumi',
                         sources=['C_py/pykasumi.cc', 'C_alg/Kasumi.cc'])
    pysnow = Extension('pysnow',
                       sources=['C_py/pysnow.cc', 'C_alg/SNOW_3G.cc'])
    pyzuc = Extension('pyzuc', sources=['C_py/pyzuc.cc', 'C_alg/ZUC.cc'])
else:
    pycomp128 = Extension('pycomp128',
                          sources=['C_py/pycomp128.c', 'C_alg/comp128.c'])
Exemplo n.º 58
0
try:
    import nose
except ImportError:
    nose = None

# local script imports:
from buildutils import (discover_settings, v_str, localpath, savepickle, loadpickle, detect_zmq,
                        warn, fatal, copy_and_patch_libzmq)

#-----------------------------------------------------------------------------
# Flags
#-----------------------------------------------------------------------------
# ignore unused-function and strict-aliasing warnings, of which there
# will be many from the Cython generated code:
# note that this is only for gcc-style compilers
if get_default_compiler() in ('unix', 'mingw32'):
    ignore_common_warnings=True
else:
    ignore_common_warnings=False

# the minimum zeromq version this will work against:
min_zmq = (2,1,4)

# set dylib ext:
if sys.platform.startswith('win'):
    lib_ext = '.dll'
elif sys.platform == 'darwin':
    lib_ext = '.1.dylib'
else:
    lib_ext = '.so.1'
Exemplo n.º 59
0
def postop():
    if dist_ccomp.get_default_compiler() == 'msvc':
        # reverting the renaming
        rename_files('./C_alg/', '.cc', '.c')
        rename_files('./C_py/', '.cc', '.c')