示例#1
0
def compiled_dylib(tmpdir):
    tmp_data_dir = _data_dir_copy('ctypes_dylib', tmpdir)

    # Compile the ctypes_dylib in the tmpdir: Make tmpdir/data the CWD. Don't
    # use monkeypatch.chdir to change, then monkeypatch.undo() to restore the
    # CWD, since this will undo ALL monkeypatches (such as the pyi_builder's
    # additions to sys.path), breaking the test.
    old_wd = tmp_data_dir.chdir()
    try:
        if is_win:
            tmp_data_dir = tmp_data_dir.join('ctypes_dylib.dll')
            # For Mingw-x64 we must pass '-m32' to build 32-bit binaries
            march = '-m32' if architecture() == '32bit' else '-m64'
            ret = subprocess.call('gcc -shared ' + march +
                                  ' ctypes_dylib.c -o ctypes_dylib.dll',
                                  shell=True)
            if ret != 0:
                # Find path to cl.exe file.
                from distutils.msvccompiler import MSVCCompiler
                comp = MSVCCompiler()
                comp.initialize()
                cl_path = comp.cc
                # Fallback to msvc.
                ret = subprocess.call([cl_path, '/LD', 'ctypes_dylib.c'],
                                      shell=False)
        elif is_darwin:
            tmp_data_dir = tmp_data_dir.join('ctypes_dylib.dylib')
            # On Mac OS X we need to detect architecture - 32 bit or 64 bit.
            arch = 'i386' if architecture() == '32bit' else 'x86_64'
            cmd = (
                'gcc -arch ' + arch + ' -Wall -dynamiclib '
                'ctypes_dylib.c -o ctypes_dylib.dylib -headerpad_max_install_names'
            )
            ret = subprocess.call(cmd, shell=True)
            id_dylib = os.path.abspath('ctypes_dylib.dylib')
            ret = subprocess.call(
                'install_name_tool -id %s ctypes_dylib.dylib' % (id_dylib, ),
                shell=True)
        else:
            tmp_data_dir = tmp_data_dir.join('ctypes_dylib.so')
            ret = subprocess.call(
                'gcc -fPIC -shared ctypes_dylib.c -o ctypes_dylib.so',
                shell=True)
        assert ret == 0, 'Compile ctypes_dylib failed.'
    finally:
        # Reset the CWD directory.
        old_wd.chdir()

    return tmp_data_dir
示例#2
0
def processor_architecture():
    """
    Detect processor architecture for assembly manifest.

    According to:
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa374219(v=vs.85).aspx
    item processorArchitecture in assembly manifest is

    'x86' - 32bit Windows
    'amd64' - 64bit Windows
    """
    return 'x86' if architecture() == '32bit' else 'amd64'
示例#3
0
def processor_architecture():
    """
    Detect processor architecture for assembly manifest.

    According to:
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa374219(v=vs.85).aspx
    item processorArchitecture in assembly manifest is

    'x86' - 32bit Windows
    'amd64' - 64bit Windows
    """
    return 'x86' if architecture() == '32bit' else 'amd64'
示例#4
0
def compiled_dylib(tmpdir):
    tmp_data_dir = _data_dir_copy('ctypes_dylib', tmpdir)

    # Compile the ctypes_dylib in the tmpdir: Make tmpdir/data the CWD. Don't
    # use monkeypatch.chdir to change, then monkeypatch.undo() to restore the
    # CWD, since this will undo ALL monkeypatches (such as the pyi_builder's
    # additions to sys.path), breaking the test.
    old_wd = tmp_data_dir.chdir()
    try:
        if is_win:
            tmp_data_dir = tmp_data_dir.join('ctypes_dylib.dll')
            # For Mingw-x64 we must pass '-m32' to build 32-bit binaries
            march = '-m32' if architecture() == '32bit' else '-m64'
            ret = subprocess.call('gcc -shared ' + march + ' ctypes_dylib.c -o ctypes_dylib.dll', shell=True)
            if ret != 0:
                # Find path to cl.exe file.
                from distutils.msvccompiler import MSVCCompiler
                comp = MSVCCompiler()
                comp.initialize()
                cl_path = comp.cc
                # Fallback to msvc.
                ret = subprocess.call([cl_path, '/LD', 'ctypes_dylib.c'], shell=False)
        elif is_darwin:
            tmp_data_dir = tmp_data_dir.join('ctypes_dylib.dylib')
            # On Mac OS X we need to detect architecture - 32 bit or 64 bit.
            arch = 'i386' if architecture() == '32bit' else 'x86_64'
            cmd = ('gcc -arch ' + arch + ' -Wall -dynamiclib '
                'ctypes_dylib.c -o ctypes_dylib.dylib -headerpad_max_install_names')
            ret = subprocess.call(cmd, shell=True)
            id_dylib = os.path.abspath('ctypes_dylib.dylib')
            ret = subprocess.call('install_name_tool -id %s ctypes_dylib.dylib' % (id_dylib,), shell=True)
        else:
            tmp_data_dir = tmp_data_dir.join('ctypes_dylib.so')
            ret = subprocess.call('gcc -fPIC -shared ctypes_dylib.c -o ctypes_dylib.so', shell=True)
        assert ret == 0, 'Compile ctypes_dylib failed.'
    finally:
        # Reset the CWD directory.
        old_wd.chdir()

    return tmp_data_dir
示例#5
0
def get_config(upx_dir, **kw):
    if is_darwin and compat.architecture() == '64bit':
        logger.warn('You are running 64-bit Python: created binaries will only'
            ' work on Mac OS X 10.6+.\nIf you need 10.4-10.5 compatibility,'
            ' run Python as a 32-bit binary with this command:\n\n'
            '    VERSIONER_PYTHON_PREFER_32_BIT=yes arch -i386 %s\n' % sys.executable)
        # wait several seconds for user to see this message
        time.sleep(4)

    config = {}
    test_RsrcUpdate(config)
    test_UPX(config, upx_dir)
    find_PYZ_dependencies(config)
    return config
示例#6
0
def get_config(upx_dir, **kw):
    if is_darwin and compat.architecture() == '64bit':
        logger.warn('You are running 64-bit Python: created binaries will only'
            ' work on Mac OS X 10.6+.\nIf you need 10.4-10.5 compatibility,'
            ' run Python as a 32-bit binary with this command:\n\n'
            '    VERSIONER_PYTHON_PREFER_32_BIT=yes arch -i386 %s\n' % sys.executable)
        # wait several seconds for user to see this message
        time.sleep(4)

    config = {}
    test_RsrcUpdate(config)
    test_UPX(config, upx_dir)
    find_PYZ_dependencies(config)
    return config
示例#7
0
def get_config(upx_dir, **kw):
    if is_darwin and compat.architecture() == "64bit":
        logger.warn(
            "You are running 64-bit Python: created binaries will only"
            " work on Mac OS X 10.6+.\nIf you need 10.4-10.5 compatibility,"
            " run Python as a 32-bit binary with this command:\n\n"
            "    VERSIONER_PYTHON_PREFER_32_BIT=yes arch -i386 %s\n" % sys.executable
        )
        # wait several seconds for user to see this message
        time.sleep(4)

    # if not set by Make.py we can assume Windows
    config = {"useELFEXE": 1}
    test_Zlib(config)
    test_Crypt(config)
    test_RsrcUpdate(config)
    test_UPX(config, upx_dir)
    find_PYZ_dependencies(config)
    return config
示例#8
0
def main(configfilename, upx_dir, **kw):

    if is_darwin and compat.architecture() == '64bit':
        logger.warn(
            'You are running 64-bit Python. Created binary will not'
            ' work on Mac OS X 10.4 or 10.5. For this version it is necessary'
            ' to create 32-bit binaries.'
            ' If you need 32-bit version of Python, run Python as 32-bit binary'
            ' by command:\n\n'
            '    arch -i386 python\n')
        # wait several seconds for user to see this message
        time.sleep(4)

    try:
        config = build._load_data(configfilename)
        logger.info('read old config from %s', configfilename)
    except (IOError, SyntaxError):
        # IOerror: file not present/readable
        # SyntaxError: invalid file (platform change?)
        # if not set by Make.py we can assume Windows
        config = {'useELFEXE': 1}

    # Save Python version, to detect and avoid conflicts
    config["pythonVersion"] = sys.version
    config["pythonDebug"] = __debug__

    # Save PyInstaller path and version
    config["pyinstaller_version"] = get_version()
    config["pyinstaller_homepath"] = HOMEPATH

    find_EXE_dependencies(config)
    test_TCL_TK(config)
    test_Zlib(config)
    test_Crypt(config)
    test_RsrcUpdate(config)
    test_unicode(config)
    test_UPX(config, upx_dir)
    find_PYZ_dependencies(config)

    build._save_data(configfilename, config)
    logger.info("done generating %s", configfilename)
示例#9
0
def main(configfilename, upx_dir, **kw):

    if is_darwin and compat.architecture() == '64bit':
        logger.warn('You are running 64-bit Python. Created binary will not'
            ' work on Mac OS X 10.4 or 10.5. For this version it is necessary'
            ' to create 32-bit binaries.'
            ' If you need 32-bit version of Python, run Python as 32-bit binary'
            ' by command:\n\n'
            '    arch -i386 python\n')
        # wait several seconds for user to see this message
        time.sleep(4)

    try:
        config = build._load_data(configfilename)
        logger.info('read old config from %s', configfilename)
    except (IOError, SyntaxError):
        # IOerror: file not present/readable
        # SyntaxError: invalid file (platform change?)
        # if not set by Make.py we can assume Windows
        config = {'useELFEXE': 1}

    # Save Python version, to detect and avoid conflicts
    config["pythonVersion"] = sys.version
    config["pythonDebug"] = __debug__

    # Save PyInstaller path and version
    config["pyinstaller_version"] = get_version()
    config["pyinstaller_homepath"] = HOMEPATH

    find_EXE_dependencies(config)
    test_TCL_TK(config)
    test_Zlib(config)
    test_Crypt(config)
    test_RsrcUpdate(config)
    test_unicode(config)
    test_UPX(config, upx_dir)
    find_PYZ_dependencies(config)

    build._save_data(configfilename, config)
    logger.info("done generating %s", configfilename)
示例#10
0
if is_win:
    CONFIGDIR = compat.getenv('APPDATA')
    if not CONFIGDIR:
        CONFIGDIR = os.path.expanduser('~\\Application Data')
elif is_darwin:
    CONFIGDIR = os.path.expanduser('~/Library/Application Support')
else:
    # According to XDG specification
    # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
    CONFIGDIR = compat.getenv('XDG_DATA_HOME')
    if not CONFIGDIR:
        CONFIGDIR = os.path.expanduser('~/.local/share')
CONFIGDIR = os.path.join(CONFIGDIR, 'pyinstaller')


PLATFORM = compat.system() + '-' + compat.architecture()
# Include machine name in path to bootloader for some machines.
# e.g. 'arm'
if compat.machine():
    PLATFORM += '-' + compat.machine()


# path extensions for module seach
# FIXME this should not be a global variable
__pathex__ = []


def get_version():
    version = '%s.%s' % (VERSION[0], VERSION[1])
    if VERSION[2]:
        version = '%s.%s' % (version, VERSION[2])
示例#11
0
    CONFIGDIR = compat.getenv('APPDATA')
    if not CONFIGDIR:
        CONFIGDIR = os.path.expanduser('~\\Application Data')
elif is_darwin:
    CONFIGDIR = os.path.expanduser('~/Library/Application Support')
else:
    # According to XDG specification
    # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
    CONFIGDIR = compat.getenv('XDG_DATA_HOME')
    if not CONFIGDIR:
        CONFIGDIR = os.path.expanduser('~/.local/share')
CONFIGDIR = os.path.join(CONFIGDIR, 'pyinstaller')

DEFAULT_CONFIGFILE = os.path.join(CONFIGDIR, 'config.dat')

PLATFORM = compat.system() + '-' + compat.architecture()

# path extensions for module seach
# :fixme: this should not be a global variable
__pathex__ = []


def get_version():
    version = '%s.%s' % (VERSION[0], VERSION[1])
    if VERSION[2]:
        version = '%s.%s' % (version, VERSION[2])
    if VERSION[3]:
        version = '%s%s' % (version, VERSION[3])
    # include svn revision in version string
    if VERSION[3] == 'dev' and VERSION[4] > 0:
        version = '%s%s' % (version, VERSION[4])
import glob
import os
import subprocess

from PyInstaller.config import CONF
from PyInstaller.compat import (
    architecture, exec_command_stdout, is_darwin, is_win, is_linux, open_file, which)
from PyInstaller.utils.hooks import (
    collect_glib_translations, get_gi_typelibs, get_gi_libdir, logger)

# If the "gdk-pixbuf-query-loaders" command is not in the current ${PATH}, GDK
# and thus GdkPixbuf is unavailable. Return with a non-fatal warning.
gdk_pixbuf_query_loaders = None

if architecture() == '64bit':
    # CentOS/Fedora package as -64
    cmds = ['gdk-pixbuf-query-loaders-64', 'gdk-pixbuf-query-loaders']
else:
    cmds = ['gdk-pixbuf-query-loaders']

for cmd in cmds:
    gdk_pixbuf_query_loaders = which(cmd)
    if gdk_pixbuf_query_loaders is not None:
        break

if gdk_pixbuf_query_loaders is None:
    logger.warning(
        '"hook-gi.repository.GdkPixbuf" ignored, since GDK not found '
        '(i.e., "gdk-pixbuf-query-loaders" not in $PATH).'
    )
def findLibrary(name):
    """
    Look for a library in the system.

    Emulate the algorithm used by dlopen.
    `name`must include the prefix, e.g. ``libpython2.4.so``
    """
    assert is_unix, ("Current implementation for Unix only (Linux, Solaris, "
                     "AIX, FreeBSD)")

    lib = None

    # Look in the LD_LIBRARY_PATH according to platform.
    if is_aix:
        lp = compat.getenv('LIBPATH', '')
    elif is_darwin:
        lp = compat.getenv('DYLD_LIBRARY_PATH', '')
    else:
        lp = compat.getenv('LD_LIBRARY_PATH', '')
    for path in lp.split(os.pathsep):
        libs = glob(os.path.join(path, name + '*'))
        if libs:
            lib = libs[0]
            break

    # Look in /etc/ld.so.cache
    # TODO Look for ldconfig in /usr/sbin/ldconfig. /sbin is deprecated
    #      in recent linux distributions.
    # Solaris does not have /sbin/ldconfig. Just check if this file exists.
    if lib is None and os.path.exists('/sbin/ldconfig'):
        expr = r'/[^\(\)\s]*%s\.[^\(\)\s]*' % re.escape(name)
        if is_freebsd:
            # This has a slightly different format than on linux, but the
            # regex still works.
            m = re.search(expr, compat.exec_command('/sbin/ldconfig', '-r'))
        else:
            m = re.search(expr, compat.exec_command('/sbin/ldconfig', '-p'))

        if m:
            lib = m.group(0)

    # Look in the known safe paths.
    if lib is None:
        # Architecture independent locations.
        paths = ['/lib', '/usr/lib']
        # Architecture dependent locations.
        arch = compat.architecture()
        if arch == '32bit':
            paths.extend(['/lib32', '/usr/lib32', '/usr/lib/i386-linux-gnu'])
        else:
            paths.extend(['/lib64', '/usr/lib64', '/usr/lib/x86_64-linux-gnu'])

        # On Debian/Ubuntu /usr/bin/python is linked statically with libpython.
        # Newer Debian/Ubuntu with multiarch support putsh the libpythonX.Y.so
        # To paths like /usr/lib/i386-linux-gnu/.
        try:
            # Module available only in Python 2.7+
            import sysconfig
            # 'multiarchsubdir' works on Debian/Ubuntu only in Python 2.7 and 3.3+.
            arch_subdir = sysconfig.get_config_var('multiarchsubdir')
            # Ignore if None is returned.
            if arch_subdir:
                arch_subdir = os.path.basename(arch_subdir)
                paths.append(os.path.join('/usr/lib', arch_subdir))
            else:
                logger.debug('Multiarch directory not detected.')
        except ImportError:
            logger.debug('Multiarch directory not detected.')

        if is_aix:
            paths.append('/opt/freeware/lib')
        elif is_freebsd:
            paths.append('/usr/local/lib')
        for path in paths:
            libs = glob(os.path.join(path, name + '*'))
            if libs:
                lib = libs[0]
                break

    # give up :(
    if lib is None:
        return None

    # Resolve the file name into the soname
    if is_freebsd or is_aix:
        # On FreeBSD objdump doesn't show SONAME,
        # and on AIX objdump does not exist,
        # so we just return the lib we've found
        return lib
    else:
        dir = os.path.dirname(lib)
        return os.path.join(dir, _get_so_name(lib))
示例#14
0
from PyInstaller.config import CONF
from PyInstaller.compat import (architecture, exec_command_stdout, is_darwin,
                                is_win, is_linux, open_file, which)
from PyInstaller.utils.hooks import (collect_glib_translations,
                                     get_gi_typelibs, get_gi_libdir, logger)

loaders_path = os.path.join('gdk-pixbuf-2.0', '2.10.0', 'loaders')

destpath = "lib/gdk-pixbuf-2.0/2.10.0/loaders"
cachedest = "lib/gdk-pixbuf-2.0/2.10.0"

# If the "gdk-pixbuf-query-loaders" command is not in the current ${PATH}, GDK
# and thus GdkPixbuf is unavailable. Return with a non-fatal warning.
gdk_pixbuf_query_loaders = None

if architecture() == '64bit':
    # CentOS/Fedora package as -64
    cmds = ['gdk-pixbuf-query-loaders-64', 'gdk-pixbuf-query-loaders']
else:
    cmds = ['gdk-pixbuf-query-loaders']

for cmd in cmds:
    gdk_pixbuf_query_loaders = which(cmd)
    if gdk_pixbuf_query_loaders is not None:
        break

if gdk_pixbuf_query_loaders is None:
    logger.warning(
        '"hook-gi.repository.GdkPixbuf" ignored, since GDK not found '
        '(i.e., "gdk-pixbuf-query-loaders" not in $PATH).')
# Else, GDK is available. Let's do this.
示例#15
0
文件: bindepend.py 项目: cbgp/diyabc
def findLibrary(name):
    """
    Look for a library in the system.

    Emulate the algorithm used by dlopen.
    `name`must include the prefix, e.g. ``libpython2.4.so``
    """
    assert is_unix, ("Current implementation for Unix only (Linux, Solaris, "
                     "AIX, FreeBSD)")

    lib = None

    # Look in the LD_LIBRARY_PATH according to platform.
    if is_aix:
        lp = compat.getenv('LIBPATH', '')
    elif is_darwin:
        lp = compat.getenv('DYLD_LIBRARY_PATH', '')
    else:
        lp = compat.getenv('LD_LIBRARY_PATH', '')
    for path in lp.split(os.pathsep):
        libs = glob(os.path.join(path, name + '*'))
        if libs:
            lib = libs[0]
            break

    # Look in /etc/ld.so.cache
    # TODO Look for ldconfig in /usr/sbin/ldconfig. /sbin is deprecated
    #      in recent linux distributions.
    # Solaris does not have /sbin/ldconfig. Just check if this file exists.
    if lib is None and os.path.exists('/sbin/ldconfig'):
        expr = r'/[^\(\)\s]*%s\.[^\(\)\s]*' % re.escape(name)
        if is_freebsd:
            # This has a slightly different format than on linux, but the
            # regex still works.
            m = re.search(expr, compat.exec_command('/sbin/ldconfig', '-r'))
        else:
            m = re.search(expr, compat.exec_command('/sbin/ldconfig', '-p'))

        if m:
            lib = m.group(0)

    # Look in the known safe paths.
    if lib is None:
        # Architecture independent locations.
        paths = ['/lib', '/usr/lib']
        # Architecture dependent locations.
        arch = compat.architecture()
        if arch == '32bit':
            paths.extend(['/lib32', '/usr/lib32', '/usr/lib/i386-linux-gnu'])
        else:
            paths.extend(['/lib64', '/usr/lib64', '/usr/lib/x86_64-linux-gnu'])


        # On Debian/Ubuntu /usr/bin/python is linked statically with libpython.
        # Newer Debian/Ubuntu with multiarch support putsh the libpythonX.Y.so
        # To paths like /usr/lib/i386-linux-gnu/.
        try:
            # Module available only in Python 2.7+
            import sysconfig
            # 'multiarchsubdir' works on Debian/Ubuntu only in Python 2.7 and 3.3+.
            arch_subdir = sysconfig.get_config_var('multiarchsubdir')
            # Ignore if None is returned.
            if arch_subdir:
                arch_subdir = os.path.basename(arch_subdir)
                paths.append(os.path.join('/usr/lib', arch_subdir))
            else:
                logger.debug('Multiarch directory not detected.')
        except ImportError:
            logger.debug('Multiarch directory not detected.')

        if is_aix:
            paths.append('/opt/freeware/lib')
        elif is_freebsd:
            paths.append('/usr/local/lib')
        for path in paths:
            libs = glob(os.path.join(path, name + '*'))
            if libs:
                lib = libs[0]
                break

    # give up :(
    if lib is None:
        return None

    # Resolve the file name into the soname
    if is_freebsd or is_aix:
        # On FreeBSD objdump doesn't show SONAME,
        # and on AIX objdump does not exist,
        # so we just return the lib we've found
        return lib
    else:
        dir = os.path.dirname(lib)
        return os.path.join(dir, _get_so_name(lib))