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
|
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
from __future__ import annotations
import calendar
import datetime
import os
import site
import sys
from pathlib import Path
from build_scripts.options import Options
from build_scripts.utils import (parse_cmake_conf_assignments_by_key,
remove_tree, run_instruction)
options = Options()
class CI:
def __init__(self):
# Values must match COIN thrift
self.HOST_OS = options.option_value("os")
self.TARGET_OS = options.option_value("targetOs")
self.HOST_ARCH = options.option_value("hostArch")
self.TARGET_ARCH = options.option_value("targetArch")
self.HOST_OS_VER = options.option_value("osVer")
self.ENV_INSTALL_DIR = options.option_value("instdir")
self.ENV_AGENT_DIR = options.option_value("agentdir") or "."
self.COMPILER = options.option_value("compiler")
self.USE_SCCACHE = options.option_value("compiler-launcher")
self.INTEGRATION_ID = options.option_value("coinIntegrationId") or str(
calendar.timegm(datetime.datetime.now().timetuple())
)
self.FEATURES = []
_ci_features = options.option_value("features")
if _ci_features is not None:
for f in _ci_features.split(", "):
self.FEATURES.append(f)
self.RELEASE_CONF = options.has_option("packaging")
self.TEST_PHASE = options.option_value("phase")
if self.TEST_PHASE not in ["ALL", "BUILD"]:
self.TEST_PHASE = "ALL"
def get_ci_exe_path(ci_install_dir, ci_host_os, qtexe):
"""
qtexe can only be 'qmake' or 'qtpaths'
"""
ext = ""
if ci_host_os == "Windows":
ext = ".exe"
_path = Path(ci_install_dir) / "bin" / f"{qtexe}{ext}"
return f"--{qtexe}={_path}"
def get_env_or_raise(name: str) -> str:
o = os.getenv(name)
if o is None:
raise Exception(f"Variable not defined: {name}")
return o
def get_qtci_virtualenv(python_ver, log, host, host_arch, target_arch):
_exe = "python"
_env = os.environ.get("PYSIDE_VIRTUALENV") or f"env{python_ver}"
env_python = f"{_env}/bin/python"
env_pip = f"{_env}/bin/pip"
if host == "Windows":
log.info("New virtualenv to build {target_arch} in {host_arch} host")
_exe = "python.exe"
if python_ver.startswith("3"):
var = f"PYTHON{python_ver}-64_PATH"
log.info(f"Try to find python from {var} env variable")
_path = Path(os.getenv(var, ""))
_exe = _path / "python.exe"
if not _exe.is_file():
log.warning(f"Can't find python.exe from {_exe}, using default python3")
_exe = Path(get_env_or_raise("PYTHON3_PATH")) / "python.exe"
env_python = rf"{_env}\Scripts\python.exe"
env_pip = rf"{_env}\Scripts\pip.exe"
else:
_exe = f"python{python_ver}"
try:
run_instruction([_exe, "--version"], f"Failed to guess python version {_exe}")
except Exception as e:
print(f"Exception {type(e).__name__}: {e}")
_exe = "python3"
return (_exe, _env, env_pip, env_python)
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 = Path(this_file).resolve()
return this_file.parents[0]
def is_snapshot_build():
"""
Returns True if project needs to be built with --snapshot-build
This is true if the version found in .cmake.conf 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).
"""
# This returns pyside-setup/coin/ so we go one level down
# to get the root of the repo
setup_script_dir = get_current_script_path()
pyside_project_dir = setup_script_dir / ".." / "sources" / "pyside6"
d = parse_cmake_conf_assignments_by_key(str(pyside_project_dir))
release_version_type = d.get("pyside_PRE_RELEASE_VERSION_TYPE")
pre_release_version = d.get("pyside_PRE_RELEASE_VERSION")
if pre_release_version and release_version_type:
return True
return False
def get_architecture(ci):
return "32" if ci.TARGET_ARCH == "X86" else "64"
def get_python_version(ci):
python_ver = "3"
if ci.TARGET_OS == "Linux" and ci.HOST_ARCH != "aarch64":
python_ver = "3.11"
elif ci.TARGET_OS == "Windows":
python_ver = "3.10.0"
return python_ver
def remove_variables(vars):
for env_var in vars:
if os.environ.get(env_var):
del os.environ[env_var]
def setup_virtualenv(python, exe, env, pip, log, ci):
# Within Ubuntu 24.04 one can't install anything with pip to outside of
# virtual env. Trust that we already have proper virtualenv installed.
if os.environ.get("HOST_OSVERSION_COIN") != "ubuntu_24_04":
run_instruction(
[str(python), "-m", "pip", "install", "--user", "virtualenv==20.7.2"],
"Failed to pin virtualenv",
)
# installing to user base might not be in PATH by default.
env_path = Path(str(site.USER_BASE)) / "bin"
v_env = env_path / "virtualenv"
if sys.platform == "win32":
if ci.TARGET_ARCH == "aarch64":
env_path = os.path.join(site.USER_BASE, "Python311-arm64", "Scripts")
else:
env_path = os.path.join(site.USER_BASE, "Scripts")
v_env = os.path.join(env_path, "virtualenv.exe")
try:
run_instruction([str(v_env), "--version"], "Using default virtualenv")
except Exception as e:
log.info("Failed to use the default virtualenv")
log.info(f"{type(e).__name__}: {e}")
v_env = "virtualenv"
run_instruction([str(v_env), "-p", str(exe), str(env)], "Failed to create virtualenv")
# Pip is always upgraded when CI template is provisioned,
# upgrading it in later phase may cause perm issue
run_instruction(
[str(pip), "install", "-r", "requirements.txt"], "Failed to install dependencies"
)
def call_setup(python_ver, ci, phase, log, buildnro=0):
print("call_setup")
print("python_ver", python_ver)
print("phase", phase)
exe, env, pip, env_python = get_qtci_virtualenv(
python_ver, log, ci.HOST_OS, ci.HOST_ARCH, ci.TARGET_ARCH
)
if phase not in ["BUILD", "TEST"]:
sys.exit(1)
remove_tree(env, True)
# Pinning the virtualenv before creating one
# Use pip3 if possible while pip seems to install the virtualenv to wrong dir in some OS
python = "python3"
if sys.platform == "win32":
python = Path(get_env_or_raise("PYTHON3_PATH")) / "python.exe"
if phase == "BUILD":
setup_virtualenv(python, exe, env, pip, log, ci)
elif phase == "TEST":
if ci.HOST_OS == "MacOS" and ci.HOST_ARCH == "ARM64":
v_env = "virtualenv"
run_instruction([str(v_env), "-p", str(exe), str(env)], "Failed to create virtualenv")
run_instruction(
[pip, "install", "-r", "requirements.txt"], "Failed to install dependencies"
)
else:
setup_virtualenv(python, exe, env, pip, log, ci)
# Install distro to replace missing platform.linux_distribution() in python3.8
run_instruction([pip, "install", "distro"], "Failed to install distro")
if phase == "BUILD":
cmd = [
env_python,
"-u",
"setup.py",
"build",
"--standalone",
"--unity",
"--build-tests",
"--log-level=verbose",
"--limited-api=yes",
]
if ci.TARGET_ARCH == "X86_64-ARM64":
cmd += ["--macos-arch='x86_64;arm64'"]
if ci.USE_SCCACHE:
cmd += [f"--compiler-launcher={ci.USE_SCCACHE}"]
if is_snapshot_build():
cmd += ["--snapshot-build"]
qtpaths_path = get_ci_exe_path(ci.ENV_INSTALL_DIR, ci.HOST_OS, "qtpaths")
cmd.append(qtpaths_path)
# Due to certain older CMake versions generating very long paths
# (at least with CMake 3.6.2) when using the export() function,
# pass the shorter paths option on Windows so we don't hit
# the path character length limit (260).
if ci.HOST_OS == "Windows":
cmd += ["--shorter-paths"]
cmd += ["--package-timestamp=" + ci.INTEGRATION_ID]
env = os.environ
run_instruction(cmd, "Failed to run setup.py for build", initial_env=env)
elif phase == "TEST":
cmd = [
env_python,
"testrunner.py",
"test",
"--blacklist",
"build_history/blacklist.txt",
f"--buildno={buildnro}",
]
run_instruction(cmd, "Failed to run testrunner.py")
qmake_path = get_ci_exe_path(ci.ENV_INSTALL_DIR, ci.HOST_OS, "qmake")
# Try to install built wheels, and build some buildable examples.
if ci.RELEASE_CONF:
wheel_tester_path = os.path.join("testing", "wheel_tester.py")
# Run the test for the new set of wheels
cmd = [env_python, wheel_tester_path, qmake_path, "--wheels-dir=dist", "--new"]
run_instruction(cmd, "Error while running wheel_tester.py on new wheels")
|