aboutsummaryrefslogtreecommitdiffstats
path: root/packaging-tools/bld_sdktool.py
blob: 47fb80db3f1b0d8e5bab4c9886d408183ef26900 (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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#############################################################################
##
## Copyright (C) 2022 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 os
from pathlib import Path

import bldinstallercommon
from bld_utils import is_windows, is_linux
import collections
from runner import do_execute_sub_process

BuildParams = collections.namedtuple('BuildParams',
                                     ['src_path', 'build_path', 'target_path',
                                      'make_command', 'redirect_output'])

def qt_static_configure_options():
    return ['-release', '-opensource', '-confirm-license', '-accessibility',
            '-no-gui',
            '-no-openssl',
            '-no-feature-sql',
            '-qt-zlib',
            '-nomake', 'examples',
            '-nomake', 'tests',
            '-static'] + qt_static_platform_configure_options()

def qt_static_platform_configure_options():
    if is_windows():
        return ['-static-runtime', '-no-icu', '-mp']
    elif is_linux():
        return ['-no-icu', '-no-glib', '-qt-zlib', '-qt-pcre', '-qt-doubleconversion']
    return []

def qt_src_path(qt_build_base):
    return os.path.join(qt_build_base, 'src')

def qt_build_path(qt_build_base):
    return os.path.join(qt_build_base, 'build')

def package_extension(url):
    if url.endswith('.tar.gz'):
        return '.tar.gz'
    elif url.endswith('.zip'):
        return '.zip'
    elif url.endswith('.tar.xz'):
        return '.tar.xz'
    else:
        (_, ext) = os.path.splitext(url)
        return ext

def get_and_extract_qt_src(url, temp, path):
    Path(temp).mkdir(parents=True, exist_ok=True)
    ext = package_extension(url)
    file_path = os.path.join(temp, 'qtsrc' + ext)
    bldinstallercommon.retrieve_url(url, file_path)
    Path(path).mkdir(parents=True, exist_ok=True)
    bldinstallercommon.extract_file(file_path, path)
    bldinstallercommon.remove_one_tree_level(path)

def configure_qt(params, src, build):
    Path(build).mkdir(parents=True, exist_ok=True)
    configure = os.path.join(src, 'configure')
    do_execute_sub_process([configure, '-prefix', build] + qt_static_configure_options(),
                                              build, redirect_output=params.redirect_output)

def build_qt(params, build):
    do_execute_sub_process([params.make_command], build, redirect_output=params.redirect_output)

def build_sdktool_impl(params, qt_build_path):
    Path(params.build_path).mkdir(parents=True, exist_ok=True)
    cmake_args = ['cmake',
                  '-DCMAKE_PREFIX_PATH=' + qt_build_path,
                  '-DCMAKE_BUILD_TYPE=Release']
    # force MSVC on Windows, because it looks for GCC in the PATH first,
    # even if MSVC is first mentioned in the PATH...
    # TODO would be nicer if we only did this if cl.exe is indeed first in the PATH
    if is_windows():
        cmake_args += ['-DCMAKE_C_COMPILER=cl', '-DCMAKE_CXX_COMPILER=cl']

    do_execute_sub_process(cmake_args +
                                              ['-G', 'Ninja', params.src_path],
                                              params.build_path,
                                              redirect_output=params.redirect_output)
    do_execute_sub_process(['cmake', '--build', '.'], params.build_path,
                                              redirect_output=params.redirect_output)
    do_execute_sub_process(['cmake',
                                               '--install', '.',
                                               '--prefix', params.target_path],
                                              params.build_path,
                                              redirect_output=params.redirect_output)

def build_sdktool(qt_src_url, qt_build_base, sdktool_src_path, sdktool_build_path, sdktool_target_path,
                  make_command, redirect_output=None):
    params = BuildParams(src_path=sdktool_src_path,
                         build_path=sdktool_build_path,
                         target_path=sdktool_target_path,
                         make_command=make_command,
                         redirect_output=redirect_output)
    qt_src = qt_src_path(qt_build_base)
    qt_build = qt_build_path(qt_build_base)
    get_and_extract_qt_src(qt_src_url, qt_build_base, qt_src)
    configure_qt(params, qt_src, qt_build)
    build_qt(params, qt_build)
    build_sdktool_impl(params, qt_build)

def zip_sdktool(sdktool_target_path, out_7zip, redirect_output=None):
    glob = "*.exe" if is_windows() else "*"
    do_execute_sub_process(['7z', 'a', out_7zip, glob],
                                              sdktool_target_path, redirect_output=redirect_output)