-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_qt6_source_bundle.py
164 lines (139 loc) · 5.64 KB
/
create_qt6_source_bundle.py
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
#!/usr/bin/env python3
import sys
import os
import subprocess
import shutil
import glob
import zipfile
import argparse
import platform
from math import ceil
from pathlib import Path
from target_qt6_version import qt_version, qt_modules
parser = argparse.ArgumentParser(description = "Create bundle for Qt 6 source code")
parser.add_argument("--skip-clone", help="skip cloning the Qt 6 source code", action="store_true")
parser.add_argument("--skip-clean", help="skip removing the Qt 6 source code", action="store_true")
parser.add_argument("--mirror", help="use source mirror", action="store")
args = parser.parse_args()
base_dir = Path(__file__).resolve().parent
qt_dir = base_dir / "build"
source_path = qt_dir / "src"
qt_source_path = source_path / f"qt{qt_version}"
artifact_path = base_dir / "artifacts"
qt_patches_path = base_dir / 'qt_patches'
pyside_patches_path = base_dir / 'pyside_patches'
pyside_source_path = source_path / f"pyside{qt_version}"
qt_patches = []
for patch in sorted(qt_patches_path.iterdir()):
if patch.suffix == '.patch':
resolved_path = patch.resolve()
qt_patches.append(patch.resolve())
pyside_patches = []
for patch in sorted(pyside_patches_path.iterdir()):
if patch.suffix == '.patch':
resolved_path = patch.resolve()
pyside_patches.append(patch.resolve())
mirror = []
if args.mirror:
print(f"Using source mirror: {args.mirror}")
mirror = ["--mirror", args.mirror]
if sys.version_info.major < 3:
print('Please use Python 3')
sys.exit(1)
if sys.platform == 'win32':
print('Please use Linux or Mac')
sys.exit(1)
if not os.path.exists(artifact_path):
os.mkdir(artifact_path)
if os.path.exists(source_path):
shutil.rmtree(source_path)
os.mkdir(source_path)
os.mkdir(qt_source_path)
print("\nActive Qt version is " + qt_version)
for patch in qt_patches:
print(f"Apply Qt patch: {patch}")
for patch in pyside_patches:
print(f"Apply PySide patch: {patch}")
if input("\nIs this correct (y/n)? ") != "y":
print("Aborted")
sys.exit(1)
if not args.skip_clone:
print("\nCloning Qt...")
if args.mirror:
if subprocess.call(["git", "clone", f"{args.mirror}qt5.git", qt_source_path]) != 0:
print("Failed to clone Qt git repository")
sys.exit(1)
else:
if subprocess.call(["git", "clone", "https://codereview.qt-project.org/qt/qt5.git", qt_source_path]) != 0:
print("Failed to clone Qt git repository")
sys.exit(1)
if subprocess.call(["git", "checkout", f"v{qt_version}"], cwd=qt_source_path) != 0:
print("Failed to check out branch '{}'".format(qt_version))
sys.exit(1)
if subprocess.call(["./init-repository", "--module-subset=" + ",".join(qt_modules), "--no-update"] + mirror, cwd=qt_source_path) != 0:
print("Failed to initialize submodules")
sys.exit(1)
# Check out submodules, but don't check out recursively until we've had a chance to patch
# module paths
if subprocess.call(["git", "submodule", "update", "--init"] + qt_modules, cwd=qt_source_path) != 0:
print("Failed to check out submodules")
sys.exit(1)
if args.mirror:
# Fix qttools .gitmodules to use mirror
open(os.path.join(qt_source_path, "qttools", ".gitmodules"), 'w').write(
'[submodule "src/assistant/qlitehtml"]\n' +
' path = src/assistant/qlitehtml\n' +
f' url = {args.mirror}qlitehtml.git'
)
# Check out all submodules
if subprocess.call(["git", "submodule", "update", "--init", "--recursive"] + qt_modules, cwd=qt_source_path) != 0:
print("Failed to check out submodules")
sys.exit(1)
qt_patch_contents = ""
for patch in qt_patches:
print(f"\nApplying patch {patch}...")
if subprocess.call(["git", "apply", os.path.abspath(patch)], cwd=qt_source_path) != 0:
print("Failed to patch source")
sys.exit(1)
qt_patch_contents += open(patch).read()
print("\nCloning pyside-setup...")
if args.mirror:
if subprocess.call(["git", "clone", f"{args.mirror}pyside-setup", pyside_source_path]) != 0:
print("Failed to clone PySide git repository")
sys.exit(1)
else:
if subprocess.call(["git", "clone", "https://codereview.qt-project.org/pyside/pyside-setup", pyside_source_path]) != 0:
print("Failed to clone PySide git repository")
sys.exit(1)
if subprocess.call(["git", "checkout", qt_version], cwd=pyside_source_path) != 0:
print("Failed to check out branch '{}'".format(qt_version))
sys.exit(1)
pyside_patch_contents = ""
for patch in pyside_patches:
print(f"\nApplying patch {patch}...")
if subprocess.call(["patch", "-p1", "-i", os.path.abspath(patch)], cwd=pyside_source_path) != 0:
print("Failed to patch source")
sys.exit(1)
pyside_patch_contents += open(patch).read()
open(os.path.join(artifact_path, f"qt{qt_version}.patch"), 'w').write(qt_patch_contents)
open(os.path.join(artifact_path, f"pyside{qt_version}.patch"), 'w').write(pyside_patch_contents)
print("Removing .git directories...")
if subprocess.call("find . -name .git | xargs rm -rf", shell=True, cwd=qt_source_path) != 0:
print("Failed to remove .git directories")
sys.exit(1)
if subprocess.call("find . -name .gitmodules | xargs rm -rf", shell=True, cwd=qt_source_path) != 0:
print("Failed to remove .gitmodules")
sys.exit(1)
if subprocess.call("find . -name .git | xargs rm -rf", shell=True, cwd=pyside_source_path) != 0:
print("Failed to remove .git directories")
sys.exit(1)
if subprocess.call("find . -name .gitmodules | xargs rm -rf", shell=True, cwd=pyside_source_path) != 0:
print("Failed to remove .gitmodules")
sys.exit(1)
print("Compressing...")
if subprocess.call(["tar", "cJf", os.path.join(artifact_path, f"qt{qt_version}.tar.xz"), f"qt{qt_version}", f"pyside{qt_version}"], cwd=source_path) != 0:
print("Failed to compress source")
sys.exit(1)
if not args.skip_clean:
print("Cleaning up...")
shutil.rmtree(source_path)