Use buildflags and only build one attach_linux binary
authorJulian Gilbey <jdg@debian.org>
Mon, 5 Sep 2022 20:56:24 +0000 (21:56 +0100)
committerJulian Gilbey <jdg@debian.org>
Mon, 5 Sep 2022 20:56:24 +0000 (21:56 +0100)
Forwarded: not-needed
Last-Update: 2022-06-16

 Original patch: William Grzybowski <william@grzy.org>
 The original code tries to build both 32-bit and 64-bit versions.
 This patched version only builds one copy of the library for the
 build architecture.

Gbp-Pq: Name improve-compilation-system.patch

pydevd_attach_to_process/add_code_to_python_process.py
pydevd_tracing.py

index 462feae9b29e2d3f156180ce0348caaa5b153d62..acdeb183cdda1df5e5ed0be680e38d737ea0a200 100644 (file)
@@ -76,7 +76,6 @@ import subprocess
 import sys
 import time
 from contextlib import contextmanager
-import platform
 import traceback
 
 try:
@@ -142,115 +141,14 @@ def get_target_filename(is_target_process_64=None, prefix=None, extension=None):
     # and not from the debugger).
     libdir = os.path.dirname(__file__)
 
-    if is_target_process_64 is None:
-        if IS_WINDOWS:
-            # i.e.: On windows the target process could have a different bitness (32bit is emulated on 64bit).
-            raise AssertionError("On windows it's expected that the target bitness is specified.")
-
-        # For other platforms, just use the the same bitness of the process we're running in.
-        is_target_process_64 = is_python_64bit()
-
-    arch = ''
-    if IS_WINDOWS:
-        # prefer not using platform.machine() when possible (it's a bit heavyweight as it may
-        # spawn a subprocess).
-        arch = os.environ.get("PROCESSOR_ARCHITEW6432", os.environ.get('PROCESSOR_ARCHITECTURE', ''))
-
-    if not arch:
-        arch = platform.machine()
-        if not arch:
-            print('platform.machine() did not return valid value.')  # This shouldn't happen...
-            return None
-
-    if IS_WINDOWS:
-        if not extension:
-            extension = '.dll'
-        suffix_64 = 'amd64'
-        suffix_32 = 'x86'
-
-    elif IS_LINUX:
-        if not extension:
-            extension = '.so'
-        suffix_64 = 'amd64'
-        suffix_32 = 'x86'
-
-    elif IS_MAC:
-        if not extension:
-            extension = '.dylib'
-        suffix_64 = 'x86_64'
-        suffix_32 = 'x86'
+    # This is a very simplified version for Debian builds
 
-    else:
+    if not IS_LINUX:
         print('Unable to attach to process in platform: %s', sys.platform)
         return None
 
-    if arch.lower() not in ('amd64', 'x86', 'x86_64', 'i386', 'x86'):
-        # We don't support this processor by default. Still, let's support the case where the
-        # user manually compiled it himself with some heuristics.
-        #
-        # Ideally the user would provide a library in the format: "attach_<arch>.<extension>"
-        # based on the way it's currently compiled -- see:
-        # - windows/compile_windows.bat
-        # - linux_and_mac/compile_linux.sh
-        # - linux_and_mac/compile_mac.sh
-
-        try:
-            found = [name for name in os.listdir(libdir) if name.startswith('attach_') and name.endswith(extension)]
-        except:
-            print('Error listing dir: %s' % (libdir,))
-            traceback.print_exc()
-            return None
-
-        if prefix:
-            expected_name = prefix + arch + extension
-            expected_name_linux = prefix + 'linux_' + arch + extension
-        else:
-            # Default is looking for the attach_ / attach_linux
-            expected_name = 'attach_' + arch + extension
-            expected_name_linux = 'attach_linux_' + arch + extension
-
-        filename = None
-        if expected_name in found:  # Heuristic: user compiled with "attach_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name)
-
-        elif IS_LINUX and expected_name_linux in found:  # Heuristic: user compiled with "attach_linux_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name_linux)
-
-        elif len(found) == 1:  # Heuristic: user removed all libraries and just left his own lib.
-            filename = os.path.join(libdir, found[0])
-
-        else:  # Heuristic: there's one additional library which doesn't seem to be our own. Find the odd one.
-            filtered = [name for name in found if not name.endswith((suffix_64 + extension, suffix_32 + extension))]
-            if len(filtered) == 1:  # If more than one is available we can't be sure...
-                filename = os.path.join(libdir, found[0])
-
-        if filename is None:
-            print(
-                'Unable to attach to process in arch: %s (did not find %s in %s).' % (
-                    arch, expected_name, libdir
-                )
-            )
-            return None
-
-        print('Using %s in arch: %s.' % (filename, arch))
-
-    else:
-        if is_target_process_64:
-            suffix = suffix_64
-        else:
-            suffix = suffix_32
-
-        if not prefix:
-            # Default is looking for the attach_ / attach_linux
-            if IS_WINDOWS or IS_MAC:  # just the extension changes
-                prefix = 'attach_'
-            elif IS_LINUX:
-                prefix = 'attach_linux_'  # historically it has a different name
-            else:
-                print('Unable to attach to process in platform: %s' % (sys.platform,))
-                return None
-
-        filename = os.path.join(libdir, '%s%s%s' % (prefix, suffix, extension))
+    libname = 'attach.so'
+    filename = os.path.join(libdir, libname)
 
     if not os.path.exists(filename):
         print('Expected: %s to exist.' % (filename,))
index 5061a53363650abc6555062d00bacb864b237602..ad9dc9f1e7b952cda59b4d30aab2fdda64a559c8 100644 (file)
@@ -4,7 +4,6 @@ from _pydevd_bundle.pydevd_constants import get_frame, IS_CPYTHON, IS_64BIT_PROC
 from _pydev_bundle._pydev_saved_modules import thread, threading
 from _pydev_bundle import pydev_log, pydev_monkey
 import os.path
-import platform
 import ctypes
 from io import StringIO
 import sys
@@ -138,99 +137,16 @@ def get_python_helper_lib_filename():
     # and not from the debugger).
     libdir = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process')
 
-    arch = ''
-    if IS_WINDOWS:
-        # prefer not using platform.machine() when possible (it's a bit heavyweight as it may
-        # spawn a subprocess).
-        arch = os.environ.get("PROCESSOR_ARCHITEW6432", os.environ.get('PROCESSOR_ARCHITECTURE', ''))
+    # This is a very simplified version for Debian builds
 
-    if not arch:
-        arch = platform.machine()
-        if not arch:
-            pydev_log.info('platform.machine() did not return valid value.')  # This shouldn't happen...
-            return None
-
-    if IS_WINDOWS:
-        extension = '.dll'
-        suffix_64 = 'amd64'
-        suffix_32 = 'x86'
-
-    elif IS_LINUX:
-        extension = '.so'
-        suffix_64 = 'amd64'
-        suffix_32 = 'x86'
-
-    elif IS_MAC:
-        extension = '.dylib'
-        suffix_64 = 'x86_64'
-        suffix_32 = 'x86'
-
-    else:
-        pydev_log.info('Unable to set trace to all threads in platform: %s', sys.platform)
+    if not IS_LINUX:
+        print('Unable to attach to process in platform: %s', sys.platform)
         return None
 
-    if arch.lower() not in ('amd64', 'x86', 'x86_64', 'i386', 'x86'):
-        # We don't support this processor by default. Still, let's support the case where the
-        # user manually compiled it himself with some heuristics.
-        #
-        # Ideally the user would provide a library in the format: "attach_<arch>.<extension>"
-        # based on the way it's currently compiled -- see:
-        # - windows/compile_windows.bat
-        # - linux_and_mac/compile_linux.sh
-        # - linux_and_mac/compile_mac.sh
-
-        try:
-            found = [name for name in os.listdir(libdir) if name.startswith('attach_') and name.endswith(extension)]
-        except:
-            if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1:
-                # There is no need to show this unless debug tracing is enabled.
-                pydev_log.exception('Error listing dir: %s', libdir)
-            return None
-
-        expected_name = 'attach_' + arch + extension
-        expected_name_linux = 'attach_linux_' + arch + extension
-
-        filename = None
-        if expected_name in found:  # Heuristic: user compiled with "attach_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name)
-
-        elif IS_LINUX and expected_name_linux in found:  # Heuristic: user compiled with "attach_linux_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name_linux)
-
-        elif len(found) == 1:  # Heuristic: user removed all libraries and just left his own lib.
-            filename = os.path.join(libdir, found[0])
-
-        else:  # Heuristic: there's one additional library which doesn't seem to be our own. Find the odd one.
-            filtered = [name for name in found if not name.endswith((suffix_64 + extension, suffix_32 + extension))]
-            if len(filtered) == 1:  # If more than one is available we can't be sure...
-                filename = os.path.join(libdir, found[0])
-
-        if filename is None:
-            pydev_log.info(
-                'Unable to set trace to all threads in arch: %s (did not find a %s lib in %s).',
-                arch, expected_name, libdir
-
-            )
-            return None
-
-        pydev_log.info('Using %s lib in arch: %s.', filename, arch)
-
-    else:
-        # Happy path for which we have pre-compiled binaries.
-        if IS_64BIT_PROCESS:
-            suffix = suffix_64
-        else:
-            suffix = suffix_32
-
-        if IS_WINDOWS or IS_MAC:  # just the extension changes
-            prefix = 'attach_'
-        elif IS_LINUX:  #
-            prefix = 'attach_linux_'  # historically it has a different name
-        else:
-            pydev_log.info('Unable to set trace to all threads in platform: %s', sys.platform)
-            return None
+    libname = 'attach.so'
+    filename = os.path.join(libdir, libname)
 
-        filename = os.path.join(libdir, '%s%s%s' % (prefix, suffix, extension))
+    pydev_log.info('Using %s lib.', filename)
 
     if not os.path.exists(filename):
         pydev_log.critical('Expected: %s to exist.', filename)