Skip to content

Commit 989f79d

Browse files
committed
LLDB: Generate and install Python.zip and shared library file
This way one can run lldb with python bindings and having the python runtime deployed. Change-Id: Ia576d7b64acf1dcd7204b351c528bc86f8238dc5 Reviewed-by: David Schulz <[email protected]>
1 parent 1eee682 commit 989f79d

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

lldb/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,54 @@ if (LLDB_ENABLE_PYTHON)
7171
endif()
7272
endif()
7373
endforeach()
74+
75+
# For Python3.dll and Python3.zip deployment
76+
find_package(Python3 3.8 COMPONENTS Development)
77+
78+
if (NOT ${Python3_Development_FOUND})
79+
message(WARNING "PythonLibs (at least version 3.8) not found. qtcreatorcdbext will be built without Python support.")
80+
return()
81+
endif()
82+
83+
set(PythonRegex "^(.*)/(.*)/(python([0-9]+))${CMAKE_IMPORT_LIBRARY_SUFFIX}$")
84+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
85+
set(PythonRegex "^(.*)/(.*)/(python([0-9]+)_d)${CMAKE_IMPORT_LIBRARY_SUFFIX}$")
86+
endif()
87+
88+
foreach(lib IN LISTS Python3_LIBRARIES)
89+
if (lib MATCHES ${PythonRegex})
90+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
91+
set(PythonZipFileName "python${CMAKE_MATCH_4}_d.zip")
92+
else()
93+
set(PythonZipFileName "python${CMAKE_MATCH_4}.zip")
94+
endif()
95+
set(PythonNameWithVersion "${CMAKE_MATCH_3}")
96+
97+
set(PythonDll "${CMAKE_MATCH_1}/${PythonNameWithVersion}${CMAKE_SHARED_LIBRARY_SUFFIX}")
98+
set(PythonExe "${CMAKE_MATCH_1}/python${CMAKE_EXECUTABLE_SUFFIX}")
99+
set(PythonZip "${CMAKE_MATCH_1}/${PythonZipFileName}")
100+
101+
break()
102+
endif()
103+
endforeach()
104+
105+
if (NOT EXISTS "${PythonZip}" AND
106+
NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
107+
include(CreatePythonXY)
108+
create_python_xy("${PythonExe}" "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
109+
endif()
110+
111+
if (NOT EXISTS "${PythonZip}" AND
112+
EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
113+
set(PythonZip "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
114+
endif()
115+
116+
list(APPEND deployPythonFiles "${PythonDll}")
117+
list(APPEND deployPythonFiles "${PythonZip}")
118+
119+
install(FILES ${deployPythonFiles}
120+
DESTINATION ${CMAKE_INSTALL_BINDIR})
121+
74122
endif ()
75123

76124
if (LLDB_ENABLE_LUA)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# create_python_xy function will precompile the Python/lib/*.py files
2+
# and create a zip file containing all the pyc files
3+
function(create_python_xy PythonExe PythonZipFilePath)
4+
get_filename_component(python_lib_dir "${PythonExe}" DIRECTORY)
5+
get_filename_component(python_lib_dir "${python_lib_dir}/Lib" ABSOLUTE)
6+
foreach(dir collections encodings importlib json urllib re)
7+
file(COPY ${python_lib_dir}/${dir}
8+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python-lib
9+
FILES_MATCHING PATTERN "*.py"
10+
)
11+
endforeach()
12+
file(GLOB python_lib_files "${python_lib_dir}/*.py")
13+
foreach(not_needed
14+
aifc.py imghdr.py socket.py
15+
antigravity.py imp.py socketserver.py
16+
argparse.py ipaddress.py ssl.py
17+
asynchat.py locale.py statistics.py
18+
asyncore.py lzma.py string.py
19+
bdb.py mailbox.py stringprep.py
20+
binhex.py mailcap.py sunau.py
21+
bisect.py mimetypes.py symbol.py
22+
bz2.py modulefinder.py symtable.py
23+
calendar.py netrc.py tabnanny.py
24+
cgi.py nntplib.py tarfile.py
25+
cgitb.py nturl2path.py telnetlib.py
26+
chunk.py numbers.py tempfile.py
27+
cmd.py optparse.py
28+
pathlib.py this.py
29+
pdb.py timeit.py
30+
colorsys.py pickle.py trace.py
31+
compileall.py pickletools.py tracemalloc.py
32+
configparser.py pipes.py tty.py
33+
contextvars.py plistlib.py turtle.py
34+
cProfile.py poplib.py typing.py
35+
crypt.py pprint.py uu.py
36+
csv.py profile.py
37+
dataclasses.py pstats.py wave.py
38+
pty.py webbrowser.py
39+
decimal.py pyclbr.py xdrlib.py
40+
difflib.py py_compile.py zipapp.py
41+
doctest.py queue.py zipfile.py
42+
dummy_threading.py quopri.py zipimport.py
43+
filecmp.py random.py _compat_pickle.py
44+
fileinput.py rlcompleter.py _compression.py
45+
formatter.py runpy.py _dummy_thread.py
46+
fractions.py sched.py _markupbase.py
47+
ftplib.py secrets.py _osx_support.py
48+
getopt.py selectors.py _pydecimal.py
49+
getpass.py shelve.py _pyio.py
50+
gettext.py shlex.py _py_abc.py
51+
gzip.py shutil.py _strptime.py
52+
hashlib.py smtpd.py _threading_local.py
53+
hmac.py smtplib.py
54+
imaplib.py sndhdr.py __phello__.foo.py
55+
)
56+
list(FIND python_lib_files "${python_lib_dir}/${not_needed}" found_not_needed)
57+
if (NOT found_not_needed STREQUAL "-1")
58+
list(REMOVE_AT python_lib_files ${found_not_needed})
59+
endif()
60+
endforeach()
61+
62+
file(COPY ${python_lib_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/python-lib")
63+
64+
set(ENV{PYTHONOPTIMIZE} "2")
65+
execute_process(
66+
COMMAND "${PythonExe}" -OO -m compileall "${CMAKE_CURRENT_BINARY_DIR}/python-lib" -b
67+
${QTC_COMMAND_ERROR_IS_FATAL}
68+
)
69+
70+
file(GLOB_RECURSE python_lib_files "${CMAKE_CURRENT_BINARY_DIR}/python-lib/*.py")
71+
file(REMOVE ${python_lib_files})
72+
73+
file(GLOB_RECURSE python_lib_files LIST_DIRECTORIES ON "${CMAKE_CURRENT_BINARY_DIR}/python-lib/*/__pycache__$")
74+
file(REMOVE_RECURSE ${python_lib_files})
75+
76+
execute_process(
77+
COMMAND ${CMAKE_COMMAND} -E tar cf "${PythonZipFilePath}" . --format=zip
78+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/python-lib/"
79+
${QTC_COMMAND_ERROR_IS_FATAL}
80+
)
81+
endfunction()

0 commit comments

Comments
 (0)