build_wrapper: Add validation for APPLICATION_NAME and APPLICATION_VERSION
[qtsdk:qtsdk.git] / packaging-tools / build_wrapper.py
1 #!/usr/bin/env python
2 #############################################################################
3 ##
4 ## Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
5 ## Contact: http://www.qt-project.org/legal
6 ##
7 ## This file is part of the release tools of the Qt Toolkit.
8 ##
9 ## $QT_BEGIN_LICENSE:LGPL$
10 ## Commercial License Usage
11 ## Licensees holding valid commercial Qt licenses may use this file in
12 ## accordance with the commercial license agreement provided with the
13 ## Software or, alternatively, in accordance with the terms contained in
14 ## a written agreement between you and Digia.  For licensing terms and
15 ## conditions see http://qt.digia.com/licensing.  For further information
16 ## use the contact form at http://qt.digia.com/contact-us.
17 ##
18 ## GNU Lesser General Public License Usage
19 ## Alternatively, this file may be used under the terms of the GNU Lesser
20 ## General Public License version 2.1 as published by the Free Software
21 ## Foundation and appearing in the file LICENSE.LGPL included in the
22 ## packaging of this file.  Please review the following information to
23 ## ensure the GNU Lesser General Public License version 2.1 requirements
24 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ##
26 ## In addition, as a special exception, Digia gives you certain additional
27 ## rights.  These rights are described in the Digia Qt LGPL Exception
28 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file.  Please review the following information to
35 ## ensure the GNU General Public Lhttps://www.google.fi/icense version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ##
39 ## $QT_END_LICENSE$
40 ##
41 #############################################################################
42
43 """Scripts to generate SDK installer based on open source InstallerFramework"""
44
45 # import the print function which is used in python 3.x
46 from __future__ import print_function
47 import ConfigParser
48 import os
49 import shutil
50 import sys
51 import re
52 from time import gmtime, strftime
53 import urllib
54 from optparse import OptionParser, Option
55
56
57 import bldinstallercommon
58 import release_build_handler
59
60
61 # ----------------------------------------------------------------------
62 # external commands
63 CURL_COMMAND                = ''
64 RM_COMMAND                  = ''
65 SSH_COMMAND                 = ''
66 SCP_COMMAND                 = ''
67
68 # ----------------------------------------------------------------------
69 BUILD_TIMESTAMP             = strftime('%Y-%m-%d', gmtime())
70 SCRIPT_ROOT_DIR             = os.path.dirname(os.path.realpath(__file__))
71 REPO_OUTPUT_DIR             = os.path.normpath(os.path.join(SCRIPT_ROOT_DIR, 'repository'))
72 WORK_DIR                    = os.path.join(os.environ['PKG_NODE_ROOT'], 'build')
73 #WORK_DIR                    = os.environ['PKG_NODE_ROOT']
74 COMMAND                     = ''
75 LICENSE                     = ''
76 OPTION_PARSER               = 0
77 QT_VERSION                  = ''
78 QT_VERSION_TAG              = ''
79 QTCREATOR_VERSION           = ''
80 QTCREATOR_VERSION_DESCRIPTION = ''
81 QT_FULL_VERSION             = ''
82 TIME_STAMP                  = ''
83 BUILD_NUMBER                = ''
84 PKG_SERVER_ADDR             = ''
85 PATH                        = '/data/www/packages/jenkins'
86 SNAPSHOT_SERVER             = ''
87 SNAPSHOT_PATH               = ''
88 TARGET_ENV                  = ''
89 ICU_LIBS                    = 'http://download.qt-project.org/development_releases/prebuilt/icu/src/icu4c-51_1-src.tgz'
90 QT_SRC_FOR_IFW_PREPARED     = 'http://download.qt-project.org/development_releases/prebuilt/qt-src-for-ifw/qt_4.8.4_ifw_prepared'
91 IFW_GIT_URL                 = 'git://gitorious.org/installer-framework/installer-framework.git'
92 SRC_URL_PREFIX              = 'http://qt-rnd.it.local/packages/jenkins'
93 SRC_URL                     = ''
94 PLATFORM                    = ''
95 SRC_DEST_DIRS               = ['src', 'src/submodules', 'src/examples_injection', 'src/licheck']
96 INSTALLER_BUILD_OUTPUT_DIR  = 'build_artifacts'
97 # TODO: target directories hard coded, should be figured out from somewhere!
98 BIN_TARGET_DIRS             = \
99 {'linux-g++-Ubuntu11.10-x86_Android-armv5':'android_armv5/linux_x86'\
100 ,'linux-g++-Ubuntu11.10-x64_Android-armv5':'android_armv5/linux_x64'\
101 ,'mac-clang-10.7-x64_Android-armv5':'android_armv5/mac_x64'\
102 ,'win-MinGW4.8-Windows7-x86_Android-armv5':'android_armv5/mingw_x86'\
103 ,'linux-g++-Ubuntu11.10-x86_Android-armv7':'android_armv7/linux_x86'\
104 ,'linux-g++-Ubuntu11.10-x64_Android-armv7':'android_armv7/linux_x64'\
105 ,'mac-clang-10.7-x64_Android-armv7':'android_armv7/mac_x64'\
106 ,'win-MinGW4.8-Windows7-x86_Android-armv7':'android_armv7/mingw_x86'\
107 ,'linux-g++-Ubuntu11.10-x86_Android-mips':'android_mips/linux_x86'\
108 ,'linux-g++-Ubuntu11.10-x64_Android-mips':'android_mips/linux_x64'\
109 ,'mac-clang-10.7-x64_Android-mips':'android_mips/mac_x64'\
110 ,'win-MinGW4.8-Windows7-x86_Android-mips':'android_mips/mingw_x86'\
111 ,'linux-g++-Ubuntu11.10-x86_Android-x86':'android_x86/linux_x86'\
112 ,'linux-g++-Ubuntu11.10-x64_Android-x86':'android_x86/linux_x64'\
113 ,'mac-clang-10.7-x64_Android-x86':'android_x86/mac_x64'\
114 ,'win-MinGW4.8-Windows7-x86_Android-x86':'android_x86/mingw_x86'\
115 ,'mac-clang-10.8-x64_iOS':'ios/mac_x64'\
116 ,'mac-clang-10.8-x64_iOS-iphoneos':'ios_armv7/mac_x64'\
117 ,'mac-clang-10.8-x64_iOS-iphonesimulator':'ios_x86/mac_x64'\
118 ,'linux-g++-Ubuntu11.10-x86':'linux_gcc_32_ubuntu1110'\
119 ,'linux-g++-Ubuntu11.10-x64':'linux_gcc_64_ubuntu1110'\
120 ,'linux-g++-Ubuntu_11.10_x86':'linux_gcc_32_ubuntu1110'\
121 ,'linux-g++-Ubuntu_11.10_x64':'linux_gcc_64_ubuntu1110'\
122 ,'mac-clang-OSX_10.7_x64':'mac_cocoa_10.7'\
123 ,'mac-clang-10.8-x64':'mac_cocoa_10.7'\
124 ,'win-MinGW4.8-Windows7-x86_OpenGL':'windows_mingw'\
125 ,'win-msvc2010-Windows7-x86_ANGLE':'windows_vs2010_32'\
126 ,'win-msvc2010-Windows7-x86_OpenGL':'windows_vs2010_32_opengl'\
127 ,'win-msvc2012-Windows8-x86_ANGLE':'windows_vs2012_32'\
128 ,'win-msvc2012-Windows8-x64_ANGLE':'windows_vs2012_64'\
129 ,'win-msvc2012-Windows8-x64_OpenGL':'windows_vs2012_64_opengl'\
130 ,'win32-msvc2010_Windows_7':'windows_vs2010_32'\
131 ,'win64-msvc2012_Windows_8':'windows_vs2012_64'\
132 ,'macx-clang_OSX_10.7':'mac_cocoa_10.7'\
133 ,'pkg-osx107-x64-01':'mac_cocoa_10.7'\
134 ,'mac-clang-10.7-x64':'mac_cocoa_10.7'\
135 ,'pkg-win7-x86-01':'windows_vs2010_32'}
136 REMOTE_DIR                  = ''
137 LATEST_DIR                  = ''
138 EXTRA_ENV                   = dict(os.environ)
139 MAKE_INSTALL_PADDING        = ''
140
141
142 ###########################################
143 # Define possible commands for this script
144 ###########################################
145 class BldCommand:
146     init_build_cycle            = 'init'
147     execute_qt5_src_pkg         = 'build_src'
148     execute_qt5_bin_bld         = 'build_bin'
149     execute_qt5_app_bld         = 'build_qt5_app'
150     execute_ifw_bld             = 'ifw'
151     execute_creator_bld         = 'build_creator'
152     execute_repo_bld            = 'repo_build'
153     execute_offline_inst_bld    = 'offline_installer'
154     execute_online_inst_bld     = 'online_installer'
155     publish_qt5_src_pkg         = 'publish_src_packages'
156
157     def __init__(self, options):
158         self.options = options
159
160     ###########################################
161     # Validate the given command
162     ###########################################
163     def is_valid_cmd(self):
164         commands = [self.init_build_cycle]
165         commands += [self.execute_qt5_src_pkg]
166         commands += [self.execute_qt5_bin_bld]
167         commands += [self.execute_qt5_app_bld]
168         commands += [self.execute_ifw_bld]
169         commands += [self.execute_creator_bld]
170         commands += [self.execute_repo_bld]
171         commands += [self.execute_offline_inst_bld]
172         commands += [self.execute_online_inst_bld]
173         commands += [self.publish_qt5_src_pkg]
174         if self.options.command not in commands:
175             return False
176         return True
177
178     ###########################################
179     # Validate generic build arguments
180     ###########################################
181     def validate_bld_args(self):
182         if not self.options.command:
183             print('*** Build command not given? Aborting....')
184             return False
185         if not self.is_valid_cmd():
186             print('*** The given build command enum is invalid: {0}'.format(self.options.command))
187         if self.options.command == self.execute_repo_bld:
188             if len(sys.argv) < 4:
189                 return False
190         elif self.options.command == self.execute_online_inst_bld:
191             if len(sys.argv) < 4:
192                 print('*** Insufficient arguments for online installer build!')
193                 return False
194         elif self.options.command == self.execute_qt5_app_bld:
195             return self.validate_qt5_app_build_args()
196         else:
197             if len(sys.argv) < 15:
198                 return False
199         return True
200
201     ###########################################
202     # Validate build args for Qt5 app build
203     ###########################################
204     def validate_qt5_app_build_args(self):
205         print(self.options)
206         # check env variables
207         if not os.environ.get('APPLICATION_NAME'):
208             print('*** Qt5 app build missing environment variable: {0}'.format('APPLICATION_NAME'))
209             sys.exit(-1)
210         if not os.environ.get('APPLICATION_VERSION'):
211             print('*** Qt5 app build missing environment variable: {0}'.format('APPLICATION_VERSION'))
212             sys.exit(-1)
213         if not os.environ.get('QT5_APPLICATION_SRC_URI'):
214             print('*** Qt5 app build missing environment variable: {0}'.format('QT5_APPLICATION_SRC_URI'))
215             sys.exit(-1)
216         if not os.environ.get('QT5_ESSENTIALS_LIB_PACKAGE_URI'):
217             print('*** Qt5 app build missing environment variable: {0}'.format('QT5_ESSENTIALS_LIB_PACKAGE_URI'))
218             sys.exit(-1)
219         if not os.environ.get('QT5_ADDONS_LIB_PACKAGE_URI'):
220             print('*** Qt5 app build missing environment variable: {0}'.format('QT5_ADDONS_LIB_PACKAGE_URI'))
221             sys.exit(-1)
222         if bldinstallercommon.is_win_platform():
223             if not os.environ.get('QT5_APPLICATION_BUILD_CMD'):
224                 print('*** Qt5 app build missing environment variable: {0}'.format('QT5_APPLICATION_BUILD_CMD'))
225                 sys.exit(-1)
226             if not os.environ.get('QT5_APPLICATION_INSTALL_CMD'):
227                 print('*** Qt5 app build missing environment variable: {0}'.format('QT5_APPLICATION_INSTALL_CMD'))
228                 sys.exit(-1)
229             if not os.environ.get('7Z_TOOL_PATH'):
230                 print('*** Qt5 app build missing environment variable: {0}'.format('7Z_TOOL_PATH'))
231                 sys.exit(-1)
232             if not os.environ.get('GIT_TOOL_PATH'):
233                 print('*** Qt5 app build missing environment variable: {0}'.format('GIT_TOOL_PATH'))
234                 sys.exit(-1)
235         if bldinstallercommon.is_mac_platform():
236             if not os.environ.get('IFW_INSTALLERBASE_URI'):
237                 print('*** Qt5 app build missing environment variable: {0}'.format('IFW_INSTALLERBASE_URI'))
238                 sys.exit(-1)
239         # check command line arguments
240         if not self.options.license:
241             print('*** Qt5 app build missing command line argument: --license')
242             sys.exit(-1)
243         if not self.options.server:
244             print('*** Qt5 app build missing command line argument: --server')
245             sys.exit(-1)
246         if self.is_qt5_release_build() and not self.options.qt_version:
247             print('*** Qt5 app build missing command line argument: --qt_version')
248             sys.exit(-1)
249         if not self.options.target_env:
250             print('*** Qt5 app build missing command line argument: --target_env')
251             sys.exit(-1)
252         if not self.options.path:
253             print('*** Qt5 app build missing command line argument: --path')
254             sys.exit(-1)
255
256         return True
257
258     ###########################################
259     # Determine if command relates to qt5 builds
260     ###########################################
261     def is_qt5_release_build(self):
262         cmd_list = [self.init_build_cycle]
263         cmd_list += [self.execute_qt5_src_pkg]
264         cmd_list += [self.execute_qt5_bin_bld]
265         cmd_list += [self.publish_qt5_src_pkg]
266         if self.options.command not in cmd_list:
267             return False
268         return True
269
270     ###########################################
271     # Determine if this is Enginio build
272     ###########################################
273     def is_enginio_build(self):
274         if self.options.command == self.execute_qt5_app_bld:
275             app_name = os.environ.get('APPLICATION_NAME')
276             if 'enginio' in app_name.lower():
277                 return True
278         return False
279
280
281
282 class MultipleOption(Option):
283     ACTIONS = Option.ACTIONS + ("extend",)
284     STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
285     TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
286     ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
287
288     def take_action(self, action, dest, opt, value, values, parser):
289         if action == "extend":
290             values.ensure_value(dest, []).append(value)
291         else:
292             Option.take_action(self, action, dest, opt, value, values, parser)
293
294
295 ###############################
296 # Sanity check packaging server
297 ###############################
298 def sanity_check_packaging_server():
299     if not PKG_SERVER_ADDR:
300         print('*** Error - Packaging server address (PKG_SERVER_ADDR) not defined?')
301         sys.exit(-1)
302
303 ###############################
304 # sign windows executable
305 ###############################
306 def sign_windows_executable(file_path, working_dir, abort_on_fail):
307     cmd_args = ['C:\Utils\sign\signtool.exe', 'sign', '/v', '/du', os.environ['SIGNING_SERVER'], '/p', os.environ['SIGNING_PASSWORD'],
308         '/t', 'http://timestamp.verisign.com/scripts/timestamp.dll', '/f', 'C:\utils\sign\keys.pfx', file_path]
309     bldinstallercommon.do_execute_sub_process(cmd_args, working_dir, abort_on_fail)
310
311
312 ###############################
313 # Unlock keychain
314 ###############################
315 def unlock_keychain():
316     cmd_args = ['/Users/qt/unlock-keychain.sh']
317     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
318
319
320 ###############################
321 # Lock keychain
322 ###############################
323 def lock_keychain():
324     cmd_args = ['security', 'lock-keychain', 'Developer_ID_Digia.keychain']
325     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
326
327
328 ###############################
329 # sign windows executable
330 ###############################
331 def sign_mac_executable(file_path, working_dir, abort_on_fail):
332     s_arg = 'Developer ID Application: Digia Plc'
333     cmd_args = ['codesign', '-r', '/Users/qt/csreq.txt', '-s', s_arg, file_path]
334     bldinstallercommon.do_execute_sub_process(cmd_args, working_dir, abort_on_fail)
335
336
337 ###############################
338 # init_qt_build_cycle
339 ###############################
340 def init_qt_build_cycle():
341     sanity_check_packaging_server()
342     # create dir structures in network drive
343     # TODO: Figure out correct path + check parameters!
344     for dir_name in SRC_DEST_DIRS:
345         if dir_name != 'src/licheck':
346             dir_path = REMOTE_DIR + '/' + dir_name
347             create_remote_dirs(PKG_SERVER_ADDR, dir_path)
348         elif LICENSE == 'enterprise':
349             dir_path = REMOTE_DIR + '/' + dir_name
350             create_remote_dirs(PKG_SERVER_ADDR, dir_path)
351
352     # Create directories for targets
353     # for dir_name in BIN_TARGET_DIRS:
354     #    dir_path = os.path.join(REMOTE_DIR, dir_name)
355     #    create_remote_dirs(PKG_SERVER_ADDR, dir_path)
356
357     # Update latest link
358     cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, 'ln -sfn', REMOTE_DIR, LATEST_DIR]
359     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
360
361
362
363 ###############################
364 # handle_ifw_build()
365 ###############################
366 def handle_ifw_build():
367     sanity_check_packaging_server()
368     os.chdir(SCRIPT_ROOT_DIR)
369     extension = '.tar.gz'
370     qt_src_pkg = QT_SRC_FOR_IFW_PREPARED
371     ifw_url = IFW_GIT_URL
372     ifw_branch = os.environ['QT_INSTALLER_FRAMEWORK_VERSION']
373     if bldinstallercommon.is_win_platform():
374         extension = '.zip'
375     qt_src_pkg += extension
376     cmd_args = ['python', '-u', 'bld_ifw_tools.py', '--qt_archive_uri=' + qt_src_pkg, '--ifw_url=' + ifw_url, '--ifw_branch=' + ifw_branch]
377     if LICENSE == 'enterprise':
378         cmd_args += ['--product_key_checker_url=' + WORK_DIR + '/qtsdk-enterprise/productkeycheck/qt_product_key_checker.pri']
379     # execute
380     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
381
382     ## create destination dirs
383     # internal
384     create_remote_dirs(PKG_SERVER_ADDR, PATH + '/' + LICENSE + '/ifw/' + ifw_branch)
385     # public
386     if LICENSE == 'opensource':
387         # public server address and path
388         ext_server_base_url  = os.environ['EXT_SERVER_BASE_URL']
389         ext_server_base_path = os.environ['EXT_SERVER_BASE_PATH']
390         # public server directories
391         ext_dest_dir = ext_server_base_path + '/snapshots/ifw/' + ifw_branch + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER
392         cmd_args_mkdir_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
393         cmd_args_mkdir_ext = cmd_args_mkdir_pkg + ['ssh', ext_server_base_url, 'mkdir', '-p', ext_dest_dir]
394         bldinstallercommon.do_execute_sub_process(cmd_args_mkdir_ext, SCRIPT_ROOT_DIR, True)
395
396     if bldinstallercommon.is_win_platform():
397         file_list = os.listdir(SCRIPT_ROOT_DIR+'/' + INSTALLER_BUILD_OUTPUT_DIR)
398         for file_name in file_list:
399             if file_name.endswith(".7z"):
400                 cmd_args = [SCP_COMMAND, file_name, PKG_SERVER_ADDR + ':' + PATH + '/' + LICENSE + '/ifw/' + ifw_branch + '/']
401                 bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR + '/' + INSTALLER_BUILD_OUTPUT_DIR, True)
402     else:
403         cmd_args = ['rsync', '-r', './', PKG_SERVER_ADDR + ':' + PATH + '/' + LICENSE + '/ifw/' + ifw_branch + '/']
404         bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR + '/' + INSTALLER_BUILD_OUTPUT_DIR, True)
405
406     # copy ifw snapshot to public server
407     if LICENSE == 'opensource':
408         cmd_args_copy_ifw_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
409         cmd_args_copy_ifw_ext = cmd_args_copy_ifw_pkg + ['scp', PATH + '/' + LICENSE + '/ifw/' + ifw_branch + '/' + 'installer-framework-build*.7z', ext_server_base_url + ':' + ext_dest_dir]
410         bldinstallercommon.do_execute_sub_process(cmd_args_copy_ifw_ext, SCRIPT_ROOT_DIR, True)
411
412
413 ###############################
414 # handle_qt_src_package_build
415 ###############################
416 def handle_qt_src_package_build():
417     sanity_check_packaging_server()
418     exec_path = os.path.join(WORK_DIR, 'qt5')
419     #bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
420     if LICENSE == 'enterprise':
421         cmd_args = ['../patches/apply.sh']
422         bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
423
424     if LICENSE == 'enterprise':
425         copy_license_checkers()
426     package_path = os.path.join(WORK_DIR, 'src_pkg')
427     bldinstallercommon.create_dirs(package_path)
428     # parse module exclude list from release description file
429     conf_file_base_path = os.path.join(SCRIPT_ROOT_DIR, 'releases', os.environ['RELEASE_BUILD_CONF_FILE'])
430     parser = ConfigParser.ConfigParser()
431     parser.readfp(open(conf_file_base_path))
432     exclude_list = bldinstallercommon.safe_config_key_fetch(parser, 'release.global', 'module_exclude_list')
433     split_exclude_list = exclude_list.split(',')
434     module_exclude_list = []
435     for item in split_exclude_list:
436         module_exclude_list += ['-i', item]
437     # cmd args for source packaging srcipt
438     cmd_args = [os.path.join(SCRIPT_ROOT_DIR, 'mksrc.sh'), '-u', os.path.join(WORK_DIR, 'qt5')]
439     cmd_args += ['-v', QT_FULL_VERSION, '-m', '-N', '-l', LICENSE]
440     cmd_args += module_exclude_list
441     # create src package
442     bldinstallercommon.do_execute_sub_process(cmd_args, package_path, True)
443
444     # Example injection
445     package_name = 'qt-everywhere-' + LICENSE + '-src-' + QT_FULL_VERSION
446
447     cmd_args = ['tar', 'xzf', 'single/' + package_name + '.tar.gz']
448
449     bldinstallercommon.do_execute_sub_process(cmd_args, package_path, True)
450     essentials_path = os.path.join(WORK_DIR, 'src_pkg', 'examples_essentials')
451     bldinstallercommon.create_dirs(essentials_path)
452     addons_path = os.path.join(WORK_DIR, 'src_pkg', 'examples_addons')
453     bldinstallercommon.create_dirs(addons_path)
454
455     src_dirs = os.listdir(os.path.join(package_path, package_name))
456     current_path = os.getcwd()
457     os.chdir(os.path.join(package_path, package_name))
458     for dir_name in src_dirs:
459         if os.path.isdir(dir_name):
460             module_dirs = os.listdir(dir_name)
461             for example_dir in module_dirs:
462                 if example_dir == 'examples':
463                     bldinstallercommon.copy_tree(os.path.join(package_path, package_name, dir_name, example_dir), essentials_path)
464     os.chdir(current_path)
465     cmd_args = ['cp', '-r', os.path.join(package_name, 'qtbase', 'examples', 'examples.pro'), essentials_path]
466     bldinstallercommon.do_execute_sub_process(cmd_args, package_path, True)
467
468     # remove documentation source files ('doc' subdirs) from examples
469     doc_dir = 'doc'
470     for root, dirs, files in os.walk(essentials_path):
471         if doc_dir in dirs:
472             # do not recurse into doc directory
473             dirs.remove(doc_dir)
474             shutil.rmtree(os.path.join(root, doc_dir))
475
476     # remove out of place top level files from qtdeclarative
477     if os.path.exists(os.path.join(essentials_path, 'HACKING')):
478         os.remove(os.path.join(essentials_path, 'HACKING'))
479     if os.path.exists(os.path.join(essentials_path, 'README')):
480         os.remove(os.path.join(essentials_path, 'README'))
481
482     shutil.move(os.path.join(essentials_path, 'activeqt'), addons_path)
483     shutil.move(os.path.join(essentials_path, 'svg'), addons_path)
484
485     cmd_args = ['7z', 'a', os.path.join('..', 'examples_essentials.7z'), '*']
486     bldinstallercommon.do_execute_sub_process(cmd_args, essentials_path, True)
487     cmd_args = [os.path.join(SCRIPT_ROOT_DIR, 'winzipdir.sh'), os.path.join('..', 'examples_essentials.zip'), '.' ]
488     bldinstallercommon.do_execute_sub_process(cmd_args, essentials_path, True)
489
490     cmd_args = ['7z', 'a', os.path.join('..', 'examples_addons.7z'), '*']
491     bldinstallercommon.do_execute_sub_process(cmd_args, addons_path, True)
492     cmd_args = [os.path.join(SCRIPT_ROOT_DIR, 'winzipdir.sh'), os.path.join('..', 'examples_addons.zip'), '.' ]
493     bldinstallercommon.do_execute_sub_process(cmd_args, addons_path, True)
494
495
496     # Upload packages
497     exec_path = SCRIPT_ROOT_DIR
498     cmd_args = ['rsync', '-r', '../../src_pkg/single/', PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'single', '')]
499     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
500     cmd_args = ['rsync', '-r', '../../src_pkg/submodules_tar/', PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'submodules', '')]
501     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
502     cmd_args = ['rsync', '-r', '../../src_pkg/submodules_zip/', PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'submodules', '')]
503     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
504
505     file_list = os.listdir(package_path)
506     for file_name in file_list:
507         if file_name.startswith("examples_addons."):
508             cmd_args = ['scp', file_name, PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'examples_injection')]
509             bldinstallercommon.do_execute_sub_process(cmd_args, package_path, True)
510         if file_name.startswith("examples_essentials."):
511             cmd_args = ['scp', file_name, PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'examples_injection')]
512             bldinstallercommon.do_execute_sub_process(cmd_args, package_path, True)
513
514 ###############################
515 # handle_icu_build
516 ###############################
517 def handle_icu_build():
518     dir_list = os.listdir(WORK_DIR)
519     for file_name in dir_list:
520         if file_name.startswith("icu"):
521             cmd_args = 'rm -rf ' + file_name
522             bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), WORK_DIR, True)
523
524     cmd_args = 'rm -rf icu*'
525     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), WORK_DIR, True)
526     bldinstallercommon.create_dirs(os.path.join(WORK_DIR, 'icu_install'))
527     exec_path = WORK_DIR
528     cmd_args = ['wget', ICU_LIBS]
529     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
530     dir_list = os.listdir(WORK_DIR)
531     for file_name in dir_list:
532         if file_name.startswith("icu4c"):
533             cmd_args = ['tar', 'xvzf', file_name]
534             bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
535     EXTRA_ENV['LFLAGS'] = '-Wl,-rpath,\$ORIGIN'
536     cmd_args = ['./runConfigureICU', 'Linux', '--enable-rpath', '--prefix=' + os.path.join(WORK_DIR, 'icu_install')]
537     exec_path = os.path.join(WORK_DIR, 'icu', 'source')
538     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True, EXTRA_ENV)
539     cmd_args = ['make', '-j6']
540     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True, EXTRA_ENV)
541     cmd_args = ['make', 'install']
542     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True, EXTRA_ENV)
543
544     cmd_args = 'chrpath -r $ORIGIN libicuuc.so'
545     exec_path = os.path.join(WORK_DIR, 'icu_install', 'lib')
546     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
547     cmd_args = 'chrpath -r \$ORIGIN libicui18n.so'
548     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
549     cmd_args = 'chrpath -r \$ORIGIN libicudata.so'
550     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
551     cmd_args = 'chrpath -r \$ORIGIN libicuio.so'
552     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
553     cmd_args = 'chrpath -r \$ORIGIN libicule.so'
554     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
555     cmd_args = 'chrpath -r \$ORIGIN libiculx.so'
556     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
557     cmd_args = 'chrpath -r \$ORIGIN libicutest.so'
558     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
559     cmd_args = 'chrpath -r \$ORIGIN libicutu.so'
560     bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), exec_path, True, EXTRA_ENV)
561
562     dir_list = os.listdir(WORK_DIR)
563     for file_name in dir_list:
564         if file_name.startswith("icu"):
565             if file_name != 'icu_install':
566                 cmd_args = 'rm -rf ' + file_name
567                 bldinstallercommon.do_execute_sub_process(cmd_args.split(' '), WORK_DIR, True)
568
569 ###############################
570 # handle_qt_android_release_build
571 ###############################
572 def handle_qt_android_release_build():
573     cmd_args = ''
574     script_path = os.path.join(SCRIPT_ROOT_DIR, 'mkqt5bld.py')
575     source_url = SRC_URL+'/single/qt-everywhere-' + LICENSE + '-src-' + QT_FULL_VERSION
576     configure_files_path = os.path.join(SCRIPT_ROOT_DIR, 'bld_config', '')
577
578     qt_configure_options_file = os.environ['RELEASE_BUILD_QT_CONFIGURE_OPTIONS_FILE']
579     android_ndk_host          = os.environ['ANDROID_NDK_HOST']
580     android_toolchain_version = os.environ['ANDROID_TOOLCHAIN_VERSION']
581     android_api_version       = os.environ['ANDROID_API_VERSION']
582     android_sdk_home          = os.environ['ANDROID_SDK_HOME']
583     android_ndk_home          = os.environ['ANDROID_NDK_HOME']
584     if os.environ.get('EXTRA_QT_CONFIGURE_OPTIONS'):
585         configure_extra_options = os.environ['EXTRA_QT_CONFIGURE_OPTIONS']
586     else:
587         configure_extra_options = ''
588     extension = '.tar.gz'
589     if bldinstallercommon.is_win_platform():
590         extension = '.zip'
591
592     cmd_args = ['python', '-u', script_path, '-u', source_url + extension]
593     if bldinstallercommon.is_win_platform():
594         cmd_args += ['-m', 'mingw32-make']
595     cmd_args += ['-c', configure_files_path + qt_configure_options_file]
596     cmd_args += ['--android-ndk-host=' + android_ndk_host]          # "linux-x86" or "linux-x86_64" or "windows" or "darwin-x86_64"
597     cmd_args += ['--android-api-version=' + android_api_version]    # e.g. "android-10"
598     cmd_args += ['--android-sdk-home=' + android_sdk_home]          # e.g. "/opt/android/sdk"
599     cmd_args += ['--android-ndk-home=' + android_ndk_home]          # e.g. "/opt/android/ndk"
600     if bldinstallercommon.is_linux_platform():
601         cmd_args += ['--replace-rpath']
602     cmd_args += ['-a', configure_extra_options + ' -prefix ' + os.path.join(WORK_DIR,  MAKE_INSTALL_PADDING)]
603     cmd_args += [' -android-toolchain-version ' + android_toolchain_version]    # e.g. "4.8"
604
605     if bldinstallercommon.is_linux_platform() or bldinstallercommon.is_mac_platform():
606         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
607     elif bldinstallercommon.is_win_platform():
608         exec_dir = os.getcwd()
609         bldinstallercommon.do_execute_sub_process(cmd_args, exec_dir, True)
610
611
612 ###############################
613 # handle_qt_ios_release_build
614 ###############################
615 def handle_qt_ios_release_build():
616     qt_configure_options_file = os.environ['RELEASE_BUILD_QT_CONFIGURE_OPTIONS_FILE']
617     configure_extra_options   = os.environ['EXTRA_QT_CONFIGURE_OPTIONS']
618
619     cmd_args = ''
620     script_path = os.path.join(SCRIPT_ROOT_DIR, 'mkqt5bld.py')
621     source_url = SRC_URL+'/single/qt-everywhere-' + LICENSE + '-src-' + QT_FULL_VERSION
622     configure_files_path = os.path.join(SCRIPT_ROOT_DIR, 'bld_config', '')
623     if bldinstallercommon.is_mac_platform():
624         if TARGET_ENV.find("x64") >= 1:
625             cmd_args = ['python', '-u', script_path, '-u', source_url + '.tar.gz', '-c', configure_files_path + qt_configure_options_file, '-a', configure_extra_options + ' -prefix ' + os.path.join(WORK_DIR, MAKE_INSTALL_PADDING)]
626         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
627
628
629 ###############################
630 # handle_qt_desktop_release_build
631 ###############################
632 def handle_qt_desktop_release_build():
633     # download pre-compiled ICU
634     icu_lib_path = ''
635     icu_include_path = ''
636     if ICU_LIBS != '':
637         handle_icu_build()
638
639     # del os.environ['QTDIR']
640     if ICU_LIBS != '':
641         dir_list = os.listdir(WORK_DIR)
642         print(dir_list)
643         for file_name in dir_list:
644             print(file_name)
645             if file_name.startswith("icu"):
646                 print(file_name)
647                 if os.path.isdir(os.path.join(WORK_DIR, file_name)):
648                     icu_lib_path = os.path.join(WORK_DIR, file_name, 'lib')
649                     icu_include_path = os.path.join(WORK_DIR, file_name, 'include')
650                     EXTRA_ENV['LD_LIBRARY_PATH'] = icu_lib_path
651
652     ## let's build Qt
653     # some common variables
654     script_path = os.path.join(SCRIPT_ROOT_DIR, 'mkqt5bld.py')
655     source_url = SRC_URL + '/single/qt-everywhere-' + LICENSE + '-src-' + QT_FULL_VERSION
656     configure_files_path = os.path.join(SCRIPT_ROOT_DIR, 'bld_config', '')
657
658     ## common cmd_args for all platforms
659     # we need to change the extension to .zip on windows. os x and linux use .tar.gz for the source file (.zip includes configure.exe)
660     extension = '.tar.gz'
661     if bldinstallercommon.is_win_platform():
662         extension = '.zip'
663     # this args don't change, so we can re-use them
664     cmd_args = ['python', '-u', script_path, '-u', source_url + extension, '--creator-dir=' + os.path.join(WORK_DIR, 'qt-creator')]
665     # on windows we build with jom instead of make
666     if bldinstallercommon.is_win_platform():
667         cmd_args += ['-m', 'jom']
668
669     # run mkqt5bld.py with the correct options according to the platform and license being used
670     if bldinstallercommon.is_linux_platform():
671         icu_lib_prefix_rpath = icu_lib_path + ' -I ' + icu_include_path + ' -prefix ' + os.path.join(WORK_DIR, MAKE_INSTALL_PADDING) + ' -R ' + os.path.join(WORK_DIR, MAKE_INSTALL_PADDING)
672         cmd_args += ['-c', configure_files_path + 'configure_linux_' + LICENSE]
673         if LICENSE == 'enterprise':
674             cmd_args += ['-a', '-DQT_EVAL -L ' + icu_lib_prefix_rpath]
675         elif LICENSE == 'opensource':
676             cmd_args += ['-a', '-L ' + icu_lib_prefix_rpath]
677         else:
678             print('*** License unknown: {0}'.format(LICENSE))
679             sys.exit(-1)
680         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True, EXTRA_ENV)
681     elif bldinstallercommon.is_win_platform():
682         exec_path = os.getcwd()
683         if LICENSE == 'enterprise':
684             if TARGET_ENV.find('opengl') >= 1 or TARGET_ENV.find('OpenGL') >= 1:
685                 cmd_args += ['-c', configure_files_path + 'configure_win_opengl_' + LICENSE]
686             else:
687                 cmd_args += ['-c', configure_files_path + 'configure_win_' + LICENSE]
688             cmd_args += ['-a', '-D QT_EVAL' + ' -prefix ' + os.path.join(WORK_DIR, MAKE_INSTALL_PADDING)]
689         elif LICENSE == 'opensource':
690             if TARGET_ENV.find('opengl') >=1 or TARGET_ENV.find('OpenGL') >= 1:
691                 cmd_args += ['-c', configure_files_path + 'configure_win_opengl_' + LICENSE]
692             else:
693                 cmd_args += ['-c', configure_files_path + 'configure_win_' + LICENSE]
694             cmd_args += ['-a', '-prefix ' + os.path.join(WORK_DIR, MAKE_INSTALL_PADDING)]
695         else:
696             print('*** License unknown: {0}'.format(LICENSE))
697             sys.exit(-1)
698         bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
699     elif bldinstallercommon.is_mac_platform():
700         cmd_args += ['-c', configure_files_path + 'configure_mac_' + LICENSE, '-a', '-prefix ' + os.path.join(WORK_DIR, MAKE_INSTALL_PADDING)]
701         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
702
703
704 ###############################
705 # Handle Application release build
706 ###############################
707 def handle_qt5_application_release_build():
708     script_path = os.path.join(SCRIPT_ROOT_DIR, 'bld_app.py')
709     icu7z_package = os.environ.get('ICU7Z')
710     qt5_addons_lib_package_uri = os.environ.get('QT5_ADDONS_LIB_PACKAGE_URI')
711     build_command = os.environ.get('QT5_APPLICATION_BUILD_CMD')
712     install_command = os.environ.get('QT5_APPLICATION_INSTALL_CMD')
713     # build command
714     cmd_args = ['python', '-u', script_path, '--clean']
715     cmd_args += ['--qt5path', 'qt5_package_dir']
716     cmd_args += ['--qt5_essentials7z', os.environ['QT5_ESSENTIALS_LIB_PACKAGE_URI']]
717     if qt5_addons_lib_package_uri:
718         cmd_args += ['--qt5_addons7z', qt5_addons_lib_package_uri]
719     cmd_args += ['--application7z', os.environ['QT5_APPLICATION_SRC_URI']]
720     if icu7z_package:
721         cmd_args += ['--icu7z', icu7z_package]
722     if build_command:
723         cmd_args += ['--buildcommand', build_command]
724     if install_command:
725         cmd_args += ['--installcommand', install_command]
726     if bldinstallercommon.is_win_platform():
727         cmd_args += ['--sevenzippath', os.environ.get('7Z_TOOL_PATH')]
728         cmd_args += ['--gitpath', os.environ.get('GIT_TOOL_PATH')]
729     if bldinstallercommon.is_mac_platform():
730         cmd_args += ['--installerbase7z', os.environ['IFW_INSTALLERBASE_URI']]
731     # init result directories
732     create_remote_dirs(PKG_SERVER_ADDR, LATEST_DIR + '/' + BIN_TARGET_DIRS[TARGET_ENV])
733     # execute build
734     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
735     # copy 7z files to network drive
736     remote_target_dir = PKG_SERVER_ADDR + ':' + LATEST_DIR + '/' + BIN_TARGET_DIRS[TARGET_ENV]
737     if bldinstallercommon.is_win_platform():
738         remote_target_dir += '/'
739     remote_copy_archives(remote_target_dir, os.path.join(SCRIPT_ROOT_DIR, 'module_archives'))
740
741
742 ###############################
743 # Remote copy files
744 ###############################
745 def remote_copy_archives(remote_target, from_where_path):
746     remote_copy_cmd = SCP_COMMAND
747     if bldinstallercommon.is_mac_platform():
748         remote_copy_cmd = 'rsync'
749     dir_list = os.listdir(from_where_path)
750     for file_name in dir_list:
751         if file_name.endswith(".7z"):
752             cmd_args = [remote_copy_cmd, file_name, remote_target]
753             bldinstallercommon.do_execute_sub_process(cmd_args, from_where_path, True)
754
755
756 ###############################
757 # handle_examples_injection
758 ###############################
759 def handle_examples_injection():
760     # Inject examples
761     if bldinstallercommon.is_linux_platform():
762         cmd_args = ['wget', SRC_URL + '/examples_injection/examples_essentials.7z']
763         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR + '/module_archives', True)
764         cmd_args = ['wget', SRC_URL + '/examples_injection/examples_addons.7z']
765         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR + '/module_archives', True)
766     elif bldinstallercommon.is_mac_platform():
767         cmd_args = [CURL_COMMAND, '-O', SRC_URL + '/examples_injection/examples_essentials.7z']
768         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
769         cmd_args = [CURL_COMMAND, '-O', SRC_URL + '/examples_injection/examples_addons.7z']
770         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
771     else:
772         if TARGET_ENV.find('x86') >=1:
773             cmd_args = [CURL_COMMAND, '-O', SRC_URL + '/examples_injection/examples_essentials.7z']
774             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
775             cmd_args = [CURL_COMMAND, '-O', SRC_URL + '/examples_injection/examples_addons.7z']
776             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
777         else:
778             cmd_args = [CURL_COMMAND, '-O', SRC_URL + '/examples_injection/examples_essentials.7z']
779             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
780             cmd_args = [CURL_COMMAND, '-O', SRC_URL + '/examples_injection/examples_addons.7z']
781             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
782
783     bldinstallercommon.create_dirs(os.path.join(WORK_DIR, 'module_archives', 'essentials'))
784     bldinstallercommon.create_dirs(os.path.join(WORK_DIR, 'module_archives', 'addons'))
785
786     if bldinstallercommon.is_win_platform():
787         if TARGET_ENV.find('x86') >= 1:
788             cmd_args = ['7z', 'x', 'qt5_essentials.7z', '-oessentials']
789             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
790             cmd_args = ['7z', 'x', 'examples_essentials.7z', os.path.join('-oessentials', 'examples'), '-y']
791             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
792
793             cmd_args = [RM_COMMAND, 'qt5_essentials.7z']
794             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
795             cmd_args = [RM_COMMAND, 'examples_essentials.7z']
796             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
797
798             cmd_args = ['7z', 'a', os.path.join('..', 'qt5_essentials.7z'), '*']
799             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives/essentials'), True)
800
801             cmd_args = ['7z', 'x', 'qt5_addons.7z', '-oaddons']
802             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
803             cmd_args = ['7z', 'x', 'examples_addons.7z', os.path.join('-oaddons', 'examples'), '-y']
804             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
805
806             cmd_args = [RM_COMMAND, 'qt5_addons.7z']
807             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
808             cmd_args = [RM_COMMAND, 'examples_addons.7z']
809             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
810
811             cmd_args = ['7z', 'a', os.path.join('..', 'qt5_addons.7z'), '*']
812             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives/addons'), True)
813         else:
814             cmd_args = ['7z', 'x', 'qt5_essentials.7z', '-oessentials']
815             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
816             cmd_args = ['7z', 'x', 'examples_essentials.7z', os.path.join('-oessentials', 'examples'), '-y']
817             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
818
819             cmd_args = [RM_COMMAND, 'qt5_essentials.7z']
820             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
821             cmd_args = [RM_COMMAND, 'examples_essentials.7z']
822             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
823
824             cmd_args = ['7z', 'a', os.path.join('..', 'qt5_essentials.7z'), '*']
825             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives/essentials'), True)
826
827             cmd_args = ['7z', 'x', 'qt5_addons.7z', '-oaddons']
828             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
829             cmd_args = ['7z', 'x', 'examples_addons.7z', os.path.join('-oaddons', 'examples'), '-y']
830             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
831
832             cmd_args = [RM_COMMAND, 'qt5_addons.7z']
833             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
834             cmd_args = [RM_COMMAND, 'examples_addons.7z']
835             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
836
837             cmd_args = ['7z', 'a', os.path.join('..', 'qt5_addons.7z'), '*']
838             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives/addons'), True)
839     else:
840         cmd_args = ['7z', 'x', 'qt5_essentials.7z', '-oessentials']
841         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
842         cmd_args = ['7z', 'x', 'examples_essentials.7z', os.path.join('-oessentials', 'examples'), '-y']
843         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
844
845         cmd_args = [RM_COMMAND, 'qt5_essentials.7z']
846         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
847         cmd_args = [RM_COMMAND, 'examples_essentials.7z']
848         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
849
850         cmd_args = ['7z', 'a', os.path.join('..', 'qt5_essentials.7z'), '*']
851         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives/essentials'), True)
852
853         cmd_args = ['7z', 'x', 'qt5_addons.7z', '-oaddons']
854         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
855         cmd_args = ['7z', 'x', 'examples_addons.7z', os.path.join('-oaddons', 'examples'), '-y']
856         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
857
858         cmd_args = [RM_COMMAND, 'qt5_addons.7z']
859         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
860         cmd_args = [RM_COMMAND, 'examples_addons.7z']
861         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
862
863         cmd_args = ['7z', 'a', os.path.join('..', 'qt5_addons.7z'), '*']
864         bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives/addons'), True)
865
866
867 ###############################
868 # handle_qt_release_build
869 ###############################
870 def handle_qt_release_build():
871     sanity_check_packaging_server()
872     # Handle Android build
873     if TARGET_ENV.find("Android") >= 1:
874         handle_qt_android_release_build()
875     elif TARGET_ENV.find("iOS") >= 1:
876         handle_qt_ios_release_build()
877     else:
878         handle_qt_desktop_release_build()
879         handle_examples_injection()
880
881     # Create target directory
882     create_remote_dirs(PKG_SERVER_ADDR, LATEST_DIR + '/' + BIN_TARGET_DIRS[TARGET_ENV])
883
884     dir_list = os.listdir(os.path.join(WORK_DIR, 'module_archives'))
885     print(dir_list)
886     for file_name in dir_list:
887         print(file_name)
888         if file_name.endswith(".7z"):
889             print(file_name)
890             if bldinstallercommon.is_linux_platform():
891                 cmd_args = [SCP_COMMAND, os.path.join(WORK_DIR, 'module_archives', file_name), PKG_SERVER_ADDR + ':' + LATEST_DIR + '/' + BIN_TARGET_DIRS[TARGET_ENV]]
892             elif bldinstallercommon.is_win_platform():
893                 cmd_args = [SCP_COMMAND, file_name, PKG_SERVER_ADDR + ':' + LATEST_DIR + '/' + BIN_TARGET_DIRS[TARGET_ENV] + '/']
894             else:
895                 cmd_args = ['rsync', os.path.join(WORK_DIR, 'module_archives', file_name), PKG_SERVER_ADDR + ':' + LATEST_DIR + '/' + BIN_TARGET_DIRS[TARGET_ENV]]
896             bldinstallercommon.do_execute_sub_process(cmd_args, os.path.join(WORK_DIR, 'module_archives'), True)
897
898     # TODO: Missing_modules.txt upload
899
900 ###############################
901 # handle_qt_creator_build
902 ###############################
903 def handle_qt_creator_build():
904     sanity_check_packaging_server()
905
906     # Qt Creator directory
907     dir_path = PATH + '/' + LICENSE + '/' + 'qtcreator'
908     create_remote_dirs(PKG_SERVER_ADDR, dir_path + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER)
909     cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, 'ln -sfn', dir_path + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER, dir_path + '/' + 'latest']
910     bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
911     dir_path = PATH + LICENSE + '/qtcreator/latest'
912
913     # snapshot directory
914     snapshot_path = SNAPSHOT_PATH
915     if SNAPSHOT_SERVER and SNAPSHOT_PATH:
916         if QTCREATOR_VERSION:
917             snapshot_path += '/' + QTCREATOR_VERSION
918         cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, "ssh", SNAPSHOT_SERVER,
919             'mkdir', '-p', snapshot_path + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER]
920         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
921         cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, "ssh", SNAPSHOT_SERVER,
922             'mkdir', '-p', snapshot_path + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER + '/installer_source']
923         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
924         cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, "ssh", SNAPSHOT_SERVER,
925             'ln', '-sfn', snapshot_path + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER,
926                     snapshot_path + '/latest']
927         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
928         snapshot_path += '/latest'
929
930     cmd_args = ['python', '-u', 'bld_qtcreator.py',
931         '--clean',
932         '--qt5path', os.path.normpath('../../qt5_install_dir'),
933         '--qt5_essentials7z', SRC_URL + BIN_TARGET_DIRS[TARGET_ENV] + '/qt5_essentials.7z',
934         '--qt5_addons7z', SRC_URL + BIN_TARGET_DIRS[TARGET_ENV] + '/qt5_addons.7z',
935         '--versiondescription', '"' + QTCREATOR_VERSION_DESCRIPTION + '"']
936
937     if LICENSE == 'enterprise':
938         cmd_args.extend(['--additional_plugin', os.path.normpath(WORK_DIR + '/qmlprofiler'),
939                          '--additional_plugin', os.path.normpath(WORK_DIR + '/qtquickdesigner')])
940
941     if bldinstallercommon.is_linux_platform():
942         cmd_args.extend(['--icu7z', ICU_LIBS])
943         if TARGET_ENV.find('64') != -1:
944             cmd_args.extend(['--installerbase7z', 'http://it-dl241-hki/packages/jenkins/' + LICENSE + '/ifw/1.5/installer-framework-build-linux-x64.7z'])
945         else:
946             cmd_args.extend(['--installerbase7z', 'http://it-dl241-hki/packages/jenkins/' + LICENSE + '/ifw/1.5/installer-framework-build-linux-x86.7z'])
947     elif bldinstallercommon.is_mac_platform():
948         cmd_args.extend(['--installcommand', 'make -j1',
949                          '--installerbase7z', 'http://it-dl241-hki/packages/jenkins/' + LICENSE + '/ifw/1.5/installer-framework-build-mac-x64.7z',
950                          '--keychain_unlock_script', '/Users/qt/unlock-keychain.sh'])
951     else:
952         cmd_args.extend(['--buildcommand', os.path.normpath('C:/Utils/jom/jom.exe'),
953                          '--installcommand', os.path.normpath('C:/Program Files/Microsoft Visual Studio 10.0/VC/bin/nmake.exe'),
954                          '--icu7z', ICU_LIBS,
955                          '--sevenzippath', os.path.normpath('C:/Utils/sevenzip'),
956                          '--gitpath', os.path.normpath('C:/Program Files/Git/bin'),
957                          '--d3dcompiler7z', 'http://download.qt-project.org/development_releases/prebuilt/d3dcompiler/msvc2010/D3DCompiler_43-x86.dll.7z',
958                          '--installerbase7z', 'http://it-dl241-hki/packages/jenkins/' + LICENSE + '/ifw/1.5/installer-framework-build-win-x86.7z',
959                          '--environment_batch', os.path.normpath('C:/Program Files/Microsoft Visual Studio 10.0/VC/vcvarsall.bat'),
960                          '--environment_batch_argument', 'x86'])
961
962     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
963
964     if bldinstallercommon.is_mac_platform():
965         lock_keychain()
966
967     postfix = ''
968     if QTCREATOR_VERSION:
969         postfix = '-' + QTCREATOR_VERSION
970     file_upload_list = [] # pairs (source, dest), source relative to WORK_DIR, dest relative to server + dir_path
971     snapshot_upload_list = [] # pairs (source, dest), source relative to server + dir_path, dest relative to snapshot server + snapshot_path
972     if bldinstallercommon.is_linux_platform():
973         linux_bits = '32'
974         linux_arch = 'x86'
975         if TARGET_ENV.find('64') != -1:
976             linux_bits = '64'
977             linux_arch = 'x86_64'
978         file_upload_list.append(('qt-creator_build/qt-creator-installer-archive.7z', 'qtcreator_linux_gcc_' + linux_bits + '_ubuntu1110.7z'))
979         file_upload_list.append(('qt-creator_build/qt-creator.run', 'qt-creator-' + LICENSE + '-linux-' + linux_arch + postfix + '.run'))
980         snapshot_upload_list.append(('qtcreator_linux_gcc_' + linux_bits + '_ubuntu1110.7z', 'installer_source/'))
981         snapshot_upload_list.append(('qt-creator-' + LICENSE + '-linux-' + linux_arch + postfix + '.run', ''))
982     elif bldinstallercommon.is_mac_platform():
983         file_upload_list.append(('qt-creator_build/qt-creator-installer-archive.7z', 'qtcreator_mac_cocoa_10_7.7z'))
984         if LICENSE == 'opensource': # opensource gets pure disk image with app and license.txt
985             file_upload_list.append(('qt-creator_build/qt-creator.dmg', 'qt-creator-' + LICENSE + '-mac-x86_64' + postfix + '.dmg'))
986         else: # enterprise gets installer with license check
987             file_upload_list.append(('qt-creator_build/qt-creator-installer.dmg', 'qt-creator-' + LICENSE + '-mac-x86_64' + postfix + '.dmg'))
988         snapshot_upload_list.append(('qtcreator_mac_cocoa_10_7.7z', 'installer_source/'))
989         snapshot_upload_list.append(('qt-creator-' + LICENSE + '-mac-x86_64' + postfix + '.dmg', ''))
990     else: # --> windows
991         file_upload_list.append(('qt-creator_build/qt-creator-installer-archive.7z', 'qtcreator_windows_vs2010_32.7z'))
992         sign_windows_executable('qt-creator_build/qt-creator.exe', WORK_DIR, True)
993         file_upload_list.append(('qt-creator_build/qt-creator.exe', 'qt-creator-' + LICENSE + '-windows-x86' + postfix + '.exe'))
994         snapshot_upload_list.append(('qtcreator_windows_vs2010_32.7z', 'installer_source/'))
995         snapshot_upload_list.append(('qt-creator-' + LICENSE + '-windows-x86' + postfix + '.exe', ''))
996
997     # upload files
998     for source, destination in file_upload_list:
999         cmd_args = [SCP_COMMAND, source, PKG_SERVER_ADDR + ':' + dir_path + '/' + destination]
1000         bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
1001     if SNAPSHOT_SERVER and SNAPSHOT_PATH:
1002         for source, destination in snapshot_upload_list:
1003             cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, "scp",
1004                 dir_path + '/' + source,
1005                 SNAPSHOT_SERVER + ':' + snapshot_path + '/' + destination]
1006             bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
1007
1008
1009 ###############################
1010 # handle_offline_installer_build
1011 ###############################
1012 def handle_offline_installer_build():
1013     handle_installer_build(True)
1014
1015
1016 ###############################
1017 # handle_online_installer_build
1018 ###############################
1019 def handle_online_installer_build():
1020     handle_installer_build(False)
1021
1022
1023 ###############################
1024 # save_latest_successful_installer
1025 ###############################
1026 def save_latest_successful_installer(offline_installer, installer_name, installer_name_final, ls_installer_dir, installer_output):
1027     # check installer type
1028     if offline_installer:
1029         regex = re.compile('.*offline')
1030     else:
1031         regex = re.compile('.*online')
1032     installer_base_name = "".join(regex.findall(installer_name_final))
1033     if not installer_base_name:
1034         print('*** Empty installer base name string')
1035     else:
1036         old_installer = ls_installer_dir + '/' + installer_base_name + '*'
1037         # delete old installer
1038         cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, 'rm', old_installer]
1039         bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, False)
1040         # save new installer to latest_successful directory
1041         cmd_args = [SCP_COMMAND, installer_name, PKG_SERVER_ADDR + ':' + ls_installer_dir + '/' + installer_name_final]
1042         bldinstallercommon.do_execute_sub_process(cmd_args, installer_output, True)
1043
1044
1045 ###############################
1046 # generic handle installer build
1047 ###############################
1048 def handle_installer_build(offline_installer_build):
1049     sanity_check_packaging_server()
1050     conf_file = os.environ['RELEASE_BUILD_CONF_FILE']
1051     if not os.path.exists(conf_file):
1052         print('*** The given file does not exist: {0}'.format(conf_file))
1053         sys.exit(-1)
1054     branch = 'release' # TODO
1055     platform = PLATFORM
1056     if TARGET_ENV.find('64') != -1:
1057         arch = 'x64'
1058     else:
1059         arch = 'x86'
1060     # Internal server address
1061     packages_base_url = os.environ['PKG_SERVER_URL']
1062     temp_path = ''
1063     # determine local installer output directory
1064     installer_output_dir = os.path.join(SCRIPT_ROOT_DIR, 'installer_output')
1065     # (1) create all installers for this host
1066     if offline_installer_build:
1067         release_build_handler.handle_offline_installer_build(conf_file, LICENSE, branch, platform, arch, packages_base_url)
1068         temp_path = '/offline_installers/'
1069     else:
1070         release_build_handler.handle_online_installer_build(conf_file, LICENSE, branch, platform, arch, packages_base_url)
1071         temp_path = '/online_installers/'
1072     # (2) copy all installers from 'installer_output_dir' into network disk
1073     # Create remote directories
1074     dest_dir = PATH + '/' + LICENSE + temp_path + TIME_STAMP[:10] + '_' + BUILD_NUMBER
1075     latest_dir = PATH + '/' + LICENSE + temp_path + 'latest'
1076     latest_successful_dir = PATH + '/' + LICENSE + temp_path + 'latest_successful'
1077     create_remote_dirs(PKG_SERVER_ADDR, dest_dir)
1078     create_remote_dirs(PKG_SERVER_ADDR, latest_successful_dir)
1079     # Create remote dirs in Mirror Brain
1080     if LICENSE == 'opensource':
1081         # Mirror Brain server address and path
1082         ext_server_base_url  = os.environ['EXT_SERVER_BASE_URL']
1083         ext_server_base_path = os.environ['EXT_SERVER_BASE_PATH']
1084         # mirror brain directories
1085         ext_dest_dir = ext_server_base_path + '/snapshots/qt/' + QT_VERSION[:3] + '/' + QT_FULL_VERSION + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER
1086         cmd_args_mkdir_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
1087         cmd_args_mkdir_ext = cmd_args_mkdir_pkg + ['ssh', ext_server_base_url, 'mkdir -p', ext_dest_dir]
1088         bldinstallercommon.do_execute_sub_process(cmd_args_mkdir_ext, SCRIPT_ROOT_DIR, True)
1089
1090     installer_name = ''
1091     installer_name_base = ''
1092     dir_list = os.listdir(installer_output_dir)
1093     if bldinstallercommon.is_linux_platform():
1094         for file_name in dir_list:
1095             if file_name.endswith(".run"):
1096                 installer_name = file_name
1097                 installer_name_base = os.path.splitext(file_name)[0]
1098                 installer_name_final = installer_name_base + '_' + TIME_STAMP + '-' + BUILD_NUMBER + '.run'
1099                 # copy installer to internal server
1100                 cmd_args = [SCP_COMMAND, installer_name, PKG_SERVER_ADDR + ':' + dest_dir + '/' + installer_name_final]
1101                 bldinstallercommon.do_execute_sub_process(cmd_args, installer_output_dir, True)
1102                 # remove old successful and save latest successful installer
1103                 save_latest_successful_installer(offline_installer_build, installer_name, installer_name_final, latest_successful_dir, installer_output_dir)
1104                 # copy installer to mirror brain server
1105                 if LICENSE == 'opensource':
1106                     cmd_args_copy_to_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
1107                     cmd_args_copy_to_ext = cmd_args_copy_to_pkg + ['scp', dest_dir + '/' + installer_name_final, ext_server_base_url + ':' + ext_dest_dir  + '/' + installer_name_final]
1108                     bldinstallercommon.do_execute_sub_process(cmd_args_copy_to_ext, installer_output_dir, True)
1109     elif bldinstallercommon.is_mac_platform():
1110         unlock_keychain()
1111         for file_name in dir_list:
1112             if file_name.endswith(".dmg"):
1113                 installer_name = file_name
1114                 installer_name_base = os.path.splitext(file_name)[0]
1115                 installer_name_final = installer_name_base + '_' + TIME_STAMP + '-' + BUILD_NUMBER + '.dmg'
1116                 # sign executable
1117                 sign_mac_executable(installer_name_base + '.app', installer_output_dir, True)
1118                 cmd_args = ['hdiutil', 'create', '-srcfolder', os.path.join(installer_output_dir, installer_name_base) + '.app', '-volname', installer_name_base, '-format', 'UDBZ', os.path.join(installer_output_dir, installer_name_base) + '.dmg', '-ov', '-scrub', '-size', '2g']
1119                 bldinstallercommon.do_execute_sub_process(cmd_args, installer_output_dir, True)
1120                 # copy installer to internal server
1121                 cmd_args = [SCP_COMMAND, installer_name, PKG_SERVER_ADDR + ':' + dest_dir + '/' + installer_name_final]
1122                 bldinstallercommon.do_execute_sub_process(cmd_args, installer_output_dir, True)
1123                 # remove old successful and save latest successful installer
1124                 save_latest_successful_installer(offline_installer_build, installer_name, installer_name_final, latest_successful_dir, installer_output_dir)
1125                 # copy installer to mirror brain server
1126                 if LICENSE == 'opensource':
1127                     cmd_args_copy_to_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
1128                     cmd_args_copy_to_ext = cmd_args_copy_to_pkg + ['scp', dest_dir + '/' + installer_name_final, ext_server_base_url + ':' + ext_dest_dir + '/' + installer_name_final]
1129                     bldinstallercommon.do_execute_sub_process(cmd_args_copy_to_ext, installer_output_dir, True)
1130         lock_keychain()
1131     else:
1132         for file_name in dir_list:
1133             if file_name.endswith(".exe"):
1134                 installer_name = file_name
1135                 installer_name_base = os.path.splitext(file_name)[0]
1136                 installer_name_final = installer_name_base + '_' + TIME_STAMP + '-' + BUILD_NUMBER + '.exe'
1137                 sign_windows_executable(installer_name, installer_output_dir, True)
1138                 # copy installer to internal server
1139                 cmd_args = [SCP_COMMAND, installer_name, PKG_SERVER_ADDR + ':' + dest_dir + '/' + installer_name_final]
1140                 bldinstallercommon.do_execute_sub_process(cmd_args, installer_output_dir, True)
1141                 # remove old successful and save latest successful installer
1142                 save_latest_successful_installer(offline_installer_build, installer_name, installer_name_final, latest_successful_dir, installer_output_dir)
1143                 # copy installer to mirror brain server
1144                 if LICENSE == 'opensource':
1145                     cmd_args_copy_to_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
1146                     cmd_args_copy_to_ext = cmd_args_copy_to_pkg + ['scp', dest_dir + '/' + installer_name_final, ext_server_base_url + ':' + ext_dest_dir + '/' + installer_name_final]
1147                     bldinstallercommon.do_execute_sub_process(cmd_args_copy_to_ext, installer_output_dir, True)
1148     #Update latest link
1149     cmd_args = [SSH_COMMAND, PKG_SERVER_ADDR, 'ln -sfn', dest_dir, latest_dir]
1150     bldinstallercommon.do_execute_sub_process(cmd_args, WORK_DIR, True)
1151     # copy rta description file(s)
1152     for file_name in dir_list:
1153         if file_name.endswith('.txt'):
1154             cmd_args = [SCP_COMMAND, file_name, PKG_SERVER_ADDR + ':' + dest_dir + '/' + file_name]
1155             bldinstallercommon.do_execute_sub_process(cmd_args, installer_output_dir, True)
1156     # (3) trigger rta cases
1157     trigger_rta(installer_output_dir)
1158
1159
1160 ###############################
1161 # Trigger RTA cases
1162 ###############################
1163 def trigger_rta(installer_output_dir):
1164     # obtain RTA server base url
1165     if not os.environ.get('RTA_SERVER_BASE_URL'):
1166         print('*** Error - RTA server base url is not defined. Unable to proceed!')
1167         sys.exit(-1)
1168     rta_server_base_url = os.environ['RTA_SERVER_BASE_URL']
1169     if not (rta_server_base_url.endswith('/')):
1170         rta_server_base_url += '/'
1171
1172     if not os.path.isdir(installer_output_dir):
1173         print('*** Error - Given installer_output_dir does not exist: {0}'.format(installer_output_dir))
1174         sys.exit(-1)
1175     dir_list = os.listdir(installer_output_dir)
1176     matching = [s for s in dir_list if 'rta_description_file' in s]
1177     # sanity check, should contain only one rta test case file
1178     if len(matching) != 1:
1179         print('*** Warning - Given installer_output_dir contained {0} rta description files?'.format(len(matching)))
1180         return
1181     rta_file = os.path.join(installer_output_dir, matching[0])
1182     f = open(rta_file)
1183     for line in iter(f):
1184         line_split = line.split(' ')
1185         if len(line_split) != 2:
1186             print('*** Error - Invalid format in rta description file {0}, line: {1}'.format(rta_file, line))
1187             sys.exit(-1)
1188         rta_keys = line_split[1].split(',')
1189         for item in rta_keys:
1190             url = rta_server_base_url + item.rstrip() + '/build?token=JENKINS_SQUISH'
1191             print('Triggering RTA case: {0}'.format(url))
1192             urllib.urlretrieve(url)
1193     f.close()
1194
1195
1196 #def handle_online_installer_build(license, ....):
1197
1198
1199 def handle_online_repository_build():
1200     conf_file = os.environ['RELEASE_BUILD_CONF_FILE']
1201     if not os.path.exists(conf_file):
1202         print('*** The given file does not exist: {0}'.format(conf_file))
1203         sys.exit(-1)
1204     if TARGET_ENV.find('64') != -1:
1205         arch = 'x64'
1206     else:
1207         arch = 'x86'
1208     packages_base_url = os.environ['PKG_SERVER_URL']
1209     # do we also update production repository?
1210     update_production_repo = False
1211     if os.environ.get('DO_UPDATE_PRODUCTION_REPOSITORY'):
1212         update = os.environ['DO_UPDATE_PRODUCTION_REPOSITORY']
1213         if update.lower() in ['yes', 'true', '1']:
1214             update_production_repo = True
1215     release_build_handler.handle_repo_build(conf_file, LICENSE, 'release', PLATFORM, arch, packages_base_url, update_production_repo)
1216
1217
1218 ###############################
1219 # copy_license_checkers
1220 ###############################
1221 def copy_license_checkers():
1222     sanity_check_packaging_server()
1223     exec_path = os.path.join(WORK_DIR, 'qt5', 'qtbase', 'bin')
1224     cmd_args = [SCP_COMMAND, PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'licheck', 'licheck.exe'), '.']
1225     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1226     cmd_args = [SCP_COMMAND, PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'licheck', 'licheck32'), '.']
1227     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1228     cmd_args = [SCP_COMMAND, PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'licheck', 'licheck64'), '.']
1229     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1230     cmd_args = [SCP_COMMAND, PKG_SERVER_ADDR + ':' + os.path.join(LATEST_DIR, 'src', 'licheck', 'licheck_mac'), '.']
1231     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1232     #change permissions
1233     os.chdir(os.path.join(WORK_DIR, 'qt5', 'qtbase', 'bin'))
1234     os.system('chmod u+x licheck32')
1235     os.system('chmod u+x licheck64')
1236     os.system('chmod u+x licheck_mac')
1237
1238     cmd_args = ['git', 'add', '.']
1239     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1240     cmd_args = ['git', 'commit', '-m', '"Add license checkers into enterprise source package"']
1241     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1242     exec_path = os.path.join(WORK_DIR, 'qt5')
1243     cmd_args = ['git', 'add', '.']
1244     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1245     cmd_args = ['git', 'commit', '-m', '"Add license checkers into enterprise source package"']
1246     bldinstallercommon.do_execute_sub_process(cmd_args, exec_path, True)
1247
1248     os.chdir(SCRIPT_ROOT_DIR)
1249
1250
1251 ###############################
1252 # publish_src_packages
1253 ###############################
1254 def publish_src_packages():
1255     # Mirror Brain server address and path
1256     ext_server_base_url  = os.environ['EXT_SERVER_BASE_URL']
1257     ext_server_base_path = os.environ['EXT_SERVER_BASE_PATH']
1258
1259     ext_dest_dir = ext_server_base_path + '/snapshots/qt/' + QT_VERSION[:3] + '/' + QT_FULL_VERSION + '/' + TIME_STAMP[:10] + '_' + BUILD_NUMBER
1260
1261     # copy source packages to public server
1262     if LICENSE == 'opensource':
1263         # create source directories
1264         cmd_args_mkdir_src_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
1265         cmd_args_mkdir_src_ext = cmd_args_mkdir_src_pkg + ['ssh', ext_server_base_url, 'mkdir', '-p', ext_dest_dir + '/' + 'single']
1266         bldinstallercommon.do_execute_sub_process(cmd_args_mkdir_src_ext, SCRIPT_ROOT_DIR, True)
1267         cmd_args_mkdir_src_ext = cmd_args_mkdir_src_pkg + ['ssh', ext_server_base_url, 'mkdir', '-p', ext_dest_dir + '/' + 'submodules']
1268         bldinstallercommon.do_execute_sub_process(cmd_args_mkdir_src_ext, SCRIPT_ROOT_DIR, True)
1269         # copy the source packages to the remove directory
1270         cmd_args_copy_src_to_pkg = [SSH_COMMAND, PKG_SERVER_ADDR]
1271         cmd_args_copy_src_to_ext = cmd_args_copy_src_to_pkg + ['scp', '-r', LATEST_DIR + '/' + 'src/single/*', ext_server_base_url + ':' + ext_dest_dir + '/' + 'single']
1272         bldinstallercommon.do_execute_sub_process(cmd_args_copy_src_to_ext, SCRIPT_ROOT_DIR, True)
1273         cmd_args_copy_src_to_ext = cmd_args_copy_src_to_pkg + ['scp', '-r', LATEST_DIR + '/' + 'src/submodules/*', ext_server_base_url + ':' + ext_dest_dir + '/' + 'submodules']
1274         bldinstallercommon.do_execute_sub_process(cmd_args_copy_src_to_ext, SCRIPT_ROOT_DIR, True)
1275
1276
1277 ###############################
1278 # create_remote_dirs
1279 ###############################
1280 def create_remote_dirs(server, dir_path):
1281     cmd_args = [SSH_COMMAND, '-t', '-t', server, 'mkdir -p', dir_path]
1282     bldinstallercommon.do_execute_sub_process(cmd_args, SCRIPT_ROOT_DIR, True)
1283
1284
1285 ###############################
1286 # parse_cmd_line
1287 ###############################
1288 def parse_cmd_line():
1289     global COMMAND
1290     global LICENSE
1291     global QT_VERSION
1292     global TIME_STAMP
1293     global BUILD_NUMBER
1294     global PKG_SERVER_ADDR
1295     global PATH
1296     global TARGET_ENV
1297     global ICU_LIBS
1298     global SRC_URL
1299     global REMOTE_DIR
1300     global LATEST_DIR
1301     global PLATFORM
1302     global QT_VERSION_TAG
1303     global QT_FULL_VERSION
1304     global QTCREATOR_VERSION
1305     global QTCREATOR_VERSION_DESCRIPTION
1306     global SNAPSHOT_SERVER
1307     global SNAPSHOT_PATH
1308
1309     setup_option_parser()
1310     arg_count = len(sys.argv)
1311     if arg_count < 2:
1312         OPTION_PARSER.print_help()
1313         sys.exit(-1)
1314
1315     (options, args) = OPTION_PARSER.parse_args()
1316     COMMAND = options.command
1317     bld_cmd_validator = BldCommand(options)
1318     if bld_cmd_validator.validate_bld_args():
1319         COMMAND           = options.command
1320         LICENSE           = options.license
1321         QT_VERSION        = options.qt_version
1322         TIME_STAMP        = options.time_stamp
1323         BUILD_NUMBER      = options.build_number
1324         PKG_SERVER_ADDR   = options.server
1325         PATH              = options.path
1326         SNAPSHOT_SERVER   = options.snapshot_server
1327         SNAPSHOT_PATH     = options.snapshot_path
1328         TARGET_ENV        = options.target_env
1329         ICU_LIBS          = options.icu_libs
1330         SRC_URL           = options.src_url
1331         QT_VERSION_TAG    = options.version_tag
1332         QTCREATOR_VERSION = options.qtcreator_version
1333         QT_FULL_VERSION   = QT_VERSION
1334         if QT_VERSION_TAG:
1335             QT_FULL_VERSION += '-' + QT_VERSION_TAG
1336         if options.qtcreator_set_description:
1337             QTCREATOR_VERSION_DESCRIPTION = QTCREATOR_VERSION
1338         else:
1339             QTCREATOR_VERSION_DESCRIPTION = ''
1340     else:
1341         OPTION_PARSER.print_help()
1342         sys.exit(-1)
1343     if not any(LICENSE in s for s in ['opensource', 'enterprise']):
1344         print('*** License unknown: {0}'.format(LICENSE))
1345         sys.exit(-1)
1346     if bldinstallercommon.is_linux_platform():
1347         PLATFORM = 'linux'
1348     elif bldinstallercommon.is_mac_platform():
1349         PLATFORM = 'mac'
1350     else:
1351         PLATFORM = 'windows'
1352
1353     # define LATEST directories
1354     REMOTE_DIR = PATH + '/' + LICENSE + '/'
1355     LATEST_DIR = PATH + '/' + LICENSE + '/'
1356
1357     if bld_cmd_validator.is_qt5_release_build() or bld_cmd_validator.is_enginio_build():
1358         REMOTE_DIR += 'qt' + '/' + QT_VERSION + '/' + TIME_STAMP + '-' + BUILD_NUMBER
1359         LATEST_DIR += 'qt' + '/' + QT_VERSION + '/' + 'latest'
1360     elif os.environ.get('APPLICATION_NAME'):
1361         REMOTE_DIR += os.environ['APPLICATION_NAME'] + '/' + os.environ['APPLICATION_VERSION'] + '/' + TIME_STAMP + '-' + BUILD_NUMBER
1362         LATEST_DIR += os.environ['APPLICATION_NAME'] + '/' + os.environ['APPLICATION_VERSION'] + '/' + 'latest'
1363
1364     return True
1365
1366
1367 ##############################################################
1368 # Setup Option Parser
1369 ##############################################################
1370 def setup_option_parser():
1371     global OPTION_PARSER
1372     OPTION_PARSER = OptionParser(option_class=MultipleOption)
1373
1374     OPTION_PARSER.add_option("-c", "--command",
1375                       action="store", type="string", dest="command", default="",
1376                       help="command to be executed: e.g. -c init")
1377     OPTION_PARSER.add_option("-l", "--license",
1378                       action="store", type="string", dest="license", default="",
1379                       help="license type: enterprise or opensource")
1380     OPTION_PARSER.add_option("-v", "--qt_version",
1381                       action="store", type="string", dest="qt_version", default="",
1382                       help="Qt version e.g. 5.0.2")
1383     OPTION_PARSER.add_option("-t", "--time_stamp",
1384                       action="store", type="string", dest="time_stamp", default="",
1385                       help="Jenkins build time stamp")
1386     OPTION_PARSER.add_option("-b", "--build_number",
1387                       action="store", type="string", dest="build_number", default="",
1388                       help="Jenkins build number")
1389     OPTION_PARSER.add_option("-s", "--server",
1390                       action="store", type="string", dest="server", default="",
1391                       help="Upload server e.g. <user>@<host>")
1392     OPTION_PARSER.add_option("-p", "--path",
1393                       action="store", type="string", dest="path", default="",
1394                       help="Path on server")
1395     OPTION_PARSER.add_option("-e", "--target_env",
1396                       action="store", type="string", dest="target_env", default="",
1397                       help="Target environment: Linux, Linux_64, mac, win")
1398     OPTION_PARSER.add_option("-i", "--icu_libs",
1399                       action="store", type="string", dest="icu_libs", default="",
1400                       help="Url for pre-compiled icu libraries")
1401     OPTION_PARSER.add_option("-u", "--src_url",
1402                       action="store", type="string", dest="src_url", default="",
1403                       help="Url for source code")
1404     OPTION_PARSER.add_option("--version-tag",
1405                       action="store", type="string", dest="version_tag", default="",
1406                       help="Version tag e.g. alpha, beta, rc1")
1407     OPTION_PARSER.add_option("--qtcreator-version",
1408                       action="store", type="string", dest="qtcreator_version", default="",
1409                       help="Qt Creator version, e.g. 3.0.0-rc, used in file names and for --qtcreator-set-description")
1410     OPTION_PARSER.add_option("--qtcreator-set-description",
1411                       action="store_true", dest="qtcreator_set_description", default=False,
1412                       help="Sets Qt Creator's version description to the value given in --qtcreator-version")
1413     OPTION_PARSER.add_option("--snapshot-server",
1414                       action="store", type="string", dest="snapshot_server", default="",
1415                       help="Additional snapshot upload server <user>@<host> (is uploaded from upload server)")
1416     OPTION_PARSER.add_option("--snapshot-path",
1417                       action="store", type="string", dest="snapshot_path", default="",
1418                       help="Path on additional snapshot upload server")
1419
1420
1421 ##############################################################
1422 # Initialize Environment
1423 ##############################################################
1424 def init_env():
1425     global MAKE_INSTALL_PADDING
1426     global CURL_COMMAND
1427     global RM_COMMAND
1428     global SSH_COMMAND
1429     global SCP_COMMAND
1430
1431     # prefix build
1432     MAKE_INSTALL_PADDING = 'PADDING' if bldinstallercommon.is_win_platform() else '______________________________PADDING______________________________'
1433     # external commands
1434     CURL_COMMAND         = '%CURL%'  if bldinstallercommon.is_win_platform() else 'curl'
1435     RM_COMMAND           = '%RM%'    if bldinstallercommon.is_win_platform() else 'rm'
1436     SSH_COMMAND          = '%SSH%'   if bldinstallercommon.is_win_platform() else 'ssh'
1437     SCP_COMMAND          = '%SCP%'   if bldinstallercommon.is_win_platform() else 'scp'
1438
1439 ###############################
1440 # Main
1441 ###############################
1442 def main():
1443     bldinstallercommon.init_common_module(SCRIPT_ROOT_DIR)
1444
1445     init_env()
1446
1447     parse_cmd_line()
1448     if COMMAND == BldCommand.init_build_cycle:
1449         init_qt_build_cycle()
1450     elif COMMAND == BldCommand.execute_qt5_src_pkg:
1451         if LICENSE == 'opensource':
1452             init_qt_build_cycle()
1453         handle_qt_src_package_build()
1454     elif COMMAND == BldCommand.execute_qt5_bin_bld:
1455         handle_qt_release_build()
1456     elif COMMAND == BldCommand.execute_qt5_app_bld:
1457         handle_qt5_application_release_build()
1458     elif COMMAND == BldCommand.execute_ifw_bld:
1459         handle_ifw_build()
1460     elif COMMAND == BldCommand.execute_creator_bld:
1461         handle_qt_creator_build()
1462     elif COMMAND == BldCommand.execute_repo_bld:
1463         handle_online_repository_build()
1464     elif COMMAND == BldCommand.execute_offline_inst_bld:
1465         handle_offline_installer_build()
1466     elif COMMAND == BldCommand.execute_online_inst_bld:
1467         handle_online_installer_build()
1468     elif COMMAND == BldCommand.publish_qt5_src_pkg:
1469         publish_src_packages()
1470     else:
1471         print('Unsupported command')
1472
1473 if __name__ == "__main__":
1474     main()
1475