Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / packaging / nsis / windeployqt-to-nsis.py
blob2063282aa4350de1067a1efc15f19069c608aee7
1 #!/bin/env python3
3 # windeployqt-to-nsh
5 # Windeployqt-to-nsh - Convert the output of windeployqt to an equivalent set of
6 # NSIS "File" function calls.
8 # Rewritten in python from windeployqt-to-nsis.ps1, that has the following copyright:
10 # Copyright 2014 Gerald Combs <gerald@wireshark.org>
12 # Wireshark - Network traffic analyzer
13 # By Gerald Combs <gerald@wireshark.org>
14 # Copyright 1998 Gerald Combs
16 # SPDX-License-Identifier: GPL-2.0-or-later
18 import sys
19 import os
20 import argparse
21 import subprocess
23 parser = argparse.ArgumentParser()
24 group = parser.add_mutually_exclusive_group(required=True)
25 group.add_argument('--mapping')
26 group.add_argument('--executable')
27 parser.add_argument('--sysroot')
28 parser.add_argument('outfile')
29 args = parser.parse_args()
31 if args.mapping:
32 if not args.sysroot:
33 sys.exit('Option --sysroot is required with option --mapping')
34 qt_version = None
35 with open(args.mapping, 'r', encoding='utf-8') as f:
36 out = f.read()
37 else:
38 # Qt version
39 qmake_command = [
40 'qmake6.exe',
41 '-query', 'QT_VERSION'
43 qmake_out = subprocess.run(qmake_command, check=True, capture_output=True, encoding="utf-8")
44 qt_version = qmake_out.stdout.strip()
46 # XXX The powershell script asserts that the Qt version is greater than 5.3. We already require Qt6 to build the
47 # installer using MSYS2 (currently not enforced).
49 # Windeployqt output
50 windeploy_command = [
51 "windeployqt6.exe",
52 "--no-compiler-runtime",
53 "--no-translations",
54 "--list", "mapping",
55 args.executable
57 out = subprocess.run(windeploy_command, check=True, capture_output=True, encoding="utf-8").stdout
59 with open(args.outfile, 'w') as f:
60 header = """\
62 # Automatically generated by {}
63 #""".format(parser.prog)
65 if qt_version:
66 header += """\
67 # Qt version {}
68 #""".format(qt_version)
70 print(header, file=f)
72 current_dir = ""
73 for line in out.splitlines():
74 line = line.strip()
75 if not line or line.startswith('#'):
76 continue
77 if line.startswith('Adding in plugin'):
78 # https://bugreports.qt.io/browse/QTBUG-122257
79 # Affects 6.6.0 - 6.6.2
80 continue
81 path, relative = line.split(" ")
82 rel_path = os.path.split(relative)
83 if len(rel_path) > 1:
84 base_dir = rel_path[0].strip('"')
85 if base_dir != current_dir:
86 set_out_path = r'SetOutPath "$INSTDIR\{}"'.format(base_dir)
87 print(set_out_path, file=f)
88 current_dir = base_dir
90 path = path.strip('"')
91 if args.sysroot:
92 path = os.path.join(args.sysroot, path)
93 if args.mapping and not os.path.isfile(path):
94 # This hack is because Qt 6.7 renamed QWindowsVistaStylePlugin
95 # to QModernWindowsStylePlugin. (This explicit mapping because
96 # windeployqt6 doesn't work well with cross-compiling is
97 # brittle.)
98 continue
99 file_path = 'File "{}"'.format(path)
100 print(file_path, file=f)