hhb updated this revision to Diff 221251.
hhb added a comment.

Fix symbol linker


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67866/new/

https://reviews.llvm.org/D67866

Files:
  lldb/CMakeLists.txt
  lldb/scripts/CMakeLists.txt
  lldb/scripts/Python/finishSwigPythonLLDB.py
  lldb/scripts/finishSwigWrapperClasses.py
  lldb/scripts/get_relative_lib_dir.py
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
@@ -48,8 +48,7 @@
 
 protected:
   static void ComputePythonDirForApple(llvm::SmallVectorImpl<char> &path);
-  static void ComputePythonDirForPosix(llvm::SmallVectorImpl<char> &path);
-  static void ComputePythonDirForWindows(llvm::SmallVectorImpl<char> &path);
+  static void ComputePythonDir(llvm::SmallVectorImpl<char> &path);
 };
 } // namespace lldb_private
 
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -28,6 +28,7 @@
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/DataFormatters/TypeSummary.h"
+#include "lldb/Host/Config.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
@@ -302,35 +303,22 @@
   auto rend = llvm::sys::path::rend(path_ref);
   auto framework = std::find(rbegin, rend, "LLDB.framework");
   if (framework == rend) {
-    ComputePythonDirForPosix(path);
+    ComputePythonDir(path);
     return;
   }
   path.resize(framework - rend);
   llvm::sys::path::append(path, style, "LLDB.framework", "Resources", "Python");
 }
 
-void ScriptInterpreterPython::ComputePythonDirForPosix(
+void ScriptInterpreterPython::ComputePythonDir(
     llvm::SmallVectorImpl<char> &path) {
-  auto style = llvm::sys::path::Style::posix;
-#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).
-  llvm::sys::path::remove_filename(path, style);
-  llvm::sys::path::append(path, style, LLDB_PYTHON_RELATIVE_LIBDIR);
+#if defined(_WIN32)
+    auto style = llvm::sys::path::Style::windows;
 #else
-  llvm::sys::path::append(path, style,
-                          "python" + llvm::Twine(PY_MAJOR_VERSION) + "." +
-                              llvm::Twine(PY_MINOR_VERSION),
-                          "site-packages");
+    auto style = llvm::sys::path::Style::posix;
 #endif
-}
-
-void ScriptInterpreterPython::ComputePythonDirForWindows(
-    llvm::SmallVectorImpl<char> &path) {
-  auto style = llvm::sys::path::Style::windows;
   llvm::sys::path::remove_filename(path, style);
-  llvm::sys::path::append(path, style, "lib", "site-packages");
+  llvm::sys::path::append(path, style, "lib" LLDB_LIBDIR_SUFFIX, "site-packages");
 
   // This will be injected directly through FileSpec.GetDirectory().SetString(),
   // so we need to normalize manually.
@@ -347,10 +335,8 @@
 
 #if defined(__APPLE__)
     ComputePythonDirForApple(path);
-#elif defined(_WIN32)
-    ComputePythonDirForWindows(path);
 #else
-    ComputePythonDirForPosix(path);
+    ComputePythonDir(path);
 #endif
     spec.GetDirectory().SetString(path);
     return spec;
Index: lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -1,16 +1,3 @@
-if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
-  # 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(lldbPluginScriptInterpreterPython PLUGIN
   PythonDataObjects.cpp
   PythonExceptionState.cpp
Index: lldb/scripts/get_relative_lib_dir.py
===================================================================
--- lldb/scripts/get_relative_lib_dir.py
+++ /dev/null
@@ -1,44 +0,0 @@
-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: lldb/scripts/finishSwigWrapperClasses.py
===================================================================
--- lldb/scripts/finishSwigWrapperClasses.py
+++ lldb/scripts/finishSwigWrapperClasses.py
@@ -5,8 +5,6 @@
 
     Overview:       Python script(s) to finish off the SWIG Python C++ Script
                     Bridge wrapper code on the Windows/LINUX/OSX platform.
-                    The Python scripts are equivalent to the shell script (.sh)
-                    files.
                     We use SWIG to create a C++ file containing the appropriate
                     wrapper classes and functions for each scripting language,
                     before liblldb is built (thus the C++ file can be compiled
@@ -293,11 +291,9 @@
 
     # Iterate script directory find any script language directories
     for scriptLang in listDirs:
-        # __pycache__ is a magic directory in Python 3 that holds .pyc files
-        if scriptLang != "__pycache__" and scriptLang != "swig_bot_lib":
-            dbg.dump_text("Executing language script for \'%s\'" % scriptLang)
-            nResult, strStatusMsg = run_post_process(
-                scriptLang, strFinishFileName, vDictArgs)
+        dbg.dump_text("Executing language script for \'%s\'" % scriptLang)
+        nResult, strStatusMsg = run_post_process(
+            scriptLang, strFinishFileName, vDictArgs)
         if nResult < 0:
             break
 
Index: lldb/scripts/Python/finishSwigPythonLLDB.py
===================================================================
--- lldb/scripts/Python/finishSwigPythonLLDB.py
+++ lldb/scripts/Python/finishSwigPythonLLDB.py
@@ -5,8 +5,6 @@
 
     Overview:       Python script(s) to post process SWIG Python C++ Script
                     Bridge wrapper code on the Windows/LINUX/OSX platform.
-                    The Python scripts are equivalent to the shell script (.sh)
-                    files.
                     For the Python script interpreter (external to liblldb) to
                     be able to import and use the lldb module, there must be
                     two files, lldb.py and _lldb.so, that it can find. lldb.py
@@ -54,6 +52,7 @@
 strErrMsgLLDBPyFileNotNotFound = "Unable to locate lldb.py at path '%s'"
 strMsgCopyLLDBPy = "Copying lldb.py from '%s' to '%s'"
 strErrMsgFrameWkPyDirNotExist = "Unable to find the LLDB.framework directory '%s'"
+strErrMsgTargetDirNotExist = "Unable to find the --target directory '%s'"
 strMsgCreatePyPkgCopyPkgFile = "create_py_pkg: Copied file '%s' to folder '%s'"
 strMsgCreatePyPkgInitFile = "create_py_pkg: Creating pakage init file '%s'"
 strMsgCreatePyPkgMkDir = "create_py_pkg: Created folder '%s'"
@@ -386,14 +385,9 @@
         strBuildDir = os.path.join("..", "..", "..")
     else:
         # Resolve vstrSrcFile path relatively the build directory
-        if eOSType == utilsOsType.EnumOsType.Windows:
-            # On a Windows platform the vstrFrameworkPythonDir looks like:
-            # llvm\\build\\Lib\\site-packages\\lldb
-            strBuildDir = os.path.join("..", "..", "..")
-        else:
-            # On a UNIX style platform the vstrFrameworkPythonDir looks like:
-            # llvm/build/lib/python2.7/site-packages/lldb
-            strBuildDir = os.path.join("..", "..", "..", "..")
+        # vstrFrameworkPythonDir looks like:
+        # llvm/build/lib/site-packages/lldb
+        strBuildDir = os.path.join("..", "..", "..")
     strSrc = os.path.normcase(os.path.join(strBuildDir, vstrSrcFile))
 
     return make_symlink_native(vDictArgs, strSrc, strTarget)
@@ -617,7 +611,8 @@
 
 #++---------------------------------------------------------------------------
 # Details:  Determine where to put the files. Retrieve the directory path for
-#           Python's dist_packages/ site_package folder on a Windows platform.
+#           Python's dist_packages / site_package folder when build with llvm
+#           build system.
 # Args:     vDictArgs   - (R) Program input parameters.
 # Returns:  Bool - True = function success, False = failure.
 #           Str - Python Framework directory path.
@@ -626,39 +621,31 @@
 #--
 
 
-def get_framework_python_dir_windows(vDictArgs):
+def get_framework_python_dir_llvm(vDictArgs):
     dbg = utilsDebug.CDebugFnVerbose(
-        "Python script get_framework_python_dir_windows()")
+        "Python script get_framework_python_dir_llvm()")
     bOk = True
     strWkDir = ""
     strErrMsg = ""
 
+    dbg.dump_text("Built by LLVM")
     # We are being built by LLVM, so use the PYTHON_INSTALL_DIR argument,
     # and append the python version directory to the end of it.  Depending
     # on the system other stuff may need to be put here as well.
+    strWkDir = vDictArgs["--targetDir"]
     from distutils.sysconfig import get_python_lib
-    strPythonInstallDir = ""
-    bHaveArgPrefix = "--prefix" in vDictArgs
-    if bHaveArgPrefix:
-        strPythonInstallDir = os.path.normpath(vDictArgs["--prefix"])
-
-    bHaveArgCmakeBuildConfiguration = "--cmakeBuildConfiguration" in vDictArgs
-    if bHaveArgCmakeBuildConfiguration:
-        strPythonInstallDir = os.path.join(
-            strPythonInstallDir,
-            vDictArgs["--cmakeBuildConfiguration"])
-
-    if strPythonInstallDir.__len__() != 0:
-        strWkDir = get_python_lib(True, False, strPythonInstallDir)
+    if os.path.exists(strWkDir):
+        strWkDir = os.path.join(strWkDir, 'site-packages')
     else:
-        strWkDir = get_python_lib(True, False)
+        bOk = False
+        strErrMsg = strErrMsgTargetDirNotExist % strWkDir
     strWkDir = os.path.normcase(os.path.join(strWkDir, "lldb"))
 
     return (bOk, strWkDir, strErrMsg)
 
 #++---------------------------------------------------------------------------
-# Details:  Retrieve the directory path for Python's dist_packages/
-#           site_package folder on a UNIX style platform.
+# Details:  Retrieve the directory path for Python's dist_packages /
+#           site_package folder for xcode.
 # Args:     vDictArgs   - (R) Program input parameters.
 # Returns:  Bool - True = function success, False = failure.
 #           Str - Python Framework directory path.
@@ -667,32 +654,27 @@
 #--
 
 
-def get_framework_python_dir_other_platforms(vDictArgs):
+def get_framework_python_dir_xcode(vDictArgs):
     dbg = utilsDebug.CDebugFnVerbose(
-        "Python script get_framework_python_dir_other_platform()")
+        "Python script get_framework_python_dir_xcode()")
     bOk = True
     strWkDir = ""
     strErrMsg = ""
-    bDbg = "-d" in vDictArgs
 
-    bMakeFileCalled = "-m" in vDictArgs
-    if bMakeFileCalled:
-        dbg.dump_text("Built by LLVM")
-        return get_framework_python_dir_windows(vDictArgs)
+    bDbg = "-d" in vDictArgs
+    dbg.dump_text("Built by XCode")
+    # We are being built by XCode, so all the lldb Python files can go
+    # into the LLDB.framework/Resources/Python subdirectory.
+    strWkDir = vDictArgs["--targetDir"]
+    strWkDir = os.path.join(strWkDir, "LLDB.framework")
+    if os.path.exists(strWkDir):
+        if bDbg:
+            print((strMsgFoundLldbFrameWkDir % strWkDir))
+        strWkDir = os.path.join(strWkDir, "Resources", "Python", "lldb")
+        strWkDir = os.path.normcase(strWkDir)
     else:
-        dbg.dump_text("Built by XCode")
-        # We are being built by XCode, so all the lldb Python files can go
-        # into the LLDB.framework/Resources/Python subdirectory.
-        strWkDir = vDictArgs["--targetDir"]
-        strWkDir = os.path.join(strWkDir, "LLDB.framework")
-        if os.path.exists(strWkDir):
-            if bDbg:
-                print((strMsgFoundLldbFrameWkDir % strWkDir))
-            strWkDir = os.path.join(strWkDir, "Resources", "Python", "lldb")
-            strWkDir = os.path.normcase(strWkDir)
-        else:
-            bOk = False
-            strErrMsg = strErrMsgFrameWkPyDirNotExist % strWkDir
+        bOk = False
+        strErrMsg = strErrMsgFrameWkPyDirNotExist % strWkDir
 
     return (bOk, strWkDir, strErrMsg)
 
@@ -711,21 +693,12 @@
 def get_framework_python_dir(vDictArgs):
     dbg = utilsDebug.CDebugFnVerbose(
         "Python script get_framework_python_dir()")
-    bOk = True
-    strWkDir = ""
-    strErrMsg = ""
 
-    eOSType = utilsOsType.determine_os_type()
-    if eOSType == utilsOsType.EnumOsType.Unknown:
-        bOk = False
-        strErrMsg = strErrMsgOsTypeUnknown
-    elif eOSType == utilsOsType.EnumOsType.Windows:
-        bOk, strWkDir, strErrMsg = get_framework_python_dir_windows(vDictArgs)
+    bMakeFileCalled = "-m" in vDictArgs
+    if bMakeFileCalled:
+        return get_framework_python_dir_llvm(vDictArgs)
     else:
-        bOk, strWkDir, strErrMsg = get_framework_python_dir_other_platforms(
-            vDictArgs)
-
-    return (bOk, strWkDir, strErrMsg)
+        return get_framework_python_dir_xcode(vDictArgs)
 
 #++---------------------------------------------------------------------------
 # Details:  Retrieve the liblldb directory path, if it exists and is valid.
Index: lldb/scripts/CMakeLists.txt
===================================================================
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -40,17 +40,3 @@
   ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
   ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
 )
-
-if(NOT LLDB_BUILD_FRAMEWORK)
-  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
-    set(swig_python_subdir site-packages)
-  else()
-    set(swig_python_subdir python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
-  endif()
-
-  set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
-  set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
-
-  # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR})
-endif()
Index: lldb/CMakeLists.txt
===================================================================
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -231,6 +231,14 @@
             COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM
             COMMENT "Copying Python DLL to LLDB binaries directory.")
     endif ()
+
+    if(NOT LLDB_BUILD_FRAMEWORK)
+        set(SWIG_PYTHON_DIR ${liblldb_build_dir}/site-packages)
+        set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
+
+        # Install the LLDB python module
+        install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR})
+    endif()
 endif ()
 
 if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to