aboutsummaryrefslogtreecommitdiffstats
path: root/packaging-tools/install_qt.py
blob: 3e9ba6e4516069f8475f4ca4d5301ce165fa74f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#############################################################################
#
# Copyright (C) 2023 The Qt Company Ltd.
# Contact: https://www.qt.io/licensing/
#
# This file is part of the release tools of the Qt Toolkit.
#
# $QT_BEGIN_LICENSE:GPL-EXCEPT$
# Commercial License Usage
# Licensees holding valid commercial Qt licenses may use this file in
# accordance with the commercial license agreement provided with the
# Software or, alternatively, in accordance with the terms contained in
# a written agreement between you and The Qt Company. For licensing terms
# and conditions see https://www.qt.io/terms-conditions. For further
# information use the contact form at https://www.qt.io/contact-us.
#
# GNU General Public License Usage
# Alternatively, this file may be used under the terms of the GNU
# General Public License version 3 as published by the Free Software
# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
# included in the packaging of this file. Please review the following
# information to ensure the GNU General Public License requirements will
# be met: https://www.gnu.org/licenses/gpl-3.0.html.
#
# $QT_END_LICENSE$
#
#############################################################################

import argparse
import os
import sys
from typing import List, Optional

from temppathlib import TemporaryDirectory

from bldinstallercommon import create_qt_download_task, patch_qt
from logging_util import init_logger
from threadedwork import ThreadedWork

log = init_logger(__name__, debug_mode=False)


def get_arguments() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description='Build Qt Creator')
    parser.add_argument('--qt-path', help='path to Qt', required=True)
    parser.add_argument('--qt-module', help='Qt module package url (.7z) needed for building',
                        action='append', dest='qt_modules', default=[])

    parser.add_argument('--base-url', help='Base URL for given module_name(s)')
    parser.add_argument('module_name', help='Name of Qt module to install, based on --base-url and --base-url-postfix',
                        nargs='*')
    parser.add_argument('--base-url-postfix',
                        help='Postfix to add to URLs constructed from --base-url and given module_name(s)',
                        default='')

    # Linux
    parser.add_argument('--icu7z', help='a file or url where to get ICU libs as 7z')

    # Windows
    parser.add_argument('--d3dcompiler7z', help='a file or url where it get d3dcompiler lib')
    parser.add_argument('--opengl32sw7z', help='a file or url where it get opengl32sw lib')
    parser.add_argument('--openssl7z', help='a file or url where to get the openssl libs as 7z')

    args = parser.parse_args(sys.argv[1:])

    return args


def install_qt(
    qt_path: str,
    qt_modules: List[str],
    icu_url: Optional[str] = None,
    d3d_url: Optional[str] = None,
    opengl_url: Optional[str] = None,
    openssl_url: Optional[str] = None,
    temp_path: Optional[str] = None
) -> None:
    """
    Install Qt to directory qt_path with the specified module and library packages.

    Args:
        qt_path: File system path to Qt (target install directory)
        qt_modules: List of Qt module package URLs (.7z)
        icu_url: Local or remote URI to Linux ICU libraries (.7z)
        d3d_url: Local or remote URI to Windows d3dcompiler libraries (.7z)
        opengl_url: Local or remote URI to Windows OpenGL libraries (.7z)
        openssl_url: Local or remote URI to Windows OpenSSL libraries (.7z)
        temp_path: Temporary path used for saving downloaded archives

    Raises:
        SystemExit: When qt_modules list is empty

    """
    if not qt_modules:
        raise SystemExit("No modules specified in qt_modules")
    qt_path = os.path.abspath(qt_path)
    dl_pkgs_work = ThreadedWork("get and extract Qt binaries")
    need_to_install_qt = not os.path.lexists(qt_path)
    if need_to_install_qt:
        opts = argparse.Namespace(
            icu7z=icu_url,
            d3dcompiler7z=d3d_url,
            opengl32sw7z=opengl_url,
            openssl7z=openssl_url,
        )
        if temp_path:
            dl_pkgs_work.add_task_object(
                create_qt_download_task(qt_modules, qt_path, temp_path, opts)
            )
        else:
            with TemporaryDirectory() as temporary_dir:
                dl_pkgs_work.add_task_object(
                    create_qt_download_task(qt_modules, qt_path, str(temporary_dir.path), opts)
                )

    # run task if needed
    if dl_pkgs_work.task_number != 0:
        dl_pkgs_work.run()
        patch_qt(qt_path)


def main() -> None:
    """Main"""
    args: argparse.Namespace = get_arguments()
    # Check that qt_module(s) or base-url/module_name(s) combo is specified
    if not args.qt_modules and not (args.base_url and args.module_name):
        raise SystemExit("'qt-module(s)' and/or 'base-url' with 'module_name(s)' required")
    # Create the list of modules from qt_modules + module_names with base_url and postfix
    qt_modules: List[str] = args.qt_modules
    if args.base_url and args.module_name:
        for module in args.module_name:
            qt_modules += [args.base_url + "/" + module + "/" + module + args.base_url_postfix]

    install_qt(
        qt_path=args.qt_path,
        qt_modules=qt_modules,
        icu_url=args.icu7z,
        d3d_url=args.d3dcompiler7z,
        opengl_url=args.opengl32sw7z,
        openssl_url=args.openssl7z,
    )


if __name__ == '__main__':
    main()