Index: scripts/get_relative_lib_dir.py =================================================================== --- /dev/null +++ scripts/get_relative_lib_dir.py @@ -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) Index: source/Host/CMakeLists.txt =================================================================== --- source/Host/CMakeLists.txt +++ source/Host/CMakeLists.txt @@ -41,6 +41,11 @@ 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 @@ 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 @@ 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}) Index: source/Host/posix/HostInfoPosix.cpp =================================================================== --- source/Host/posix/HostInfoPosix.cpp +++ source/Host/posix/HostInfoPosix.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -214,6 +215,19 @@ 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 @@ file_spec.GetDirectory().SetCString(raw_path); return true; +#endif #else return false; #endif Index: www/build.html =================================================================== --- www/build.html +++ www/build.html @@ -202,7 +202,7 @@
  • Python
  • So for example, on a Fedora system one might run:

    - > yum install swig python-devel libedit-devel + > yum install libedit-devel libxml2-devel ncurses-devel python-devel swig

    On a Debian or Ubuntu system one might run:

    > sudo apt-get install build-essential subversion swig python2.7-dev libedit-dev libncurses5-dev

    or