Exemplo n.º 1
0
Arquivo: setup.py Projeto: uSEEet/PyAV
def new_compiler(*args, **kwargs):
    """Create a C compiler.

    :param bool silent: Eat all stdio? Defaults to ``True``.

    All other arguments passed to ``distutils.ccompiler.new_compiler``.

    """
    cc = _new_compiler(*args, **kwargs)
    make_silent = True
    # If MSVC10, initialize the compiler here and add /MANIFEST to linker flags.
    # See Python issue 4431 (https://bugs.python.org/issue4431)
    if is_msvc(cc):
        from distutils.msvc9compiler import get_build_version
        if get_build_version() == 10:
            cc.initialize()
            for ldflags in [cc.ldflags_shared, cc.ldflags_shared_debug]:
                unique_extend(ldflags, ['/MANIFEST'])
        # If MSVC14, do not silence. As msvc14 requires some custom
        # steps before the process is spawned, we can't monkey-patch this.
        elif get_build_version() == 14:
            make_silent = False
    # monkey-patch compiler to suppress stdout and stderr.
    if make_silent and kwargs.pop('silent', True):
        cc.spawn = _CCompiler_spawn_silent
    return cc
Exemplo n.º 2
0
def new_compiler(*args, **kwargs):
    """Create a C compiler.

    :param bool silent: Eat all stdio? Defaults to ``True``.

    All other arguments passed to ``distutils.ccompiler.new_compiler``.

    """
    make_silent = kwargs.pop('silent', True)
    cc = _new_compiler(*args, **kwargs)
    # If MSVC10, initialize the compiler here and add /MANIFEST to linker flags.
    # See Python issue 4431 (https://bugs.python.org/issue4431)
    if is_msvc(cc):
        from distutils.msvc9compiler import get_build_version
        if get_build_version() == 10:
            cc.initialize()
            for ldflags in [cc.ldflags_shared, cc.ldflags_shared_debug]:
                unique_extend(ldflags, ['/MANIFEST'])
        # If MSVC14, do not silence. As msvc14 requires some custom
        # steps before the process is spawned, we can't monkey-patch this.
        elif get_build_version() == 14:
            make_silent = False
    # monkey-patch compiler to suppress stdout and stderr.
    if make_silent:
        cc.spawn = _CCompiler_spawn_silent
    return cc
Exemplo n.º 3
0
 def setup_class(cls):
     cls.module = None
     from pypy.module.test_lib_pypy.cffi_tests.udir import udir
     udir.join('testownlib.c').write(SOURCE)
     if sys.platform == 'win32':
         import os
         # did we already build it?
         if os.path.exists(str(udir.join('testownlib.dll'))):
             cls.module = str(udir.join('testownlib.dll'))
             return
         # try (not too hard) to find the version used to compile this python
         # no mingw
         from distutils.msvc9compiler import get_build_version
         version = get_build_version()
         toolskey = "VS%0.f0COMNTOOLS" % version
         toolsdir = os.environ.get(toolskey, None)
         if toolsdir is None:
             return
         productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
         productdir = os.path.abspath(productdir)
         vcvarsall = os.path.join(productdir, "vcvarsall.bat")
         # 64?
         arch = 'x86'
         if sys.maxsize > 2**32:
             arch = 'amd64'
         if os.path.isfile(vcvarsall):
             cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
                     ' /LD /Fetestownlib.dll'
             subprocess.check_call(cmd, cwd = str(udir), shell=True)    
             cls.module = str(udir.join('testownlib.dll'))
     else:
         subprocess.check_call(
             'gcc testownlib.c -shared -fPIC -o testownlib.so',
             cwd=str(udir), shell=True)
         cls.module = str(udir.join('testownlib.so'))
Exemplo n.º 4
0
 def setup_class(cls):
     cls.module = None
     from pypy.module.test_lib_pypy.cffi_tests.udir import udir
     udir.join('testownlib.c').write(SOURCE)
     if sys.platform == 'win32':
         import os
         # did we already build it?
         if os.path.exists(str(udir.join('testownlib.dll'))):
             cls.module = str(udir.join('testownlib.dll'))
             return
         # try (not too hard) to find the version used to compile this python
         # no mingw
         from distutils.msvc9compiler import get_build_version
         version = get_build_version()
         toolskey = "VS%0.f0COMNTOOLS" % version
         toolsdir = os.environ.get(toolskey, None)
         if toolsdir is None:
             return
         productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
         productdir = os.path.abspath(productdir)
         vcvarsall = os.path.join(productdir, "vcvarsall.bat")
         # 64?
         arch = 'x86'
         if sys.maxsize > 2**32:
             arch = 'amd64'
         if os.path.isfile(vcvarsall):
             cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
                     ' /LD /Fetestownlib.dll'
             subprocess.check_call(cmd, cwd = str(udir), shell=True)    
             cls.module = str(udir.join('testownlib.dll'))
     else:
         subprocess.check_call(
             'cc testownlib.c -shared -fPIC -o testownlib.so',
             cwd=str(udir), shell=True)
         cls.module = str(udir.join('testownlib.so'))
Exemplo n.º 5
0
def set_msvc_version(version):
    import sys
    import re
    from distutils import msvc9compiler
    sys.version = re.sub(r"MSC v.(\d\d\d\d)",
                         r"MSC v.{:02d}00".format(version + 6), sys.version)
    msvc9compiler.VERSION = msvc9compiler.get_build_version()
Exemplo n.º 6
0
    def _check_compiler(self):
        old_config._check_compiler(self)
        from numpy.distutils.fcompiler import FCompiler, new_fcompiler

        if sys.platform == "win32" and (
            self.compiler.compiler_type in ("msvc", "intelw", "intelemw")
        ):
            # XXX: hack to circumvent a python 2.6 bug with msvc9compiler:
            # initialize call query_vcvarsall, which throws an IOError, and
            # causes an error along the way without much information. We try to
            # catch it here, hoping it is early enough, and print an helpful
            # message instead of Error: None.
            if not self.compiler.initialized:
                try:
                    self.compiler.initialize()
                except IOError:
                    e = get_exception()
                    msg = """\
Could not initialize compiler instance: do you have Visual Studio
installed?  If you are trying to build with MinGW, please use "python setup.py
build -c mingw32" instead.  If you have Visual Studio installed, check it is
correctly installed, and the right version (VS 2008 for python 2.6, 2.7 and 3.2,
VS 2010 for >= 3.3).

Original exception was: %s, and the Compiler class was %s
============================================================================""" % (
                        e,
                        self.compiler.__class__.__name__,
                    )
                    print(
                        """\
============================================================================"""
                    )
                    raise distutils.errors.DistutilsPlatformError(msg)

            # After MSVC is initialized, add an explicit /MANIFEST to linker
            # flags.  See issues gh-4245 and gh-4101 for details.  Also
            # relevant are issues 4431 and 16296 on the Python bug tracker.
            from distutils import msvc9compiler

            if msvc9compiler.get_build_version() >= 10:
                for ldflags in [
                    self.compiler.ldflags_shared,
                    self.compiler.ldflags_shared_debug,
                ]:
                    if "/MANIFEST" not in ldflags:
                        ldflags.append("/MANIFEST")

        if not isinstance(self.fcompiler, FCompiler):
            self.fcompiler = new_fcompiler(
                compiler=self.fcompiler,
                dry_run=self.dry_run,
                force=1,
                c_compiler=self.compiler,
            )
            if self.fcompiler is not None:
                self.fcompiler.customize(self.distribution)
                if self.fcompiler.get_version():
                    self.fcompiler.customize_cmd(self)
                    self.fcompiler.show_customization()
Exemplo n.º 7
0
	def GetPathToHeader(self):
		"Find full path to the requested header, searching through all INCLUDE directories"
		from distutils import msvc9compiler as mscompiler   # could try some other compilers for other python versions.
		includes = mscompiler.query_vcvarsall(mscompiler.get_build_version(), "x86")["include"].split(";")
		for path in includes:
			p = os.path.join(path, self.header).replace("\\\\", "\\")
			if os.path.isfile(p): return p
		raise ValueError("Can't find header")
Exemplo n.º 8
0
 def GetPathToHeader(self):
     "Find full path to the requested header, searching through all INCLUDE directories"
     from distutils import msvc9compiler as mscompiler  # could try some other compilers for other python versions.
     includes = mscompiler.query_vcvarsall(mscompiler.get_build_version(),
                                           "x86")["include"].split(";")
     for path in includes:
         p = os.path.join(path, self.header).replace("\\\\", "\\")
         if os.path.isfile(p): return p
     raise ValueError("Can't find header")
Exemplo n.º 9
0
    def _check_compiler(self):
        old_config._check_compiler(self)
        from numpy.distutils.fcompiler import FCompiler, new_fcompiler

        if sys.platform == "win32" and self.compiler.compiler_type == "msvc":
            # XXX: hack to circumvent a python 2.6 bug with msvc9compiler:
            # initialize call query_vcvarsall, which throws an IOError, and
            # causes an error along the way without much information. We try to
            # catch it here, hoping it is early enough, and print an helpful
            # message instead of Error: None.
            if not self.compiler.initialized:
                try:
                    self.compiler.initialize()
                except IOError:
                    e = get_exception()
                    msg = """\
Could not initialize compiler instance: do you have Visual Studio
installed?  If you are trying to build with MinGW, please use "python setup.py
build -c mingw32" instead.  If you have Visual Studio installed, check it is
correctly installed, and the right version (VS 2008 for python 2.6, 2.7 and 3.2,
VS 2010 for >= 3.3).

Original exception was: %s, and the Compiler class was %s
============================================================================""" % (
                        e,
                        self.compiler.__class__.__name__,
                    )
                    print(
                        """\
============================================================================"""
                    )
                    raise distutils.errors.DistutilsPlatformError(msg)

            # After MSVC is initialized, add an explicit /MANIFEST to linker
            # flags.  See issues gh-4245 and gh-4101 for details.  Also
            # relevant are issues 4431 and 16296 on the Python bug tracker.
            from distutils import msvc9compiler

            if msvc9compiler.get_build_version() >= 10:
                for ldflags in [self.compiler.ldflags_shared, self.compiler.ldflags_shared_debug]:
                    if "/MANIFEST" not in ldflags:
                        ldflags.append("/MANIFEST")
                    if "/DEBUG" not in ldflags:
                        ldflags.append("/DEBUG")
                    if "/pdb:None" in ldflags:
                        ldflags.remove("/pdb:None")

        if not isinstance(self.fcompiler, FCompiler):
            self.fcompiler = new_fcompiler(
                compiler=self.fcompiler, dry_run=self.dry_run, force=1, c_compiler=self.compiler
            )
            if self.fcompiler is not None:
                self.fcompiler.customize(self.distribution)
                if self.fcompiler.get_version():
                    self.fcompiler.customize_cmd(self)
                    self.fcompiler.show_customization()
Exemplo n.º 10
0
 def setup_class(cls):
     cls.module = None
     from testing.udir import udir
     udir.join('testownlib.c').write(SOURCE)
     if sys.platform == 'win32':
         # did we already build it?
         if cls.Backend is CTypesBackend:
             dll_path = str(
                 udir
             ) + '\\testownlib1.dll'  # only ascii for the ctypes backend
         else:
             dll_path = str(udir) + '\\' + (u + 'testownlib\u03be.dll'
                                            )  # non-ascii char
         if os.path.exists(dll_path):
             cls.module = dll_path
             return
         # try (not too hard) to find the version used to compile this python
         # no mingw
         from distutils.msvc9compiler import get_build_version
         version = get_build_version()
         toolskey = "VS%0.f0COMNTOOLS" % version
         toolsdir = os.environ.get(toolskey, None)
         if toolsdir is None:
             return
         productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
         productdir = os.path.abspath(productdir)
         vcvarsall = os.path.join(productdir, "vcvarsall.bat")
         # 64?
         arch = 'x86'
         if sys.maxsize > 2**32:
             arch = 'amd64'
         if os.path.isfile(vcvarsall):
             cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
                     ' /LD /Fetestownlib.dll'
             subprocess.check_call(cmd, cwd=str(udir), shell=True)
             os.rename(str(udir) + '\\testownlib.dll', dll_path)
             cls.module = dll_path
     else:
         encoded = None
         if cls.Backend is not CTypesBackend:
             try:
                 unicode_name = u + 'testownlibcaf\xe9'
                 encoded = unicode_name.encode(sys.getfilesystemencoding())
                 if sys.version_info >= (3, ):
                     encoded = str(unicode_name)
             except UnicodeEncodeError:
                 pass
         if encoded is None:
             unicode_name = u + 'testownlib'
             encoded = str(unicode_name)
         subprocess.check_call("cc testownlib.c -shared -fPIC -o '%s.so'" %
                               (encoded, ),
                               cwd=str(udir),
                               shell=True)
         cls.module = os.path.join(str(udir), unicode_name + (u + '.so'))
     print(repr(cls.module))
Exemplo n.º 11
0
def _FixDistutilsMsvcCompiler():
  # To avoid runtime mismatch, distutils should use the compiler which was used
  # to build python. But our module does not use the runtime much, so it should
  # be fine to build within a different environment.
  # See also: http://bugs.python.org/issue7511
  from distutils import msvc9compiler
  for version in [msvc9compiler.get_build_version(), 9.0, 10.0, 11.0, 12.0]:
    msvc9compiler.VERSION = version
    try:
      msvc9compiler.MSVCCompiler().initialize()
      return
    except Exception:
      pass
  raise Exception('Could not initialize MSVC compiler for distutils.')
Exemplo n.º 12
0
 def setup_class(cls):
     cls.module = None
     from testing.udir import udir
     udir.join('testownlib.c').write(SOURCE)
     if sys.platform == 'win32':
         import os
         # did we already build it?
         if cls.Backend is CTypesBackend:
             dll_path = str(
                 udir
             ) + '\\testownlib1.dll'  # only ascii for the ctypes backend
         else:
             dll_path = str(udir) + '\\' + (u + 'testownlib\u03be.dll'
                                            )  # non-ascii char
         if os.path.exists(dll_path):
             cls.module = dll_path
             return
         # try (not too hard) to find the version used to compile this python
         # no mingw
         from distutils.msvc9compiler import get_build_version
         version = get_build_version()
         toolskey = "VS%0.f0COMNTOOLS" % version
         toolsdir = os.environ.get(toolskey, None)
         if toolsdir is None:
             return
         productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
         productdir = os.path.abspath(productdir)
         vcvarsall = os.path.join(productdir, "vcvarsall.bat")
         # 64?
         arch = 'x86'
         if sys.maxsize > 2**32:
             arch = 'amd64'
         if os.path.isfile(vcvarsall):
             cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
                     ' /LD /Fetestownlib.dll'
             subprocess.check_call(cmd, cwd=str(udir), shell=True)
             os.rename(str(udir) + '\\testownlib.dll', dll_path)
             cls.module = dll_path
     else:
         subprocess.check_call(
             'cc testownlib.c -shared -fPIC -o testownlib.so',
             cwd=str(udir),
             shell=True)
         cls.module = str(udir.join('testownlib.so'))
Exemplo n.º 13
0
def _get_extra_path_for_msvc():
    import distutils.spawn
    cl_exe = distutils.spawn.find_executable('cl.exe')
    if cl_exe:
        # The compiler is already on PATH, no extra path needed.
        return None

    from distutils import msvc9compiler
    vcvarsall_bat = msvc9compiler.find_vcvarsall(
        msvc9compiler.get_build_version())
    if not vcvarsall_bat:
        # Failed to find VC.
        return None

    path = os.path.join(os.path.dirname(vcvarsall_bat), 'bin')
    if not distutils.spawn.find_executable('cl.exe', path):
        # The compiler could not be found.
        return None
    return path
Exemplo n.º 14
0
 def setup_class(cls):
     cls.module = None
     from testing.udir import udir
     udir.join('testownlib.c').write(SOURCE)
     if sys.platform == 'win32':
         import os
         # did we already build it?
         if cls.Backend is CTypesBackend:
             dll_path = str(udir) + '\\testownlib1.dll'   # only ascii for the ctypes backend
         else:
             dll_path = str(udir) + '\\' + (u+'testownlib\u03be.dll')   # non-ascii char
         if os.path.exists(dll_path):
             cls.module = dll_path
             return
         # try (not too hard) to find the version used to compile this python
         # no mingw
         from distutils.msvc9compiler import get_build_version
         version = get_build_version()
         toolskey = "VS%0.f0COMNTOOLS" % version
         toolsdir = os.environ.get(toolskey, None)
         if toolsdir is None:
             return
         productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
         productdir = os.path.abspath(productdir)
         vcvarsall = os.path.join(productdir, "vcvarsall.bat")
         # 64?
         arch = 'x86'
         if sys.maxsize > 2**32:
             arch = 'amd64'
         if os.path.isfile(vcvarsall):
             cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
                     ' /LD /Fetestownlib.dll'
             subprocess.check_call(cmd, cwd = str(udir), shell=True)
             os.rename(str(udir) + '\\testownlib.dll', dll_path)
             cls.module = dll_path
     else:
         subprocess.check_call(
             'cc testownlib.c -shared -fPIC -o testownlib.so',
             cwd=str(udir), shell=True)
         cls.module = str(udir.join('testownlib.so'))
Exemplo n.º 15
0
def compile(filename, outputfilename, arch='x86', vcver=None):
    if vcver == None:
        if os.getenv('MSVCVER'):
            vcver = float(os.getenv('MSVCVER'))
        else:
            vcver = msvc9compiler.get_build_version()
    vcvars = msvc9compiler.find_vcvarsall(vcver)
    if not vcvars:  # My VS 2008 Standard Edition doesn't have vcvarsall.bat
        vsbase = msvc9compiler.VS_BASE % vcver
        productdir = msvc9compiler.Reg.get_value(r"%s\Setup\VC" % vsbase,
                                                 "productdir")
        bat = 'vcvars%d.bat' % (arch == 'x86' and 32 or 64)
        vcvars = os.path.join(productdir, 'bin', bat)

    path = os.path.splitext(outputfilename)
    objfilename = path[0] + '.obj'
    p = subprocess.Popen('"%s" %s & cl %s /Fe%s /Fo%s' %
                         (vcvars, arch, filename, outputfilename, objfilename),
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    try:
        stdout, stderr = p.communicate()
        if p.wait() != 0:
            raise Exception(stderr.decode("mbcs"))
        os.remove(objfilename)
    finally:
        p.stdout.close()
        p.stderr.close()


#try:
#    compile('inject_python.cpp', 'inject_python_32.exe', 'x86', 10.0)
#except:
#    pass
#try:
#    compile('inject_python.cpp', 'inject_python_64.exe', 'amd64', 10.0)
#except:
#    pass
Exemplo n.º 16
0
def set_msvc_version(version):
    import sys
    import re
    from distutils import msvc9compiler
    sys.version = re.sub(r"MSC v.(\d\d\d\d)", r"MSC v.{:02d}00".format(version+6), sys.version)
    msvc9compiler.VERSION = msvc9compiler.get_build_version()
Exemplo n.º 17
0
    for directory in (
            os.path.join('libsass', 'src'),
            os.path.join('libsass', 'include'),
    ):
        for pth, _, filenames in os.walk(directory):
            for filename in filenames:
                filename = os.path.join(pth, filename)
                if filename.endswith(('.c', '.cpp')):
                    sources.append(filename)
                elif filename.endswith('.h'):
                    headers.append(filename)

    if sys.platform == 'win32':
        from distutils.msvc9compiler import get_build_version
        vscomntools_env = 'VS{}{}COMNTOOLS'.format(
            int(get_build_version()),
            int(get_build_version() * 10) % 10,
        )
        try:
            os.environ[vscomntools_env] = os.environ['VS140COMNTOOLS']
        except KeyError:
            distutils.log.warn(
                'You probably need Visual Studio 2015 (14.0) '
                'or higher', )
        from distutils import msvccompiler, msvc9compiler
        if msvccompiler.get_build_version() < 14.0:
            msvccompiler.get_build_version = lambda: 14.0
        if get_build_version() < 14.0:
            msvc9compiler.get_build_version = lambda: 14.0
            msvc9compiler.VERSION = 14.0
    elif platform.system() in ('Darwin', 'FreeBSD'):
Exemplo n.º 18
0
    for directory in (
            os.path.join('libsass', 'src'),
            os.path.join('libsass', 'include'),
    ):
        for pth, _, filenames in os.walk(directory):
            for filename in filenames:
                filename = os.path.join(pth, filename)
                if filename.endswith(('.c', '.cpp')):
                    sources.append(filename)
                elif filename.endswith('.h'):
                    headers.append(filename)

    if sys.platform == 'win32':
        from distutils.msvc9compiler import get_build_version
        vscomntools_env = 'VS{}{}COMNTOOLS'.format(
            int(get_build_version()),
            int(get_build_version() * 10) % 10,
        )
        try:
            os.environ[vscomntools_env] = os.environ['VS140COMNTOOLS']
        except KeyError:
            distutils.log.warn(
                'You probably need Visual Studio 2015 (14.0) '
                'or higher',
            )
        from distutils import msvccompiler, msvc9compiler
        if msvccompiler.get_build_version() < 14.0:
            msvccompiler.get_build_version = lambda: 14.0
        if get_build_version() < 14.0:
            msvc9compiler.get_build_version = lambda: 14.0
            msvc9compiler.VERSION = 14.0
Exemplo n.º 19
0
def query_vcvarsall():
    vcvarsall = find_vcvarsall(get_build_version())
    return query_process('"%s" %s & set' % (vcvarsall, plat))
Exemplo n.º 20
0
def query_vcvarsall():
    vcvarsall = find_vcvarsall(get_build_version())
    return query_process('"%s" %s & set' % (vcvarsall, plat))
Exemplo n.º 21
0
def distutils_vcvars():
    from distutils.msvc9compiler import find_vcvarsall, get_build_version
    return find_vcvarsall(get_build_version())
Exemplo n.º 22
0
def distutils_vcvars():
    from distutils.msvc9compiler import find_vcvarsall, get_build_version
    return find_vcvarsall(get_build_version())
Exemplo n.º 23
0
#          libhdf5 - so that CMake has an installation of it
#              zlib
#              szip
#          boost
#
# Things that need to be installed
# QT
#

is_win = sys.platform.startswith("win")
if is_win:
    from distutils.msvc9compiler import get_build_version

    lib_ext = "lib"
    dll_ext = "dll"
    build_version = get_build_version()
    toolset = "vc%d" % (int(build_version) * 10)
else:
    lib_ext = "so"
    dll_ext = "so"
    toolset = None


class BuildWithCMake(setuptools.Command):
    user_options = [
        ("cmake", None, "Location of CMake executables"),
        ("install-dir", None, "Package install directory"),
    ]

    def initialize_options(self):
        self.build_lib = None