Skip to content

Commit cac4b04

Browse files
authored
Fix disk space issues in Android CI (#142289)
1 parent 4238a97 commit cac4b04

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

Android/android.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ANDROID_DIR.name == "Android" and (PYTHON_DIR / "pyconfig.h.in").exists()
3030
)
3131

32+
ENV_SCRIPT = ANDROID_DIR / "android-env.sh"
3233
TESTBED_DIR = ANDROID_DIR / "testbed"
3334
CROSS_BUILD_DIR = PYTHON_DIR / "cross-build"
3435

@@ -129,12 +130,11 @@ def android_env(host):
129130
sysconfig_filename = next(sysconfig_files).name
130131
host = re.fullmatch(r"_sysconfigdata__android_(.+).py", sysconfig_filename)[1]
131132

132-
env_script = ANDROID_DIR / "android-env.sh"
133133
env_output = subprocess.run(
134134
f"set -eu; "
135135
f"HOST={host}; "
136136
f"PREFIX={prefix}; "
137-
f". {env_script}; "
137+
f". {ENV_SCRIPT}; "
138138
f"export",
139139
check=True, shell=True, capture_output=True, encoding='utf-8',
140140
).stdout
@@ -151,7 +151,7 @@ def android_env(host):
151151
env[key] = value
152152

153153
if not env:
154-
raise ValueError(f"Found no variables in {env_script.name} output:\n"
154+
raise ValueError(f"Found no variables in {ENV_SCRIPT.name} output:\n"
155155
+ env_output)
156156
return env
157157

@@ -281,15 +281,30 @@ def clean_all(context):
281281

282282

283283
def setup_ci():
284-
# https://github.blog/changelog/2024-04-02-github-actions-hardware-accelerated-android-virtualization-now-available/
285-
if "GITHUB_ACTIONS" in os.environ and platform.system() == "Linux":
286-
run(
287-
["sudo", "tee", "/etc/udev/rules.d/99-kvm4all.rules"],
288-
input='KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"\n',
289-
text=True,
290-
)
291-
run(["sudo", "udevadm", "control", "--reload-rules"])
292-
run(["sudo", "udevadm", "trigger", "--name-match=kvm"])
284+
if "GITHUB_ACTIONS" in os.environ:
285+
# Enable emulator hardware acceleration
286+
# (https://github.blog/changelog/2024-04-02-github-actions-hardware-accelerated-android-virtualization-now-available/).
287+
if platform.system() == "Linux":
288+
run(
289+
["sudo", "tee", "/etc/udev/rules.d/99-kvm4all.rules"],
290+
input='KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"\n',
291+
text=True,
292+
)
293+
run(["sudo", "udevadm", "control", "--reload-rules"])
294+
run(["sudo", "udevadm", "trigger", "--name-match=kvm"])
295+
296+
# Free up disk space by deleting unused versions of the NDK
297+
# (https://github.com/freakboy3742/pyspamsum/pull/108).
298+
for line in ENV_SCRIPT.read_text().splitlines():
299+
if match := re.fullmatch(r"ndk_version=(.+)", line):
300+
ndk_version = match[1]
301+
break
302+
else:
303+
raise ValueError(f"Failed to find NDK version in {ENV_SCRIPT.name}")
304+
305+
for item in (android_home / "ndk").iterdir():
306+
if item.name[0].isdigit() and item.name != ndk_version:
307+
delete_glob(item)
293308

294309

295310
def setup_sdk():

Android/testbed/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ android {
7979
val androidEnvFile = file("../../android-env.sh").absoluteFile
8080

8181
namespace = "org.python.testbed"
82-
compileSdk = 34
82+
compileSdk = 35
8383

8484
defaultConfig {
8585
applicationId = "org.python.testbed"
@@ -92,7 +92,7 @@ android {
9292
}
9393
throw GradleException("Failed to find API level in $androidEnvFile")
9494
}
95-
targetSdk = 34
95+
targetSdk = 35
9696

9797
versionCode = 1
9898
versionName = "1.0"

0 commit comments

Comments
 (0)