summaryrefslogtreecommitdiffstats
path: root/release-tools/bld_ifw_tools_impl.py
blob: 692ce675afb4d031e7d348a54bf18cc04421c977 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/usr/bin/env python
###############################################
#
# Copyright (C) 2012 Digia Plc
# For any questions to Digia, please use contact form at http://qt.digia.com
#
# $QT_BEGIN_LICENSE:LGPL$
# GNU Lesser General Public License Usage
# This file may be used under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation and
# appearing in the file LICENSE.LGPL included in the packaging of this
# file. Please review the following information to ensure the GNU Lesser
# General Public License version 2.1 requirements will be met:
# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
#
# GNU General Public License Usage
# Alternatively, this file may be used under the terms of the GNU General
# Public License version 3.0 as published by the Free Software Foundation
# and appearing in the file LICENSE.GPL included in the packaging of this
# file. Please review the following information to ensure the GNU General
# Public License version 3.0 requirements will be met:
# http://www.gnu.org/copyleft/gpl.html.
#
# $QT_END_LICENSE$
#
# If you have questions regarding the use of this file, please use
# contact form at http://qt.digia.com
#
###############################################

import sys
import os
import sys
import urllib
import shutil
import ConfigParser
import bldinstallercommon

DEVELOPMENT_MODE                    = False
CONFIG_IFW                          = ''
SCRIPT_ROOT_DIR                     = os.getcwd()
PLATFORM_IDENTIFIER                 = ''
MAKE_CMD                            = ''
QT_QMAKE_BIN                        = ''
QT_CONFIGURE_BIN                    = ''
QT_SRC_PACKAGE_URL                  = ''
QT_SRC_PACKAGE_URL_SAVE_AS          = ''
QT_SOURCE_DIR                       = ''
QT_BUILD_DIR                        = ''
QT_INSTALLERFW_QT_CONFIGURE_LINE    = ''
INSTALLER_FRAMEWORK_URL             = ''
INSTALLER_FRAMEWORK_SOURCE_DIR      = ''
INSTALLER_FRAMEWORK_BUILD_DIR       = ''
INSTALLER_FRAMEWORK_VERSION_TAG     = ''
INSTALLER_FRAMEWORK_QMAKE_ARGS      = ''
INSTALLER_FRAMEWORK_ARCHIVE_NAME    = ''
INSTALLERBASE_ARCHIVE_NAME          = ''


###############################
# function
###############################
def init_config():
    global CONFIG_IFW
    global MAKE_CMD
    global QT_QMAKE_BIN
    global QT_CONFIGURE_BIN
    global QT_SRC_PACKAGE_URL
    global QT_SRC_PACKAGE_URL_SAVE_AS
    global QT_SOURCE_DIR
    global QT_BUILD_DIR
    global QT_INSTALLERFW_QT_CONFIGURE_LINE
    global INSTALLER_FRAMEWORK_URL
    global INSTALLER_FRAMEWORK_SOURCE_DIR
    global INSTALLER_FRAMEWORK_BUILD_DIR
    global INSTALLER_FRAMEWORK_VERSION_TAG
    global INSTALLER_FRAMEWORK_QMAKE_ARGS
    global INSTALLER_FRAMEWORK_ARCHIVE_NAME
    global INSTALLERBASE_ARCHIVE_NAME

    conf_path = SCRIPT_ROOT_DIR + os.sep + 'configurations' + os.sep + PLATFORM_IDENTIFIER + os.sep + 'installer-framework'
    CONFIG_IFW = ConfigParser.ConfigParser()
    CONFIG_IFW.readfp(open(conf_path))

    print '----------------------------------------'
    print 'Installer-Framework build configuration:'
    print ''
    print 'Configuration file: ' + conf_path
    print ''

    MAKE_CMD                            = bldinstallercommon.config_section_map(CONFIG_IFW,'make')['make_cmd']
    QT_SRC_PACKAGE_URL                  = bldinstallercommon.config_section_map(CONFIG_IFW,'QtForInstallerFramework')['qt_src_package_url']
    QT_SRC_PACKAGE_URL_SAVE_AS          = SCRIPT_ROOT_DIR + os.sep + os.path.basename(QT_SRC_PACKAGE_URL)
    QT_SOURCE_DIR                       = SCRIPT_ROOT_DIR + os.sep + bldinstallercommon.config_section_map(CONFIG_IFW,'QtForInstallerFramework')['qt_source_dir']
    QT_BUILD_DIR                        = SCRIPT_ROOT_DIR + os.sep + bldinstallercommon.config_section_map(CONFIG_IFW,'QtForInstallerFramework')['qt_build_dir']
    QT_INSTALLERFW_QT_CONFIGURE_LINE    = bldinstallercommon.config_section_map(CONFIG_IFW,'QtForInstallerFramework')['qt_installerfw_qt_configure_line']

    QT_QMAKE_BIN                            = 'qmake'
    if bldinstallercommon.is_win_platform():
        QT_QMAKE_BIN += '.exe'
    QT_CONFIGURE_BIN                        = QT_SOURCE_DIR + os.sep + 'configure'
    if bldinstallercommon.is_win_platform():
        QT_CONFIGURE_BIN += '.exe'

    INSTALLER_FRAMEWORK_URL             = bldinstallercommon.config_section_map(CONFIG_IFW,'InstallerFramework')['installer_framework_url']
    INSTALLER_FRAMEWORK_SOURCE_DIR      = SCRIPT_ROOT_DIR + os.sep + bldinstallercommon.config_section_map(CONFIG_IFW,'InstallerFramework')['installer_framework_source_dir']
    INSTALLER_FRAMEWORK_BUILD_DIR       = SCRIPT_ROOT_DIR + os.sep + bldinstallercommon.config_section_map(CONFIG_IFW,'InstallerFramework')['installer_framework_build_dir']
    INSTALLER_FRAMEWORK_VERSION_TAG     = bldinstallercommon.config_section_map(CONFIG_IFW,'InstallerFramework')['installer_framework_version_tag']
    INSTALLER_FRAMEWORK_QMAKE_ARGS      = bldinstallercommon.config_section_map(CONFIG_IFW,'InstallerFramework')['installer_framework_qmake_args']
    QT_SOURCE_DIR                       = os.path.normpath(QT_SOURCE_DIR)
    QT_BUILD_DIR                        = os.path.normpath(QT_BUILD_DIR)
    INSTALLER_FRAMEWORK_SOURCE_DIR      = os.path.normpath(INSTALLER_FRAMEWORK_SOURCE_DIR)
    INSTALLER_FRAMEWORK_BUILD_DIR       = os.path.normpath(INSTALLER_FRAMEWORK_BUILD_DIR)
    INSTALLER_FRAMEWORK_ARCHIVE_NAME    = bldinstallercommon.config_section_map(CONFIG_IFW,'Output')['installer_framework_archive_name']
    INSTALLERBASE_ARCHIVE_NAME          = bldinstallercommon.config_section_map(CONFIG_IFW,'Output')['installerbase_archive_name']

    print 'make:                                ' + MAKE_CMD
    print ''
    print 'QT_SRC_PACKAGE_URL:                  ' + QT_SRC_PACKAGE_URL
    print 'QT_SRC_PACKAGE_URL_SAVE_ASL:         ' + QT_SRC_PACKAGE_URL_SAVE_AS
    print 'QT_SOURCE_DIR:                       ' + QT_SOURCE_DIR
    print 'QT_BUILD_DIR:                        ' + QT_BUILD_DIR
    print 'QT_INSTALLERFW_QT_CONFIGURE_LINE:    [' + QT_INSTALLERFW_QT_CONFIGURE_LINE + ']'
    print 'QT_QMAKE_BIN:                        ' + QT_QMAKE_BIN
    print 'QT_CONFIGURE_BIN:                    ' + QT_CONFIGURE_BIN
    print ''
    print 'INSTALLER_FRAMEWORK_URL:             ' + INSTALLER_FRAMEWORK_URL
    print 'INSTALLER_FRAMEWORK_SOURCE_DIR:      ' + INSTALLER_FRAMEWORK_SOURCE_DIR
    print 'INSTALLER_FRAMEWORK_BUILD_DIR:       ' + INSTALLER_FRAMEWORK_BUILD_DIR
    print 'INSTALLER_FRAMEWORK_VERSION_TAG:     ' + INSTALLER_FRAMEWORK_VERSION_TAG
    print 'INSTALLER_FRAMEWORK_QMAKE_ARGS:      [' + INSTALLER_FRAMEWORK_QMAKE_ARGS + ']'
    print ''
    print 'Installer-Framework Output: ' + INSTALLER_FRAMEWORK_ARCHIVE_NAME
    print 'Installerbase Output: ' + INSTALLERBASE_ARCHIVE_NAME
    print '----------------------------------------'


###############################
# function
###############################
def prepare_qt_sources():
    if DEVELOPMENT_MODE:
        if os.path.exists(QT_SOURCE_DIR):
            return

    print '--------------------------------------------------------------------'
    print 'Fetching Qt src package from: ' + QT_SRC_PACKAGE_URL
    if not os.path.isfile(QT_SRC_PACKAGE_URL_SAVE_AS):
        if not bldinstallercommon.is_content_url_valid(QT_SRC_PACKAGE_URL):
            print '*** Qt src package url is invalid! Abort!'
            sys.exit(-1)
        urllib.urlcleanup()
        urllib.urlretrieve(QT_SRC_PACKAGE_URL, QT_SRC_PACKAGE_URL_SAVE_AS)
    else:
        print 'Found old local package, using that: ' + QT_SRC_PACKAGE_URL_SAVE_AS
    print 'Done'
    print '--------------------------------------------------------------------'

    bldinstallercommon.create_dirs(QT_SOURCE_DIR)
    bldinstallercommon.extract_file(QT_SRC_PACKAGE_URL_SAVE_AS, QT_SOURCE_DIR)

    l = os.listdir(QT_SOURCE_DIR)
    items = len(l)
    if items == 1:
        dir_name = l[0]
        full_dir_name = QT_SOURCE_DIR + os.sep + dir_name
        bldinstallercommon.move_tree(full_dir_name, QT_SOURCE_DIR)
        bldinstallercommon.remove_tree(full_dir_name)
    else:
        print '*** Invalid dir structure encountered?!'
        sys.exit(-1)


###############################
# function
###############################
def build_qt():
    if DEVELOPMENT_MODE:
        if os.path.exists(QT_BUILD_DIR):
            return

    bldinstallercommon.create_dirs(QT_BUILD_DIR)
    # configure first
    print '--------------------------------------------------------------------'
    print 'Configuring Qt'
    # TODO, nasty hack, beucause of a bug in python ConfigParser module, loses trailing white spaces!!
    cmd_args = ''
    if bldinstallercommon.is_win_platform():
        cmd_args = QT_CONFIGURE_BIN + ' ' + QT_INSTALLERFW_QT_CONFIGURE_LINE + ' ' + QT_BUILD_DIR
    else:
        cmd_args = QT_CONFIGURE_BIN + ' ' + QT_INSTALLERFW_QT_CONFIGURE_LINE + QT_BUILD_DIR
    bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), QT_BUILD_DIR, True)

    print '--------------------------------------------------------------------'
    print 'Building Qt'
    cmd_args = MAKE_CMD
    bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), QT_BUILD_DIR, True)


###############################
# function
###############################
def prepare_installer_framework():
    if DEVELOPMENT_MODE:
        if os.path.exists(INSTALLER_FRAMEWORK_SOURCE_DIR):
            return

    print '--------------------------------------------------------------------'
    print 'Prepare Installer Framework source'
    #create dirs
    bldinstallercommon.create_dirs(INSTALLER_FRAMEWORK_BUILD_DIR)
    # clone repos
    bldinstallercommon.clone_repository(INSTALLER_FRAMEWORK_URL, INSTALLER_FRAMEWORK_VERSION_TAG, INSTALLER_FRAMEWORK_SOURCE_DIR)


###############################
# function
###############################
def build_installer_framework():
    print '--------------------------------------------------------------------'
    print 'Building Installer Framework'

    qmake_bin = QT_BUILD_DIR + os.sep + 'bin' + os.sep + QT_QMAKE_BIN
    if not os.path.isfile(qmake_bin):
        print '*** Unable to find qmake, aborting!'
        print 'qmake: ' + qmake_bin
        sys.exit(-1)

    if not os.path.exists(INSTALLER_FRAMEWORK_BUILD_DIR):
        bldinstallercommon.create_dirs(INSTALLER_FRAMEWORK_BUILD_DIR)

    cmd_args = qmake_bin + ' ' + INSTALLER_FRAMEWORK_QMAKE_ARGS + ' ' + INSTALLER_FRAMEWORK_SOURCE_DIR
    bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), INSTALLER_FRAMEWORK_BUILD_DIR, True)

    cmd_args = MAKE_CMD
    bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), INSTALLER_FRAMEWORK_BUILD_DIR, True)


###############################
# function
###############################
def clean_build_environment():
    if DEVELOPMENT_MODE:
        return

    # delete existing stuff if exists
    if os.path.exists(INSTALLER_FRAMEWORK_SOURCE_DIR):
        bldinstallercommon.remove_tree(INSTALLER_FRAMEWORK_SOURCE_DIR)
    if os.path.exists(INSTALLER_FRAMEWORK_BUILD_DIR):
        bldinstallercommon.remove_tree(INSTALLER_FRAMEWORK_BUILD_DIR)
    if os.path.exists(QT_SOURCE_DIR):
        bldinstallercommon.remove_tree(QT_SOURCE_DIR)
    if os.path.exists(QT_BUILD_DIR):
        bldinstallercommon.remove_tree(QT_BUILD_DIR)
    if os.path.isfile(INSTALLER_FRAMEWORK_ARCHIVE_NAME):
        os.remove(INSTALLER_FRAMEWORK_ARCHIVE_NAME)
    if os.path.isfile(QT_SRC_PACKAGE_URL_SAVE_AS):
        os.remove(QT_SRC_PACKAGE_URL_SAVE_AS)


###############################
# function
###############################
def archive_installer_framework():
    if DEVELOPMENT_MODE:
        return

    print '--------------------------------------------------------------------'
    print 'Archive Installer Framework'
    # first strip out all unnecessary files
    for root, dirs, files in os.walk(INSTALLER_FRAMEWORK_BUILD_DIR):
        for filename in files:
            if filename.endswith(('.moc', 'Makefile', '.cpp', '.h', '.o')) or filename == 'Makefile':
                os.remove(os.path.join(root, filename))

    cmd_args = ['7z', 'a', INSTALLER_FRAMEWORK_ARCHIVE_NAME, os.path.basename(INSTALLER_FRAMEWORK_BUILD_DIR)]
    bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)


###############################
# function
###############################
def archive_installerbase():
    if DEVELOPMENT_MODE:
        return

    print '--------------------------------------------------------------------'
    print 'Archive Installerbase'
    cmd_args_archive = []
    cmd_args_clean = []

    bin_temp = ''
    if bldinstallercommon.is_linux_platform() or bldinstallercommon.is_mac_platform():
        bin_path = bldinstallercommon.locate_executable(INSTALLER_FRAMEWORK_BUILD_DIR, 'installerbase')
        bin_temp = SCRIPT_ROOT_DIR + os.sep + '.tempSDKMaintenanceTool'
        shutil.copy(bin_path, bin_temp)
        cmd_args_archive = ['7z', 'a', INSTALLERBASE_ARCHIVE_NAME, bin_temp]
        cmd_args_clean = ['rm', bin_temp]
    if bldinstallercommon.is_win_platform():
        bin_path = bldinstallercommon.locate_executable(INSTALLER_FRAMEWORK_BUILD_DIR, 'installerbase.exe')
        bin_temp = SCRIPT_ROOT_DIR + os.sep + 'temp'
        bldinstallercommon.create_dirs(bin_temp)
        shutil.copy(bin_path, bin_temp + os.sep + 'SDKMaintenanceToolBase.exe')
        cmd_args_archive = ['7z', 'a', INSTALLERBASE_ARCHIVE_NAME, bin_temp]
        cmd_args_clean = ['rmdir' ,'/q/s', bin_temp]

    bldinstallercommon.do_execute_sub_process(cmd_args_archive, SCRIPT_ROOT_DIR, True)
    bldinstallercommon.do_execute_sub_process(cmd_args_clean, SCRIPT_ROOT_DIR, True)

    if not os.path.isfile(INSTALLERBASE_ARCHIVE_NAME):
        print '*** Failed to generate archive: ' + INSTALLERBASE_ARCHIVE_NAME
        sys.exit(-1)


###############################
# function
###############################
def archive_nib():
    print '--------------------------------------------------------------------'
    print 'Archive qt_menu.nib'

    content_parent_path = QT_SOURCE_DIR + os.sep + 'src/gui/mac'
    content_root_path = content_parent_path + os.sep + 'qt_menu.nib'

    content_parent_path = os.path.normpath(content_parent_path)
    content_root_path = os.path.normpath(content_root_path)
    archive_name = 'qt_menu.nib.7z'

    cmd_args = ['7z', 'a', archive_name, content_root_path]
    bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)

    if not os.path.isfile(archive_name):
        print '*** Failed to generate archive: ' + archive_name
        sys.exit(-1)


###############################
# function
###############################
def archive_macdeployqt():
    print '--------------------------------------------------------------------'
    print 'Archive macdeployqt'

    content_path = QT_BUILD_DIR + os.sep + 'tools/macdeployqt/macchangeqt/macchangeqt'
    archive_name = bldinstallercommon.config_section_map(CONFIG_IFW,'Output')['macdeployqt_archive_name']
    if not archive_name:
        print '*** Error! macdeployqt_archive_name not defined?!'
        sys.exit(-1)
    cmd_args_archive = ['7z', 'a', archive_name, content_path]
    bldinstallercommon.do_execute_sub_process(cmd_args_archive, SCRIPT_ROOT_DIR, True)

    if not os.path.isfile(archive_name):
        print '*** Failed to generate archive: ' + archive_name
        sys.exit(-1)


###############################
# function
###############################
def archive_qt():
    print '--------------------------------------------------------------------'
    print 'Archive static Qt build'

    content_path = QT_BUILD_DIR
    archive_name = bldinstallercommon.config_section_map(CONFIG_IFW,'Output')['qt_archive_name']
    if not archive_name:
        print '*** Error! macdeployqt_archive_name not defined?!'
        sys.exit(-1)
    # these directories can be deleted from the Qt binary package (built for SDK purposes only)
    directories_to_delete = ['config.tests', 'src', 'qmake', 'doc', 'imports', 'lib' + os.sep + 'pkgconfig', 'tools']
    for item in directories_to_delete:
        full_path = content_path + os.sep + item
        if os.path.exists(full_path) and not os.path.islink(full_path):
            print 'Deleting: ' + item
            shutil.rmtree(full_path)
    # then strip out all remaining unnecessary files
    for root, dirs, files in os.walk(content_path + os.sep + 'bin'):
        for filename in files:
            if filename.endswith(('.moc', 'Makefile', '.cpp', '.h', '.o')) or filename == 'Makefile':
                os.remove(os.path.join(root, filename))
            if filename.startswith(('designer', 'assistant', 'qcollectiongenerator', 'linguist', 'qhelpconverter', 'qhelpgenerator', 'pixeltool', 'qdoc3', 'qt3to4')):
                os.remove(os.path.join(root, filename))
    # archive libraries
    cmd_args_archive = ['7z', 'a', archive_name, content_path]
    bldinstallercommon.do_execute_sub_process(cmd_args_archive, SCRIPT_ROOT_DIR, True)
    # check archive was generated successfully
    if not os.path.isfile(archive_name):
        print '*** Failed to generate archive: ' + archive_name
        sys.exit(-1)


###############################
# main
###############################
def build_ifw(build_mode, platform):
    global DEVELOPMENT_MODE
    global PLATFORM_IDENTIFIER

    if build_mode == 'devmode':
        DEVELOPMENT_MODE = True
    PLATFORM_IDENTIFIER = platform

    # init
    bldinstallercommon.init_common_module(SCRIPT_ROOT_DIR)
    init_config()
    #clean environment first
    clean_build_environment()
    #checkout sources
    prepare_installer_framework()
    # copy qt sources
    prepare_qt_sources()
    # build qt
    build_qt()
    # build installer framework
    build_installer_framework()
    #archive
    archive_installerbase()
    archive_installer_framework()
    # for mac we do some extra work
    if bldinstallercommon.is_mac_platform():
        archive_nib()
        archive_macdeployqt()
    # archive static qt package
    archive_qt()
    if build_mode == 'devmode':
        #TODO, the returned values should be in config file, not return it here!
        return os.path.basename(INSTALLER_FRAMEWORK_BUILD_DIR)
    else:
        return ''