aboutsummaryrefslogtreecommitdiffstats
path: root/coin_build_instructions.py
blob: 1104e996c573d9f1dad3e7c82b55d3a4370fd8ba (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
#############################################################################
##
## Copyright (C) 2018 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
##
## $QT_BEGIN_LICENSE:LGPL$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 3 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL3 included in the
## packaging of this file. Please review the following information to
## ensure the GNU Lesser General Public License version 3 requirements
## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 2.0 or (at your option) the GNU General
## Public license version 3 or any later version approved by the KDE Free
## Qt Foundation. The licenses are as published by the Free Software
## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-2.0.html and
## https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################
from build_scripts.options import has_option
from build_scripts.options import option_value
from build_scripts.utils import install_pip_dependencies
from build_scripts.utils import install_pip_wheel_package
from build_scripts.utils import get_qtci_virtualEnv
from build_scripts.utils import run_instruction
from build_scripts.utils import rmtree
from build_scripts.utils import get_python_dict
from build_scripts.utils import acceptCITestConfiguration
from build_scripts.utils import get_ci_qmake_path
import os

# Values must match COIN thrift
CI_HOST_OS = option_value("os")
CI_TARGET_OS = option_value("targetOs")
CI_HOST_ARCH = option_value("hostArch")
CI_TARGET_ARCH = option_value("targetArch")
CI_HOST_OS_VER = option_value("osVer")
CI_ENV_INSTALL_DIR = option_value("instdir")
CI_ENV_AGENT_DIR = option_value("agentdir")
CI_COMPILER = option_value("compiler")
CI_INTEGRATION_ID = option_value("coinIntegrationId")
CI_FEATURES = []
_ci_features = option_value("features")
if _ci_features is not None:
    for f in _ci_features.split(', '):
        CI_FEATURES.append(f)
CI_RELEASE_CONF = has_option("packaging")

def get_current_script_path():
    """ Returns the absolute path containing this script. """
    try:
        this_file = __file__
    except NameError:
        this_file = sys.argv[0]
    this_file = os.path.abspath(this_file)
    return os.path.dirname(this_file)

def is_snapshot_build():
    """
    Returns True if project needs to be built with --snapshot-build

    This is true if the version found in pyside_version.py is not a
    pre-release version (no alphas, betas).

    This eliminates the need to remove the --snapshot-build option
    on a per-release branch basis (less things to remember to do
    for a release).
    """
    setup_script_dir = get_current_script_path()
    pyside_version_py = os.path.join(
        setup_script_dir, "sources", "pyside2", "pyside_version.py")
    d = get_python_dict(pyside_version_py)

    pre_release_version_type = d['pre_release_version_type']
    pre_release_version = d['pre_release_version']
    if pre_release_version or pre_release_version_type:
        return True
    return False

def call_setup(python_ver):
    _pExe, _env, env_pip, env_python = get_qtci_virtualEnv(python_ver, CI_HOST_OS, CI_HOST_ARCH, CI_TARGET_ARCH)
    rmtree(_env, True)
    run_instruction(["virtualenv", "-p", _pExe,  _env], "Failed to create virtualenv")

    install_pip_dependencies(env_pip, ["six", "setuptools"])
    install_pip_wheel_package(env_pip)

    cmd = [env_python, "-u", "setup.py"]
    if CI_RELEASE_CONF:
        cmd += ["bdist_wheel", "--standalone"]
    else:
        cmd += ["build"]
    qmake_path = get_ci_qmake_path(CI_ENV_INSTALL_DIR, CI_HOST_OS)
    cmd.append(qmake_path)
    cmd += ["--build-tests",
            "--jobs=4",
            "--verbose-build"]
    if python_ver == "3":
        cmd += ["--limited-api=yes"]
    if is_snapshot_build():
        cmd += ["--snapshot-build"]

    cmd += ["--package-timestamp=" + CI_INTEGRATION_ID]

    env = os.environ
    if CI_HOST_OS == "MacOS":
        # On Python 3, setuptools.dist.handle_display_options does some
        # weird sys.stdout.detach-ing if the stdout encoding is
        # different from utf-8. This causes issues when running
        # subprocess.call() because that access the original stdout
        # object stored in sys.__stdout__ which was detached, and
        # results in an exception being thrown.
        # The Coin macOS locale by default is US-ASCII, and that
        # triggers the above issue. Set the encoding to UTF-8 which
        # makes sure to skip over the detach-ing code.
        # Relevant links to the issue:
        # https://bugs.python.org/issue15216
        # https://bitbucket.org/tarek/distribute/issues/334/fix-for-311-breaks-packages-that-use
        # https://github.com/pypa/virtualenv/issues/359
        env['LC_CTYPE'] = 'UTF-8'
    run_instruction(cmd, "Failed to run setup.py", initial_env=env)

def run_build_instructions():
    if not acceptCITestConfiguration(CI_HOST_OS, CI_HOST_OS_VER, CI_TARGET_ARCH, CI_COMPILER):
        exit()

    if CI_HOST_ARCH == "X86_64" and CI_TARGET_ARCH == "X86":
        print("Disabled 32 bit build on 64 bit from Coin configuration, until toolchains provisioned")
        exit()

    # Uses default python, hopefully we have python2 installed on all hosts
    # Skip building using Python 2 on Windows, because of different MSVC C runtimes (VS2008 vs VS2015+)
    if CI_HOST_OS != "Windows":
        call_setup("")

    # In case of packaging build, we have to build also python3 wheel
    if CI_RELEASE_CONF and CI_HOST_OS_VER not in ["RHEL_6_6"]:
        call_setup("3")

if __name__ == "__main__":
    run_build_instructions()