Skip to content

Commit 1c630cb

Browse files
authored
Merge pull request #1883 from JDevlieghere/upstream-python-changes
Upstream python changes
2 parents ff1dd47 + 192b341 commit 1c630cb

File tree

22 files changed

+88
-149
lines changed

22 files changed

+88
-149
lines changed

lldb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ endif()
4545

4646
if (LLDB_ENABLE_PYTHON)
4747
execute_process(
48-
COMMAND ${PYTHON_EXECUTABLE}
48+
COMMAND ${Python3_EXECUTABLE}
4949
-c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(True, False, ''))"
5050
OUTPUT_VARIABLE LLDB_PYTHON_DEFAULT_RELATIVE_PATH
5151
OUTPUT_STRIP_TRAILING_WHITESPACE)

lldb/bindings/python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function(create_python_package swig_target working_dir pkg_dir)
2828
set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir})
2929
endif()
3030
if(NOT ARG_NOINIT)
31-
set(init_cmd COMMAND ${PYTHON_EXECUTABLE}
31+
set(init_cmd COMMAND ${Python3_EXECUTABLE}
3232
"${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py"
3333
"${pkg_dir}" ${ARG_FILES})
3434
endif()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#.rst:
2+
# FindPythonAndSwig
3+
# -----------
4+
#
5+
# Find the python interpreter and libraries as a whole.
6+
7+
macro(FindPython3)
8+
# Use PYTHON_HOME as a hint to find Python 3.
9+
set(Python3_ROOT_DIR "${PYTHON_HOME}")
10+
find_package(Python3 COMPONENTS Interpreter Development)
11+
if(Python3_FOUND AND Python3_Interpreter_FOUND)
12+
13+
# The install name for the Python 3 framework in Xcode is relative to
14+
# the framework's location and not the dylib itself.
15+
#
16+
# @rpath/Python3.framework/Versions/3.x/Python3
17+
#
18+
# This means that we need to compute the path to the Python3.framework
19+
# and use that as the RPATH instead of the usual dylib's directory.
20+
#
21+
# The check below shouldn't match Homebrew's Python framework as it is
22+
# called Python.framework instead of Python3.framework.
23+
if (APPLE AND Python3_LIBRARIES MATCHES "Python3.framework")
24+
string(FIND "${Python3_LIBRARIES}" "Python3.framework" python_framework_pos)
25+
string(SUBSTRING "${Python3_LIBRARIES}" "0" ${python_framework_pos} Python3_RPATH)
26+
endif()
27+
28+
set(PYTHON3_FOUND TRUE)
29+
mark_as_advanced(
30+
Python3_LIBRARIES
31+
Python3_INCLUDE_DIRS
32+
Python3_EXECUTABLE
33+
Python3_RPATH
34+
SWIG_EXECUTABLE)
35+
endif()
36+
endmacro()
37+
38+
if(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND SWIG_EXECUTABLE)
39+
set(PYTHONANDSWIG_FOUND TRUE)
40+
else()
41+
find_package(SWIG 2.0)
42+
if (SWIG_FOUND)
43+
FindPython3()
44+
else()
45+
message(STATUS "SWIG 2 or later is required for Python support in LLDB but could not be found")
46+
endif()
47+
48+
include(FindPackageHandleStandardArgs)
49+
find_package_handle_standard_args(PythonAndSwig
50+
FOUND_VAR
51+
PYTHONANDSWIG_FOUND
52+
REQUIRED_VARS
53+
Python3_LIBRARIES
54+
Python3_INCLUDE_DIRS
55+
Python3_EXECUTABLE
56+
SWIG_EXECUTABLE)
57+
endif()

lldb/cmake/modules/FindPythonInterpAndLibs.cmake

Lines changed: 0 additions & 113 deletions
This file was deleted.

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" Li
5656
add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)
5757
add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
5858
add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)
59-
add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
59+
add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
6060
add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
6161

6262
option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install a copy of it" OFF)
@@ -79,11 +79,6 @@ if(LLDB_BUILD_FRAMEWORK)
7979
if(NOT APPLE)
8080
message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms")
8181
endif()
82-
# CMake 3.6 did not correctly emit POST_BUILD commands for Apple Framework targets
83-
# CMake < 3.8 did not have the BUILD_RPATH target property
84-
if(CMAKE_VERSION VERSION_LESS 3.8)
85-
message(FATAL_ERROR "LLDB_BUILD_FRAMEWORK is not supported on CMake < 3.8")
86-
endif()
8782

8883
set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")
8984
set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework")
@@ -148,9 +143,9 @@ if (LLDB_ENABLE_PYTHON)
148143
"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python."
149144
${default_embed_python_home})
150145

151-
include_directories(${PYTHON_INCLUDE_DIRS})
146+
include_directories(${Python3_INCLUDE_DIRS})
152147
if (LLDB_EMBED_PYTHON_HOME)
153-
get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
148+
get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)
154149
set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
155150
"Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.")
156151
endif()

lldb/source/API/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX A
121121
set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
122122
endif()
123123

124-
if(PYTHON_RPATH)
125-
set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${PYTHON_RPATH}")
126-
set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH "${PYTHON_RPATH}")
124+
if(Python3_RPATH)
125+
set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
126+
set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}")
127127
endif()
128128

129129
if (MSVC)
@@ -187,9 +187,9 @@ endif()
187187

188188
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
189189
# Only MSVC has the ABI compatibility problem and avoids using FindPythonLibs,
190-
# so only it needs to explicitly link against ${PYTHON_LIBRARIES}
190+
# so only it needs to explicitly link against ${Python3_LIBRARIES}
191191
if (MSVC AND LLDB_ENABLE_PYTHON)
192-
target_link_libraries(liblldb PRIVATE ${PYTHON_LIBRARIES})
192+
target_link_libraries(liblldb PRIVATE ${Python3_LIBRARIES})
193193
endif()
194194
else()
195195
set_target_properties(liblldb

lldb/source/Plugins/ObjectFile/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ add_subdirectory(ELF)
33
add_subdirectory(Mach-O)
44
add_subdirectory(PECOFF)
55
add_subdirectory(JIT)
6-
add_subdirectory(wasm)
6+
add_subdirectory(wasm)

lldb/source/Plugins/ScriptInterpreter/None/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ add_lldb_library(lldbPluginScriptInterpreterNone PLUGIN
44
LINK_LIBS
55
lldbCore
66
lldbInterpreter
7-
)
7+
)

lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN
1919
lldbHost
2020
lldbInterpreter
2121
lldbTarget
22-
${PYTHON_LIBRARIES}
22+
${Python3_LIBRARIES}
2323
${LLDB_LIBEDIT_LIBS}
2424

2525
LINK_COMPONENTS

lldb/test/API/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(add_python_test_target name test_script args comment)
22
set(PYTHON_TEST_COMMAND
3-
${PYTHON_EXECUTABLE}
3+
${Python3_EXECUTABLE}
44
${test_script}
55
${args}
66
)

0 commit comments

Comments
 (0)