forked from beeware/mobile-forge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_dep_wheels.py
151 lines (130 loc) · 4.54 KB
/
make_dep_wheels.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
"""make_dep_wheels.py.
A utility script for converting the "installed" versions of dependencies into wheels
that can be referenced during forge builds.
You should not need to invoke this script directly; it should be called by `./setup-
iOS.sh` when creating a new forge environment.
"""
import os
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
def make_wheel(package, os_name, target):
"""Create a target-specific wheel for a given package.
Requires that PYTHON_APPLE_SUPPORT is set in the environment, and that variable
points to a completed support build.
:param package: The name of the package to build (e.g., "BZip2")
:param os_name: The OS name to target (e.g., "iOS")
:param target: The target specifier (e.g., "iphoneos.arm64")
"""
support = Path(os.environ["PYTHON_ANDROID_SUPPORT" if os_name == "android" else "PYTHON_APPLE_SUPPORT"])
versions_file = (
support
/ "support"
/ ".".join(sys.version.split(".")[:2])
/ os_name
/ "VERSIONS"
)
with versions_file.open(encoding="utf-8") as f:
versions = f.read()
package_version_build = re.search(rf"^{package}: (.*)", versions, re.MULTILINE)[1]
min_version = re.search(rf"^Min {os_name} version: (.*)", versions, re.MULTILINE)[1]
package_version, package_build = package_version_build.split("-")
target_parts = target.split(".")
target_parts.reverse()
wheel_target = "_".join(target_parts)
wheel_tag = f"py3-none-{os_name}_{min_version}_{wheel_target.replace('-', '_')}".lower().replace(".", "_")
wheel_file = (
Path("dist") / f"{package.lower()}-{package_version_build}-{wheel_tag}.whl"
)
if wheel_file.exists():
print(f"{wheel_file} already exists")
return
install_path = (
support
/ "install"
/ os_name
/ target
/ f"{package.lower()}-{package_version_build}"
)
if not install_path.exists():
print(
f"Cannot build {target} wheel for {package}; can't find installed version in {install_path}"
)
sys.exit(1)
with tempfile.TemporaryDirectory(dir=".") as tmp:
wheel_path = Path(tmp)
distinfo_path = wheel_path / f"{package.lower()}-{package_version}.dist-info"
distinfo_path.mkdir()
# Copy the installed content.
# TODO: Enable ignore_dangling_symlinks because of https://github.com/beeware/cpython-android-source-deps/issues/2
shutil.copytree(install_path, wheel_path / "opt", ignore_dangling_symlinks=True)
# Write package metadata
with (distinfo_path / "METADATA").open("w", encoding="utf-8") as f:
f.write(
"\n".join(
[
"Metadata-Version: 1.2",
f"Name: {package.lower()}",
f"Version: {package_version}",
"Summary: ",
"Download-URL: ",
]
)
)
# Write wheel metadata
with (distinfo_path / "WHEEL").open("w", encoding="utf-8") as f:
f.write(
"\n".join(
[
"Wheel-Version: 1.0",
"Root-Is-Purelib: false",
"Generator: Mobile-Forge.BeeWare",
f"Build: {package_build}",
f"Tag: {wheel_tag}",
]
)
)
# Ensure the dist folder exists
Path("dist").mkdir(exist_ok=True)
# Pack the wheel
subprocess.run(
[
sys.executable,
"-m",
"wheel",
"pack",
"--dest-dir",
"dist",
wheel_path,
]
)
if __name__ == "__main__":
os_name = sys.argv[1]
for target in {
"android": [
"arm64-v8a",
"armeabi-v7a",
"x86_64",
"x86"
],
"iOS": [
"iphoneos.arm64",
"iphonesimulator.arm64",
"iphonesimulator.x86_64",
],
"tvOS": [
"appletvos.arm64",
"appletvsimulator.arm64",
"appletvsimulator.x86_64",
],
"watchOS": [
"watchos.arm64_32",
"watchsimulator.arm64",
"watchsimulator.x86_64",
],
}[os_name]:
for dep in ["BZip2", "XZ", "libFFI", "OpenSSL"]:
make_wheel(dep, os_name, target)