[Lldb-commits] [lldb] r250093 - Support RHEL 7 and similar systems that use architecture-specific Python lib dirs

Todd Fiala via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 12 13:12:28 PDT 2015


Author: tfiala
Date: Mon Oct 12 15:12:27 2015
New Revision: 250093

URL: http://llvm.org/viewvc/llvm-project?rev=250093&view=rev
Log:
Support RHEL 7 and similar systems that use architecture-specific Python lib dirs

This change commits: http://reviews.llvm.org/D13625

Added:
    lldb/trunk/scripts/get_relative_lib_dir.py
Modified:
    lldb/trunk/source/Host/CMakeLists.txt
    lldb/trunk/source/Host/posix/HostInfoPosix.cpp
    lldb/trunk/www/build.html

Added: lldb/trunk/scripts/get_relative_lib_dir.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/get_relative_lib_dir.py?rev=250093&view=auto
==============================================================================
--- lldb/trunk/scripts/get_relative_lib_dir.py (added)
+++ lldb/trunk/scripts/get_relative_lib_dir.py Mon Oct 12 15:12:27 2015
@@ -0,0 +1,44 @@
+import distutils.sysconfig
+import os
+import platform
+import re
+import sys
+
+
+def get_python_relative_libdir():
+    """Returns the appropropriate python libdir relative to the build directory.
+
+    @param exe_path the path to the lldb executable
+
+    @return the python path that needs to be added to sys.path (PYTHONPATH)
+    in order to find the lldb python module.
+    """
+    if platform.system() != 'Linux':
+        return None
+
+    # We currently have a bug in lldb -P that does not account for
+    # architecture variants in python paths for
+    # architecture-specific modules.  Handle the lookup here.
+    # When that bug is fixed, we should just ask lldb for the
+    # right answer always.
+    arch_specific_libdir = distutils.sysconfig.get_python_lib(True, False)
+    split_libdir = arch_specific_libdir.split(os.sep)
+    lib_re = re.compile(r"^lib.+$")
+
+    for i in range(len(split_libdir)):
+        match = lib_re.match(split_libdir[i])
+        if match is not None:
+            # We'll call this the relative root of the lib dir.
+            # Things like RHEL will have an arch-specific python
+            # lib dir, which isn't 'lib' on x86_64.
+            return os.sep.join(split_libdir[i:])
+    # Didn't resolve it.
+    return None
+
+if __name__ == '__main__':
+    lib_dir = get_python_relative_libdir()
+    if lib_dir is not None:
+        sys.stdout.write(lib_dir)
+        sys.exit(0)
+    else:
+        sys.exit(1)

Modified: lldb/trunk/source/Host/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/CMakeLists.txt?rev=250093&r1=250092&r2=250093&view=diff
==============================================================================
--- lldb/trunk/source/Host/CMakeLists.txt (original)
+++ lldb/trunk/source/Host/CMakeLists.txt Mon Oct 12 15:12:27 2015
@@ -41,6 +41,11 @@ add_host_subdirectory(common
   common/XML.cpp
   )
 
+# Keep track of whether we want to provide a define for the
+# Python's architecture-specific lib path (i.e. where a
+# Python lldb module would go).
+set (get_python_libdir 0)
+
 if (NOT LLDB_DISABLE_LIBEDIT)
   add_host_subdirectory(common
     common/Editline.cpp
@@ -70,6 +75,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
     windows/Windows.cpp
     )
 else()
+  if (NOT LLDB_DISABLE_PYTHON)
+    # We'll grab the arch-specific python libdir on POSIX systems.
+    set (get_python_libdir 1)
+  endif()
+
   add_host_subdirectory(posix
     posix/FileSystem.cpp
     posix/HostInfoPosix.cpp
@@ -133,4 +143,17 @@ else()
   endif()
 endif()
 
+if (${get_python_libdir})
+  # Call a python script to gather the arch-specific libdir for
+  # modules like the lldb module.
+  execute_process(
+    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/get_relative_lib_dir.py
+    RESULT_VARIABLE get_libdir_status
+    OUTPUT_VARIABLE relative_libdir
+    )
+  if (get_libdir_status EQUAL 0)
+    add_definitions(-DLLDB_PYTHON_RELATIVE_LIBDIR="${relative_libdir}")
+  endif()
+endif()
+
 add_lldb_library(lldbHost ${HOST_SOURCES})

Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=250093&r1=250092&r2=250093&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Mon Oct 12 15:12:27 2015
@@ -22,6 +22,7 @@
 #include <mutex>
 #include <netdb.h>
 #include <pwd.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -214,6 +215,19 @@ HostInfoPosix::ComputePythonDirectory(Fi
     char raw_path[PATH_MAX];
     lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
 
+#if defined(LLDB_PYTHON_RELATIVE_LIBDIR)
+    // Build the path by backing out of the lib dir, then building
+    // with whatever the real python interpreter uses.  (e.g. lib
+    // for most, lib64 on RHEL x86_64).
+    char python_path[PATH_MAX];
+    ::snprintf(python_path, sizeof(python_path), "%s/../%s", raw_path, LLDB_PYTHON_RELATIVE_LIBDIR);
+
+    char final_path[PATH_MAX];
+    realpath(python_path, final_path);
+    file_spec.GetDirectory().SetCString(final_path);
+
+    return true;
+#else
     llvm::SmallString<256> python_version_dir;
     llvm::raw_svector_ostream os(python_version_dir);
     os << "/python" << PY_MAJOR_VERSION << '.' << PY_MINOR_VERSION << "/site-packages";
@@ -223,6 +237,7 @@ HostInfoPosix::ComputePythonDirectory(Fi
 
     file_spec.GetDirectory().SetCString(raw_path);
     return true;
+#endif
 #else
     return false;
 #endif

Modified: lldb/trunk/www/build.html
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/www/build.html?rev=250093&r1=250092&r2=250093&view=diff
==============================================================================
--- lldb/trunk/www/build.html (original)
+++ lldb/trunk/www/build.html Mon Oct 12 15:12:27 2015
@@ -202,7 +202,7 @@
               <li><a href="http://www.python.org">Python</a></li>
             </ul>
             <p>So for example, on a Fedora system one might run:</p>
-            <code>> yum install swig python-devel libedit-devel</code>
+            <code>> yum install libedit-devel libxml2-devel ncurses-devel python-devel swig</code>
             <p>On a Debian or Ubuntu system one might run:</p>
             <code>> sudo apt-get install build-essential subversion swig python2.7-dev libedit-dev libncurses5-dev </code>
             <p>or</p>




More information about the lldb-commits mailing list