Commit 969afe34 authored by Alex Richardson's avatar Alex Richardson

Add a python script that starts kdevelop with the all required env vars

I have set up a system where all KF5 libraries are system libraries and
only KDevelop and Clang are built from source. I have two installations
of KDevelop built using two different clang versions and want to start
these without setting env vars globally.

It will only be installed when the user runs cmake with
-DINSTALL_KDEVELOP_LAUNCH_WRAPPER=ON as it is not normally required.

REVIEW: 129254
parent 17643d13
......@@ -60,6 +60,12 @@ ENDIF()
install(TARGETS kdevelop ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
install(FILES kdevelop! DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
configure_file(start-kdevelop.py.in ${CMAKE_CURRENT_BINARY_DIR}/start-kdevelop.py @ONLY)
option(INSTALL_KDEVELOP_LAUNCH_WRAPPER "Install a wrapper script that sets required environment variables. Only useful when installing into a separate prefix" OFF)
if(INSTALL_KDEVELOP_LAUNCH_WRAPPER)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/start-kdevelop.py DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
endif()
if (WIN32)
install(FILES windows/kdevelop-msvc.bat DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
......
#!/usr/bin/env python3
import os
import pprint
import subprocess
import sys
new_env = {}
def prepend_to_env_list(var: str, new_dirs: list, default_dirs: list=list()):
path_list = new_dirs + list(os.getenv(var, "").split(":")) + default_dirs
# print(var, "path_list:", pprint.pformat(path_list))
# remove duplicates as well as empty entries and preserve order
unique_path_list = []
for path in path_list:
if path and path not in unique_path_list:
unique_path_list.append(path)
# print(var, "unique_path_list:", pprint.pformat(unique_path_list))
new_env[var] = ":".join(unique_path_list)
plugin_dirs = ["@KDE_INSTALL_FULL_PLUGINDIR@"]
if "@QT_PLUGIN_INSTALL_DIR@" and os.path.exists("@QT_PLUGIN_INSTALL_DIR@"):
plugin_dirs.append("@QT_PLUGIN_INSTALL_DIR@")
qt_plugin_dir = subprocess.check_output(["qtpaths", "--plugin-dir"]).decode("utf-8").strip()
plugin_dirs.append(qt_plugin_dir)
prepend_to_env_list("QT_PLUGIN_PATH", plugin_dirs)
qml_import_dirs = ["@KDE_INSTALL_FULL_QMLDIR@"]
if "@QT_INSTALL_QML@" and os.path.exists("@QT_INSTALL_QML@"):
qml_import_dirs.append("@QT_INSTALL_QML@")
qml_import_dirs.append(os.path.abspath(os.path.join(qt_plugin_dir, os.pardir, "qml")))
prepend_to_env_list("QML2_IMPORT_PATH", qml_import_dirs)
config_dirs = subprocess.check_output(["qtpaths", "--paths", "GenericConfigLocation"]).decode("utf-8").strip().split(":")
prepend_to_env_list("XDG_CONFIG_DIRS", ["@KDE_INSTALL_FULL_CONFDIR@"], config_dirs)
data_dirs = subprocess.check_output(["qtpaths", "--paths", "GenericDataLocation"]).decode("utf-8").strip().split(":")
prepend_to_env_list("XDG_DATA_DIRS", ["@KDE_INSTALL_FULL_DATADIR@"], data_dirs)
# add the directory where we installed kdevelop to $PATH in case e.g. CMake, etc. are also there
prepend_to_env_list("PATH", ["@KDE_INSTALL_FULL_BINDIR@"])
new_env["QT_MESSAGE_PATTERN"] = "\033[32m%{time h:mm:ss.zzz}%{if-category}\033[32m %{category}:%{endif} %{if-debug}\033[34m%{function}%{endif}%{if-warning}\033[31m%{backtrace depth=5}\n%{endif}%{if-critical}\033[31m%{backtrace depth=5}\n%{endif}%{if-fatal}\033[31m%{backtrace depth=5}\n%{endif}\033[0m %{message}"
os.environ.update(new_env)
# print("updating env:", pprint.pformat(new_env))
kdevelop_binary = "@KDE_INSTALL_FULL_BINDIR@/kdevelop"
os.execvpe(kdevelop_binary, [kdevelop_binary] + sys.argv[1:], os.environ)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment