コード例 #1
0
 def test_keep_debug(self, exe, tmpdir):
     smartstrip(exe, keep_debug=True)
     debug = tmpdir.join("myprog.debug")
     assert debug.check(file=True)
     perm = debug.stat().mode & 0777
     assert perm & 0111 == 0  # 'x' bit not set
     #
     info = info_symbol(exe, "foo")
     assert info == "foo in section .text of %s" % exe
     #
     debug.remove()
     info = info_symbol(exe, "foo")
     assert info.startswith("No symbol table is loaded")
コード例 #2
0
ファイル: package.py プロジェクト: 3tty0n/pypy
def create_package(basedir, options, _fake=False):
    retval = 0
    name = options.name
    if not name:
        name = 'pypy-nightly'
    assert '/' not in name
    rename_pypy_c = options.pypy_c
    override_pypy_c = options.override_pypy_c

    basedir = py.path.local(basedir)
    if not override_pypy_c:
        basename = POSIX_EXE + '-c'
        if ARCH == 'win32':
            basename += '.exe'
        pypy_c = basedir.join('pypy', 'goal', basename)
    else:
        pypy_c = py.path.local(override_pypy_c)
    if not _fake and not pypy_c.check():
        raise PyPyCNotFound('Expected but did not find %s.'
                            ' Please compile pypy first, using translate.py,'
                            ' or check that you gave the correct path'
                            ' with --override_pypy_c' % pypy_c)
    if not _fake and not pypy_runs(pypy_c):
        raise OSError("Running %r failed!" % (str(pypy_c), ))
    if not options.no_cffi:
        failures = create_cffi_import_libraries(
            str(pypy_c),
            options,
            str(basedir),
            embed_dependencies=options.embed_dependencies,
        )

        for key, module in failures:
            print("""!!!!!!!!!!\nBuilding {0} bindings failed.
                You can either install development headers package,
                add the --without-{0} option to skip packaging this
                binary CFFI extension, or say --without-cffi.""".format(key),
                  file=sys.stderr)
        if len(failures) > 0:
            return 1, None

    if ARCH == 'win32' and not rename_pypy_c.lower().endswith('.exe'):
        rename_pypy_c += '.exe'
    binaries = [(pypy_c, rename_pypy_c, None)]

    if (ARCH != 'win32' and  # handled below
            not _fake and os.path.getsize(str(pypy_c)) < 500000):
        # This 'pypy_c' is very small, so it means it relies on a so/dll
        # If it would be bigger, it wouldn't.  That's a hack.
        if ARCH.startswith('darwin'):
            ext = 'dylib'
        else:
            ext = 'so'
        libpypy_name = 'lib' + POSIX_EXE + '-c.' + ext
        libpypy_c = pypy_c.new(basename=libpypy_name)
        if not libpypy_c.check():
            raise PyPyCNotFound('Expected pypy to be mostly in %r, but did '
                                'not find it' % (str(libpypy_c), ))
        binaries.append((libpypy_c, libpypy_name, None))
    #
    builddir = py.path.local(options.builddir)
    pypydir = builddir.ensure(name, dir=True)
    lib_pypy = pypydir.join('lib_pypy')
    # do not create lib_pypy yet, it will be created by the copytree below

    includedir = basedir.join('include')
    shutil.copytree(str(includedir), str(pypydir.join('include')))
    pypydir.ensure('include', dir=True)

    if ARCH == 'win32':
        os.environ['PATH'] = str(basedir.join('externals').join('bin')) + ';' + \
                            os.environ.get('PATH', '')
        src, tgt, _ = binaries[0]
        pypyw = src.new(purebasename=src.purebasename + 'w')
        if pypyw.exists():
            tgt = py.path.local(tgt)
            binaries.append(
                (pypyw, tgt.new(purebasename=tgt.purebasename + 'w').basename,
                 None))
            print("Picking %s" % str(pypyw))
        # Can't rename a DLL
        win_extras = [('lib' + POSIX_EXE + '-c.dll', None),
                      ('sqlite3.dll', lib_pypy)]
        if not options.no__tkinter:
            tkinter_dir = lib_pypy.join('_tkinter')
            win_extras += [('tcl86t.dll', tkinter_dir),
                           ('tk86t.dll', tkinter_dir)]

        for extra, target_dir in win_extras:
            p = pypy_c.dirpath().join(extra)
            if not p.check():
                p = py.path.local.sysfind(extra)
                if not p:
                    print("%s not found, expect trouble if this "
                          "is a shared build" % (extra, ))
                    continue
            print("Picking %s" % p)
            binaries.append((p, p.basename, target_dir))
        libsdir = basedir.join('libs')
        if libsdir.exists():
            print('Picking %s (and contents)' % libsdir)
            shutil.copytree(str(libsdir), str(pypydir.join('libs')))
        else:
            if not _fake:
                raise RuntimeError('"libs" dir with import library not found.')
            # XXX users will complain that they cannot compile capi (cpyext)
            # modules for windows, also embedding pypy (i.e. in cffi)
            # will fail.
            # Has the lib moved, was translation not 'shared', or are
            # there no exported functions in the dll so no import
            # library was created?
        if not options.no__tkinter:
            try:
                p = pypy_c.dirpath().join('tcl86t.dll')
                if not p.check():
                    p = py.path.local.sysfind('tcl86t.dll')
                    if p is None:
                        raise WindowsError("tcl86t.dll not found")
                tktcldir = p.dirpath().join('..').join('lib')
                shutil.copytree(str(tktcldir), str(pypydir.join('tcl')))
            except WindowsError:
                print("Packaging Tk runtime failed. tk86t.dll and tcl86t.dll "
                      "found in %s, expecting to find runtime in %s directory "
                      "next to the dlls, as per build "
                      "instructions." % (p, tktcldir),
                      file=sys.stderr)
                import traceback
                traceback.print_exc()
                raise MissingDependenciesError('Tk runtime')

    print('* Binaries:', [
        source.relto(str(basedir)) for source, target, target_dir in binaries
    ])

    # Careful: to copy lib_pypy, copying just the hg-tracked files
    # would not be enough: there are also build artifacts like cffi-generated
    # dynamic libs
    shutil.copytree(str(basedir.join('lib-python').join(STDLIB_VER)),
                    str(pypydir.join('lib-python').join(STDLIB_VER)),
                    ignore=ignore_patterns('.svn', 'py', '*.pyc', '*~'))
    shutil.copytree(str(basedir.join('lib_pypy')),
                    str(lib_pypy),
                    ignore=ignore_patterns('.svn', 'py', '*.pyc', '*~',
                                           '*_cffi.c', '*.o', '*.pyd-*',
                                           '*.obj', '*.lib', '*.exp',
                                           '*.manifest'))
    for file in [
            'README.rst',
    ]:
        shutil.copy(str(basedir.join(file)), str(pypydir))
    for file in ['_testcapimodule.c', '_ctypes_test.c']:
        shutil.copyfile(str(basedir.join('lib_pypy', file)),
                        str(lib_pypy.join(file)))
    # Use original LICENCE file
    base_file = str(basedir.join('LICENSE'))
    with open(base_file) as fid:
        license = fid.read()
    with open(str(pypydir.join('LICENSE')), 'w') as LICENSE:
        LICENSE.write(license)
    #
    spdir = pypydir.ensure('site-packages', dir=True)
    shutil.copy(str(basedir.join('site-packages', 'README')), str(spdir))
    #
    if ARCH == 'win32':
        bindir = pypydir
    else:
        bindir = pypydir.join('bin')
        bindir.ensure(dir=True)
    for source, target, target_dir in binaries:
        if target_dir:
            archive = target_dir.join(target)
        else:
            archive = bindir.join(target)
        if not _fake:
            shutil.copy(str(source), str(archive))
        else:
            open(str(archive), 'wb').close()
        os.chmod(str(archive), 0755)
    #if not _fake and not ARCH == 'win32':
    #    # create the pypy3 symlink
    #    old_dir = os.getcwd()
    #    os.chdir(str(bindir))
    #    try:
    #        os.symlink(POSIX_EXE, 'pypy3')
    #    finally:
    #        os.chdir(old_dir)
    fix_permissions(pypydir)

    old_dir = os.getcwd()
    try:
        os.chdir(str(builddir))
        if not _fake:
            for source, target, target_dir in binaries:
                if target_dir:
                    archive = target_dir.join(target)
                else:
                    archive = bindir.join(target)
                smartstrip(archive, keep_debug=options.keep_debug)

            # make the package portable by adding rpath=$ORIGIN/..lib,
            # bundling dependencies
            if options.make_portable:
                os.chdir(str(name))
                if not os.path.exists('lib'):
                    os.mkdir('lib')
                make_portable()
                os.chdir(str(builddir))
        if USE_ZIPFILE_MODULE:
            import zipfile
            archive = str(builddir.join(name + '.zip'))
            zf = zipfile.ZipFile(archive,
                                 'w',
                                 compression=zipfile.ZIP_DEFLATED)
            for (dirpath, dirnames, filenames) in os.walk(name):
                for fnname in filenames:
                    filename = os.path.join(dirpath, fnname)
                    zf.write(filename)
            zf.close()
        else:
            archive = str(builddir.join(name + '.tar.bz2'))
            if ARCH == 'darwin':
                print(
                    "Warning: tar on current platform does not suport "
                    "overriding the uid and gid for its contents. The tarball "
                    "will contain your uid and gid. If you are building the "
                    "actual release for the PyPy website, you may want to be "
                    "using another platform...",
                    file=sys.stderr)
                e = os.system('tar --numeric-owner -cvjf ' + archive + " " +
                              name)
            elif sys.platform.startswith('freebsd'):
                e = os.system('tar --uname=root --gname=wheel -cvjf ' +
                              archive + " " + name)
            elif sys.platform == 'cygwin':
                e = os.system(
                    'tar --owner=Administrator --group=Administrators --numeric-owner -cvjf '
                    + archive + " " + name)
            else:
                e = os.system(
                    'tar --owner=root --group=root --numeric-owner -cvjf ' +
                    archive + " " + name)
            if e:
                raise OSError('"tar" returned exit status %r' % e)
    finally:
        os.chdir(old_dir)
    if options.targetdir:
        print("Copying %s to %s" % (archive, options.targetdir))
        shutil.copy(archive, options.targetdir)
    else:
        print("Ready in %s" % (builddir, ))
    return retval, builddir  # for tests
コード例 #3
0
def create_package(basedir, options, _fake=False):
    retval = 0
    name = options.name
    if not name:
        name = 'pypy-nightly'
    assert '/' not in name
    rename_pypy_c = options.pypy_c
    override_pypy_c = options.override_pypy_c

    basedir = py.path.local(basedir)
    if not override_pypy_c:
        basename = 'pypy-c'
        if sys.platform == 'win32':
            basename += '.exe'
        pypy_c = basedir.join('pypy', 'goal', basename)
    else:
        pypy_c = py.path.local(override_pypy_c)
    if not _fake and not pypy_c.check():
        raise PyPyCNotFound('Expected but did not find %s.'
                            ' Please compile pypy first, using translate.py,'
                            ' or check that you gave the correct path'
                            ' with --override_pypy_c' % pypy_c)
    if not _fake and not pypy_runs(pypy_c):
        raise OSError("Running %r failed!" % (str(pypy_c), ))
    if not options.no_cffi:
        failures = create_cffi_import_libraries(pypy_c, options, basedir)
        for key, module in failures:
            print >> sys.stderr, """!!!!!!!!!!\nBuilding {0} bindings failed.
                You can either install development headers package,
                add the --without-{0} option to skip packaging this
                binary CFFI extension, or say --without-cffi.""".format(key)
        if len(failures) > 0:
            return 1, None

    if sys.platform == 'win32' and not rename_pypy_c.lower().endswith('.exe'):
        rename_pypy_c += '.exe'
    binaries = [(pypy_c, rename_pypy_c)]

    if (sys.platform != 'win32' and  # handled below
            not _fake and os.path.getsize(str(pypy_c)) < 500000):
        # This pypy-c is very small, so it means it relies on libpypy_c.so.
        # If it would be bigger, it wouldn't.  That's a hack.
        libpypy_name = ('libpypy-c.so' if not sys.platform.startswith('darwin')
                        else 'libpypy-c.dylib')
        libpypy_c = pypy_c.new(basename=libpypy_name)
        if not libpypy_c.check():
            raise PyPyCNotFound('Expected pypy to be mostly in %r, but did '
                                'not find it' % (str(libpypy_c), ))
        binaries.append((libpypy_c, libpypy_name))
    libminiz_oxide_name = "libminiz_oxide_c_api.so"
    binaries.append(
        (pypy_c.new(basename=libminiz_oxide_name), libminiz_oxide_name))
    #
    builddir = py.path.local(options.builddir)
    pypydir = builddir.ensure(name, dir=True)

    includedir = basedir.join('include')
    shutil.copytree(str(includedir), str(pypydir.join('include')))
    pypydir.ensure('include', dir=True)

    if sys.platform == 'win32':
        src, tgt = binaries[0]
        pypyw = src.new(purebasename=src.purebasename + 'w')
        if pypyw.exists():
            tgt = py.path.local(tgt)
            binaries.append(
                (pypyw, tgt.new(purebasename=tgt.purebasename + 'w').basename))
            print "Picking %s" % str(pypyw)
        # Can't rename a DLL: it is always called 'libpypy-c.dll'
        win_extras = ['libpypy-c.dll', 'sqlite3.dll']
        if not options.no_tk:
            win_extras += ['tcl85.dll', 'tk85.dll']

        for extra in win_extras:
            p = pypy_c.dirpath().join(extra)
            if not p.check():
                p = py.path.local.sysfind(extra)
                if not p:
                    print "%s not found, expect trouble if this is a shared build" % (
                        extra, )
                    continue
            print "Picking %s" % p
            binaries.append((p, p.basename))
        libsdir = basedir.join('libs')
        if libsdir.exists():
            print 'Picking %s (and contents)' % libsdir
            shutil.copytree(str(libsdir), str(pypydir.join('libs')))
        else:
            print '"libs" dir with import library not found.'
            print 'You have to create %r' % (str(libsdir), )
            print 'and copy libpypy-c.lib in there, renamed to python27.lib'
            # XXX users will complain that they cannot compile capi (cpyext)
            # modules for windows, also embedding pypy (i.e. in cffi)
            # will fail.
            # Has the lib moved, was translation not 'shared', or are
            # there no exported functions in the dll so no import
            # library was created?
        if not options.no_tk:
            try:
                p = pypy_c.dirpath().join('tcl85.dll')
                if not p.check():
                    p = py.path.local.sysfind('tcl85.dll')
                    if p is None:
                        raise WindowsError("tcl85.dll not found")
                tktcldir = p.dirpath().join('..').join('lib')
                shutil.copytree(str(tktcldir), str(pypydir.join('tcl')))
            except WindowsError:
                print >> sys.stderr, r"""Packaging Tk runtime failed.
tk85.dll and tcl85.dll found in %s, expecting to find runtime in %s
directory next to the dlls, as per build instructions.""" % (p, tktcldir)
                import traceback
                traceback.print_exc()
                raise MissingDependenciesError('Tk runtime')

    print '* Binaries:', [
        source.relto(str(basedir)) for source, target in binaries
    ]

    # Careful: to copy lib_pypy, copying just the hg-tracked files
    # would not be enough: there are also ctypes_config_cache/_*_cache.py.
    # XXX ^^^ this is no longer true!
    shutil.copytree(str(basedir.join('lib-python').join(STDLIB_VER)),
                    str(pypydir.join('lib-python').join(STDLIB_VER)),
                    ignore=ignore_patterns('.svn', 'py', '*.pyc', '*~'))
    shutil.copytree(str(basedir.join('lib_pypy')),
                    str(pypydir.join('lib_pypy')),
                    ignore=ignore_patterns('.svn', 'py', '*.pyc', '*~',
                                           '*_cffi.c', '*.o'))
    for file in [
            'README.pypy.rst',
            'README.md',
    ]:
        shutil.copy(str(basedir.join(file)), str(pypydir))
    for file in ['_testcapimodule.c', '_ctypes_test.c']:
        shutil.copyfile(str(basedir.join('lib_pypy', file)),
                        str(pypydir.join('lib_pypy', file)))
    # Use original LICENCE file
    base_file = str(basedir.join('LICENSE'))
    with open(base_file) as fid:
        license = fid.read()
    with open(str(pypydir.join('LICENSE')), 'w') as LICENSE:
        LICENSE.write(license)
    #
    spdir = pypydir.ensure('site-packages', dir=True)
    shutil.copy(str(basedir.join('site-packages', 'README')), str(spdir))
    #
    if sys.platform == 'win32':
        bindir = pypydir
    else:
        bindir = pypydir.join('bin')
        bindir.ensure(dir=True)
    for source, target in binaries:
        archive = bindir.join(target)
        if not _fake:
            shutil.copy(str(source), str(archive))
        else:
            open(str(archive), 'wb').close()
        os.chmod(str(archive), 0755)
    fix_permissions(pypydir)

    old_dir = os.getcwd()
    try:
        os.chdir(str(builddir))
        if not _fake:
            for source, target in binaries:
                smartstrip(bindir.join(target), keep_debug=options.keep_debug)
        #
        if USE_ZIPFILE_MODULE:
            import zipfile
            archive = str(builddir.join(name + '.zip'))
            zf = zipfile.ZipFile(archive,
                                 'w',
                                 compression=zipfile.ZIP_DEFLATED)
            for (dirpath, dirnames, filenames) in os.walk(name):
                for fnname in filenames:
                    filename = os.path.join(dirpath, fnname)
                    zf.write(filename)
            zf.close()
        else:
            archive = str(builddir.join(name + '.tar.bz2'))
            if sys.platform == 'darwin':
                print >> sys.stderr, """Warning: tar on current platform does not suport overriding the uid and gid
for its contents. The tarball will contain your uid and gid. If you are
building the actual release for the PyPy website, you may want to be
using another platform..."""
                e = os.system('tar --numeric-owner -cvjf ' + archive + " " +
                              name)
            elif sys.platform.startswith('freebsd'):
                e = os.system('tar --uname=root --gname=wheel -cvjf ' +
                              archive + " " + name)
            elif sys.platform == 'cygwin':
                e = os.system(
                    'tar --owner=Administrator --group=Administrators --numeric-owner -cvjf '
                    + archive + " " + name)
            else:
                e = os.system(
                    'tar --owner=root --group=root --numeric-owner -cvjf ' +
                    archive + " " + name)
            if e:
                raise OSError('"tar" returned exit status %r' % e)
    finally:
        os.chdir(old_dir)
    if options.targetdir:
        print "Copying %s to %s" % (archive, options.targetdir)
        shutil.copy(archive, options.targetdir)
    else:
        print "Ready in %s" % (builddir, )
    return retval, builddir  # for tests
コード例 #4
0
 def test_strip(self, exe):
     smartstrip(exe, keep_debug=False)
     info = info_symbol(exe, "foo")
     assert info.startswith("No symbol table is loaded")