[pypy-commit] pypy py3.5: merge default into py3.5

mattip pypy.commits at gmail.com
Thu Nov 2 04:07:39 EDT 2017


Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.5
Changeset: r92902:6311c6a24eba
Date: 2017-11-02 10:10 +0200
http://bitbucket.org/pypy/pypy/changeset/6311c6a24eba/

Log:	merge default into py3.5

diff --git a/pypy/tool/build_cffi_imports.py b/pypy/tool/build_cffi_imports.py
--- a/pypy/tool/build_cffi_imports.py
+++ b/pypy/tool/build_cffi_imports.py
@@ -145,6 +145,12 @@
 
     shutil.rmtree(str(join(basedir,'lib_pypy','__pycache__')),
                   ignore_errors=True)
+    # be sure pip, setuptools are installed in a fresh pypy
+    # allows proper functioning of cffi on win32 with newer vc compilers
+    # XXX move this to a build slave step?
+    status, stdout, stderr = run_subprocess(str(pypy_c), ['-c', 'import setuptools'])
+    if status  != 0:
+        status, stdout, stderr = run_subprocess(str(pypy_c), ['-m', 'ensurepip'])
     failures = []
 
     for key, module in sorted(cffi_build_scripts.items()):
diff --git a/pypy/tool/release/package.py b/pypy/tool/release/package.py
--- a/pypy/tool/release/package.py
+++ b/pypy/tool/release/package.py
@@ -20,6 +20,7 @@
 import py
 import fnmatch
 import subprocess
+from pypy.tool.release.smartstrip import smartstrip
 
 USE_ZIPFILE_MODULE = sys.platform == 'win32'
 
@@ -223,15 +224,8 @@
     old_dir = os.getcwd()
     try:
         os.chdir(str(builddir))
-        if not options.nostrip:
-            for source, target in binaries:
-                if sys.platform == 'win32':
-                    pass
-                elif sys.platform == 'darwin':
-                    # 'strip' fun: see issue #587 for why -x
-                    os.system("strip -x " + str(bindir.join(target)))    # ignore errors
-                else:
-                    os.system("strip " + str(bindir.join(target)))    # ignore errors
+        for source, target in binaries:
+            smartstrip(bindir.join(target), keep_debug=options.keep_debug)
         #
         if USE_ZIPFILE_MODULE:
             import zipfile
@@ -297,8 +291,8 @@
                     help='do not build and package the %r cffi module' % (key,))
     parser.add_argument('--without-cffi', dest='no_cffi', action='store_true',
         help='skip building *all* the cffi modules listed above')
-    parser.add_argument('--nostrip', dest='nostrip', action='store_true',
-        help='do not strip the exe, making it ~10MB larger')
+    parser.add_argument('--no-keep-debug', dest='keep_debug',
+                        action='store_false', help='do not keep debug symbols')
     parser.add_argument('--rename_pypy_c', dest='pypy_c', type=str, default=pypy_exe,
         help='target executable name, defaults to "%s"' % pypy_exe)
     parser.add_argument('--archive-name', dest='name', type=str, default='',
@@ -317,8 +311,8 @@
                         '(default on OS X)')
     options = parser.parse_args(args)
 
-    if os.environ.has_key("PYPY_PACKAGE_NOSTRIP"):
-        options.nostrip = True
+    if os.environ.has_key("PYPY_PACKAGE_NOKEEPDEBUG"):
+        options.keep_debug = False
     if os.environ.has_key("PYPY_PACKAGE_WITHOUTTK"):
         options.no_tk = True
     if os.environ.has_key("PYPY_EMBED_DEPENDENCIES"):
diff --git a/pypy/tool/release/smartstrip.py b/pypy/tool/release/smartstrip.py
new file mode 100644
--- /dev/null
+++ b/pypy/tool/release/smartstrip.py
@@ -0,0 +1,32 @@
+"""
+Strip symbols from an executable, but keep them in a .debug file
+"""
+
+import sys
+import os
+import py
+
+def _strip(exe):
+    if sys.platform == 'win32':
+        pass
+    elif sys.platform == 'darwin':
+        # 'strip' fun: see issue #587 for why -x
+        os.system("strip -x " + str(exe))    # ignore errors
+    else:
+        os.system("strip " + str(exe))       # ignore errors
+
+def _extract_debug_symbols(exe, debug):
+    if sys.platform == 'linux2':
+        os.system("objcopy --only-keep-debug %s %s" % (exe, debug))
+        os.system("objcopy --add-gnu-debuglink=%s %s" % (debug, exe))
+
+def smartstrip(exe, keep_debug=True):
+    exe = py.path.local(exe)
+    debug = py.path.local(str(exe) + '.debug')
+    if keep_debug:
+        _extract_debug_symbols(exe, debug)
+    _strip(exe)
+
+
+if __name__ == '__main__':
+    smartstrip(sys.argv[1])
diff --git a/pypy/tool/release/test/test_smartstrip.py b/pypy/tool/release/test/test_smartstrip.py
new file mode 100644
--- /dev/null
+++ b/pypy/tool/release/test/test_smartstrip.py
@@ -0,0 +1,50 @@
+import pytest
+import sys
+import os
+from commands import getoutput
+from pypy.tool.release.smartstrip import smartstrip
+
+ at pytest.fixture
+def exe(tmpdir):
+    src = tmpdir.join("myprog.c")
+    src.write("""
+    int foo(int a, int b) {
+        return a+b;
+    }
+    int main(void) { }
+    """)
+    exe = tmpdir.join("myprog")
+    ret = os.system("gcc -o %s %s" % (exe, src))
+    assert ret == 0
+    return exe
+
+def info_symbol(exe, symbol):
+    out = getoutput("gdb %s -ex 'info symbol %s' -ex 'quit'" % (exe, symbol))
+    lines = out.splitlines()
+    return lines[-1]
+
+ at pytest.mark.skipif(sys.platform == 'win32',
+                    reason='strip not supported on windows')
+class TestSmarStrip(object):
+
+    def test_info_symbol(self, exe):
+        info = info_symbol(exe, "foo")
+        assert info == "foo in section .text"
+
+    def test_strip(self, exe):
+        smartstrip(exe, keep_debug=False)
+        info = info_symbol(exe, "foo")
+        assert info.startswith("No symbol table is loaded")
+
+    @pytest.mark.skipif(sys.platform != 'linux2',
+                        reason='keep_debug not supported')
+    def test_keep_debug(self, exe, tmpdir):
+        smartstrip(exe, keep_debug=True)
+        debug = tmpdir.join("myprog.debug")
+        assert debug.check(file=True)
+        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")


More information about the pypy-commit mailing list