aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2020-10-09 14:17:59 +0200
committerCristian Adam <cristian.adam@qt.io>2020-10-19 09:45:04 +0000
commitd7e24f28ba18be268ea93f41e3215bfb56c9950f (patch)
tree6faf34e2ab5aafa462f77b4df4053a7e21c69568
parent3ff8c42431f6f060aa729cdedbd20f0ec2495906 (diff)
CMake Build: Fix missing pythonXY.zip on MSVC
Ammends 94b9b33a17e3f7760cbbf9abd021984839106647 Change-Id: I531a648a108233fbefbe6878f65f8ab7186db39a Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--cmake/CreatePythonXY.cmake79
-rw-r--r--src/libs/qtcreatorcdbext/CMakeLists.txt27
2 files changed, 100 insertions, 6 deletions
diff --git a/cmake/CreatePythonXY.cmake b/cmake/CreatePythonXY.cmake
new file mode 100644
index 0000000000..8aeeb156cb
--- /dev/null
+++ b/cmake/CreatePythonXY.cmake
@@ -0,0 +1,79 @@
+# create_python_xy function will precompile the Python/lib/*.py files
+# and create a zip file containing all the pyc files
+function(create_python_xy PythonExe PythonZipFilePath)
+ get_filename_component(python_lib_dir "${PythonExe}" DIRECTORY)
+ get_filename_component(python_lib_dir "${python_lib_dir}/Lib" ABSOLUTE)
+ foreach(dir collections encodings importlib json urllib)
+ file(COPY ${python_lib_dir}/${dir}
+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python-lib
+ FILES_MATCHING PATTERN "*.py"
+ )
+ endforeach()
+ file(GLOB python_lib_files "${python_lib_dir}/*.py")
+ foreach(not_needed
+ aifc.py imghdr.py socket.py
+ antigravity.py imp.py socketserver.py
+ argparse.py ipaddress.py ssl.py
+ asynchat.py locale.py statistics.py
+ asyncore.py lzma.py string.py
+ bdb.py mailbox.py stringprep.py
+ binhex.py mailcap.py sunau.py
+ bisect.py mimetypes.py symbol.py
+ bz2.py modulefinder.py symtable.py
+ calendar.py netrc.py tabnanny.py
+ cgi.py nntplib.py tarfile.py
+ cgitb.py nturl2path.py telnetlib.py
+ chunk.py numbers.py tempfile.py
+ cmd.py optparse.py textwrap.py
+ code.py pathlib.py this.py
+ codeop.py pdb.py timeit.py
+ colorsys.py pickle.py trace.py
+ compileall.py pickletools.py tracemalloc.py
+ configparser.py pipes.py tty.py
+ contextvars.py plistlib.py turtle.py
+ cProfile.py poplib.py typing.py
+ crypt.py pprint.py uu.py
+ csv.py profile.py uuid.py
+ dataclasses.py pstats.py wave.py
+ datetime.py pty.py webbrowser.py
+ decimal.py pyclbr.py xdrlib.py
+ difflib.py py_compile.py zipapp.py
+ doctest.py queue.py zipfile.py
+ dummy_threading.py quopri.py zipimport.py
+ filecmp.py random.py _compat_pickle.py
+ fileinput.py rlcompleter.py _compression.py
+ formatter.py runpy.py _dummy_thread.py
+ fractions.py sched.py _markupbase.py
+ ftplib.py secrets.py _osx_support.py
+ getopt.py selectors.py _pydecimal.py
+ getpass.py shelve.py _pyio.py
+ gettext.py shlex.py _py_abc.py
+ gzip.py shutil.py _strptime.py
+ hashlib.py smtpd.py _threading_local.py
+ hmac.py smtplib.py __future__.py
+ imaplib.py sndhdr.py __phello__.foo.py
+ )
+ list(FIND python_lib_files "${python_lib_dir}/${not_needed}" found_not_needed)
+ if (NOT found_not_needed STREQUAL "-1")
+ list(REMOVE_AT python_lib_files ${found_not_needed})
+ endif()
+ endforeach()
+
+ file(COPY ${python_lib_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/python-lib")
+
+ set(ENV{PYTHONOPTIMIZE} "2")
+ execute_process(
+ COMMAND "${PythonExe}" -OO -m compileall "${CMAKE_CURRENT_BINARY_DIR}/python-lib" -b
+ )
+
+ file(GLOB_RECURSE python_lib_files "${CMAKE_CURRENT_BINARY_DIR}/python-lib/*.py")
+ file(REMOVE ${python_lib_files})
+
+ file(GLOB_RECURSE python_lib_files LIST_DIRECTORIES ON "${CMAKE_CURRENT_BINARY_DIR}/python-lib/*/__pycache__$")
+ file(REMOVE_RECURSE ${python_lib_files})
+
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E tar cf "${PythonZipFilePath}" . --format=zip
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/python-lib/"
+ )
+endfunction()
diff --git a/src/libs/qtcreatorcdbext/CMakeLists.txt b/src/libs/qtcreatorcdbext/CMakeLists.txt
index 0a45ef0cc3..f024eaa482 100644
--- a/src/libs/qtcreatorcdbext/CMakeLists.txt
+++ b/src/libs/qtcreatorcdbext/CMakeLists.txt
@@ -59,8 +59,12 @@ if (_library_enabled)
foreach(lib IN LISTS PYTHON_LIBRARIES)
if (lib MATCHES ${PythonRegex})
+ set(PythonZipFileName "python${CMAKE_MATCH_4}.zip")
+
set(PythonDll "${CMAKE_MATCH_1}/${CMAKE_MATCH_3}${CMAKE_SHARED_LIBRARY_SUFFIX}")
- set(PythonZip "${CMAKE_MATCH_1}/python${CMAKE_MATCH_4}.zip")
+ set(PythonExe "${CMAKE_MATCH_1}/python${CMAKE_EXECUTABLE_SUFFIX}")
+ set(PythonZip "${CMAKE_MATCH_1}/${PythonZipFileName}")
+
break()
endif()
endforeach()
@@ -85,16 +89,27 @@ if (_library_enabled)
pyvalue.cpp pyvalue.h
)
- install(FILES
- "${PythonDll}"
- "${PythonZip}"
+ if (NOT EXISTS "${PythonZip}" AND
+ NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
+ include(CreatePythonXY)
+ create_python_xy("${PythonExe}" "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
+ endif()
+
+ if (NOT EXISTS "${PythonZip}" AND
+ EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
+ set(PythonZip "${CMAKE_CURRENT_BINARY_DIR}/${PythonZipFileName}")
+ endif()
+
+ list(APPEND deployPythonFiles "${PythonDll}")
+ list(APPEND deployPythonFiles "${PythonZip}")
+
+ install(FILES ${deployPythonFiles}
DESTINATION lib/qtcreatorcdbext${ArchSuffix}/
COMPONENT qtcreatorcdbext)
add_custom_target(copy_python_dll ALL VERBATIM)
add_custom_command(TARGET copy_python_dll POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E copy "${PythonDll}" "${PROJECT_BINARY_DIR}/lib/qtcreatorcdbext${ArchSuffix}/"
- COMMAND "${CMAKE_COMMAND}" -E copy "${PythonZip}" "${PROJECT_BINARY_DIR}/lib/qtcreatorcdbext${ArchSuffix}/"
+ COMMAND "${CMAKE_COMMAND}" -E copy ${deployPythonFiles} "${PROJECT_BINARY_DIR}/lib/qtcreatorcdbext${ArchSuffix}/"
VERBATIM
)
endif()