diff options
Diffstat (limited to 'scripts/deployqt.py')
-rwxr-xr-x | scripts/deployqt.py | 134 |
1 files changed, 86 insertions, 48 deletions
diff --git a/scripts/deployqt.py b/scripts/deployqt.py index 5e4808a211..5d7011e068 100755 --- a/scripts/deployqt.py +++ b/scripts/deployqt.py @@ -27,10 +27,10 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################ +import argparse import os import locale import sys -import getopt import subprocess import re import shutil @@ -38,10 +38,38 @@ from glob import glob import common -ignoreErrors = False debug_build = False encoding = locale.getdefaultlocale()[1] +def get_args(): + parser = argparse.ArgumentParser(description='Deploy Qt Creator dependencies for packaging') + parser.add_argument('-i', '--ignore-errors', help='For backward compatibility', + action='store_true', default=False) + parser.add_argument('--elfutils-path', + help='Path to elfutils installation for use by perfprofiler (Windows, Linux)') + # TODO remove defaulting to LLVM_INSTALL_DIR when we no longer build qmake based packages + parser.add_argument('--llvm-path', + help='Path to LLVM installation', + default=os.environ.get('LLVM_INSTALL_DIR')) + parser.add_argument('qtcreator_binary', help='Path to Qt Creator binary') + parser.add_argument('qmake_binary', help='Path to qmake binary') + + args = parser.parse_args() + + args.qtcreator_binary = os.path.abspath(args.qtcreator_binary) + if common.is_windows_platform() and not args.qtcreator_binary.lower().endswith(".exe"): + args.qtcreator_binary = args.qtcreator_binary + ".exe" + if not os.path.isfile(args.qtcreator_binary): + print('Cannot find Qt Creator binary.') + sys.exit(1) + + args.qmake_binary = which(args.qmake_binary) + if not args.qmake_binary: + print('Cannot find qmake binary.') + sys.exit(2) + + return args + def usage(): print("Usage: %s <existing_qtcreator_binary> [qmake_path]" % os.path.basename(sys.argv[0])) @@ -74,17 +102,12 @@ def is_debug(fpath): # bootstrap exception if coredebug.search(fpath): return True - output = subprocess.check_output(['dumpbin', '/imports', fpath]) - return coredebug.search(output.decode(encoding)) != None - -def op_failed(details = None): - if details != None: - print(details) - if ignoreErrors == False: - print("Error: operation failed!") - sys.exit(2) - else: - print("Error: operation failed, but proceeding gracefully.") + try: + output = subprocess.check_output(['dumpbin', '/imports', fpath]) + return coredebug.search(output.decode(encoding)) != None + except FileNotFoundError: + # dumpbin is not there, maybe MinGW ? Just ship all .dlls. + return debug_build def is_ignored_windows_file(use_debug, basepath, filename): ignore_patterns = ['.lib', '.pdb', '.exp', '.ilk'] @@ -132,7 +155,7 @@ def copy_qt_libs(target_qt_prefix_path, qt_bin_dir, qt_libs_dir, qt_plugin_dir, try: os.symlink(linkto, os.path.join(lib_dest, os.path.basename(library))) except OSError: - op_failed("Link already exists!") + pass else: shutil.copy(library, lib_dest) @@ -270,43 +293,56 @@ def deploy_libclang(install_dir, llvm_install_dir, chrpath_bin): shutil.rmtree(resourcetarget) common.copytree(resourcesource, resourcetarget, symlinks=True) +def deploy_elfutils(qtc_install_dir, chrpath_bin, args): + if common.is_mac_platform(): + return + + def lib_name(name, version): + return ('lib' + name + '.so.' + version if common.is_linux_platform() + else name + '.dll') + + version = '1' + libs = ['elf', 'dw'] + elfutils_lib_path = os.path.join(args.elfutils_path, 'lib') + if common.is_linux_platform(): + install_path = os.path.join(qtc_install_dir, 'lib', 'elfutils') + backends_install_path = install_path + elif common.is_windows_platform(): + install_path = os.path.join(qtc_install_dir, 'bin') + backends_install_path = os.path.join(qtc_install_dir, 'lib', 'elfutils') + libs.append('eu_compat') + if not os.path.exists(install_path): + os.makedirs(install_path) + if not os.path.exists(backends_install_path): + os.makedirs(backends_install_path) + # copy main libs + libs = [os.path.join(elfutils_lib_path, lib_name(lib, version)) for lib in libs] + for lib in libs: + print(lib, '->', install_path) + shutil.copy(lib, install_path) + # fix rpath + if common.is_linux_platform(): + relative_path = os.path.relpath(backends_install_path, install_path) + subprocess.check_call([chrpath_bin, '-r', os.path.join('$ORIGIN', relative_path), + os.path.join(install_path, lib_name('dw', version))]) + # copy backend files + # only non-versioned, we never dlopen the versioned ones + files = glob(os.path.join(elfutils_lib_path, 'elfutils', '*ebl_*.*')) + versioned_files = glob(os.path.join(elfutils_lib_path, 'elfutils', '*ebl_*.*-*.*.*')) + unversioned_files = [file for file in files if file not in versioned_files] + for file in unversioned_files: + print(file, '->', backends_install_path) + shutil.copy(file, backends_install_path) + def main(): - try: - opts, args = getopt.gnu_getopt(sys.argv[1:], 'hi', ['help', 'ignore-errors']) - except getopt.GetoptError: - usage() - sys.exit(2) - for o, _ in opts: - if o in ('-h', '--help'): - usage() - sys.exit(0) - if o in ('-i', '--ignore-errors'): - global ignoreErrors - ignoreErrors = True - print("Note: Ignoring all errors") - - qtcreator_binary = os.path.abspath(args[0]) - if common.is_windows_platform() and not qtcreator_binary.lower().endswith(".exe"): - qtcreator_binary = qtcreator_binary + ".exe" - - if len(args) < 1 or not os.path.isfile(qtcreator_binary): - usage() - sys.exit(2) + args = get_args() - qtcreator_binary_path = os.path.dirname(qtcreator_binary) + qtcreator_binary_path = os.path.dirname(args.qtcreator_binary) install_dir = os.path.abspath(os.path.join(qtcreator_binary_path, '..')) if common.is_linux_platform(): qt_deploy_prefix = os.path.join(install_dir, 'lib', 'Qt') else: qt_deploy_prefix = os.path.join(install_dir, 'bin') - qmake_bin = 'qmake' - if len(args) > 1: - qmake_bin = args[1] - qmake_bin = which(qmake_bin) - - if qmake_bin == None: - print("Cannot find required binary 'qmake'.") - sys.exit(2) chrpath_bin = None if common.is_linux_platform(): @@ -315,7 +351,7 @@ def main(): print("Cannot find required binary 'chrpath'.") sys.exit(2) - qt_install_info = common.get_qt_install_info(qmake_bin) + qt_install_info = common.get_qt_install_info(args.qmake_binary) QT_INSTALL_LIBS = qt_install_info['QT_INSTALL_LIBS'] QT_INSTALL_BINS = qt_install_info['QT_INSTALL_BINS'] QT_INSTALL_PLUGINS = qt_install_info['QT_INSTALL_PLUGINS'] @@ -334,16 +370,18 @@ def main(): if common.is_windows_platform(): global debug_build - debug_build = is_debug(qtcreator_binary) + debug_build = is_debug(args.qtcreator_binary) if common.is_windows_platform(): copy_qt_libs(qt_deploy_prefix, QT_INSTALL_BINS, QT_INSTALL_BINS, QT_INSTALL_PLUGINS, QT_INSTALL_IMPORTS, QT_INSTALL_QML, plugins, imports) else: copy_qt_libs(qt_deploy_prefix, QT_INSTALL_BINS, QT_INSTALL_LIBS, QT_INSTALL_PLUGINS, QT_INSTALL_IMPORTS, QT_INSTALL_QML, plugins, imports) copy_translations(install_dir, QT_INSTALL_TRANSLATIONS) - if "LLVM_INSTALL_DIR" in os.environ: - deploy_libclang(install_dir, os.environ["LLVM_INSTALL_DIR"], chrpath_bin) + if args.llvm_path: + deploy_libclang(install_dir, args.llvm_path, chrpath_bin) + if args.elfutils_path: + deploy_elfutils(install_dir, chrpath_bin, args) if not common.is_windows_platform(): print("fixing rpaths...") common.fix_rpaths(install_dir, os.path.join(qt_deploy_prefix, 'lib'), qt_install_info, chrpath_bin) |