Skip to content

Commit 24bee4e

Browse files
authored
[3.13] Backport miscellaneous Android testbed changes (#131985)
Backport miscellaneous Android testbed changes from #125946, but without the Android API version bump.
1 parent c318a03 commit 24bee4e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Android/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ stderr. Add the `-v` option to also show Gradle output, and non-Python logcat
143143
messages.
144144

145145
Any other arguments on the `android.py test` command line will be passed through
146-
to `python -m test` use `--` to separate them from android.py's own options.
146+
to `python -m test` use `--` to separate them from android.py's own options.
147147
See the [Python Developer's
148148
Guide](https://devguide.python.org/testing/run-write-tests/) for common options
149-
 most of them will work on Android, except for those that involve subprocesses,
149+
most of them will work on Android, except for those that involve subprocesses,
150150
such as `-j`.
151151

152152
Every time you run `android.py test`, changes in pure-Python files in the

Android/testbed/app/build.gradle.kts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,24 @@ for ((i, prefix) in prefixes.withIndex()) {
7575

7676

7777
android {
78+
val androidEnvFile = file("../../android-env.sh").absoluteFile
79+
7880
namespace = "org.python.testbed"
7981
compileSdk = 34
8082

8183
defaultConfig {
8284
applicationId = "org.python.testbed"
83-
minSdk = 21
85+
86+
minSdk = androidEnvFile.useLines {
87+
for (line in it) {
88+
"""api_level:=(\d+)""".toRegex().find(line)?.let {
89+
return@useLines it.groupValues[1].toInt()
90+
}
91+
}
92+
throw GradleException("Failed to find API level in $androidEnvFile")
93+
}
8494
targetSdk = 34
95+
8596
versionCode = 1
8697
versionName = "1.0"
8798

@@ -101,7 +112,6 @@ android {
101112
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
102113
}
103114

104-
val androidEnvFile = file("../../android-env.sh").absoluteFile
105115
ndkVersion = androidEnvFile.useLines {
106116
for (line in it) {
107117
"""ndk_version=(\S+)""".toRegex().find(line)?.let {

Android/testbed/app/src/main/c/main_activity.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ typedef struct {
3434
int pipe[2];
3535
} StreamInfo;
3636

37+
// The FILE member can't be initialized here because stdout and stderr are not
38+
// compile-time constants. Instead, it's initialized immediately before the
39+
// redirection.
3740
static StreamInfo STREAMS[] = {
38-
{stdout, STDOUT_FILENO, ANDROID_LOG_INFO, "native.stdout", {-1, -1}},
39-
{stderr, STDERR_FILENO, ANDROID_LOG_WARN, "native.stderr", {-1, -1}},
41+
{NULL, STDOUT_FILENO, ANDROID_LOG_INFO, "native.stdout", {-1, -1}},
42+
{NULL, STDERR_FILENO, ANDROID_LOG_WARN, "native.stderr", {-1, -1}},
4043
{NULL, -1, ANDROID_LOG_UNKNOWN, NULL, {-1, -1}},
4144
};
4245

@@ -87,6 +90,8 @@ static char *redirect_stream(StreamInfo *si) {
8790
JNIEXPORT void JNICALL Java_org_python_testbed_PythonTestRunner_redirectStdioToLogcat(
8891
JNIEnv *env, jobject obj
8992
) {
93+
STREAMS[0].file = stdout;
94+
STREAMS[1].file = stderr;
9095
for (StreamInfo *si = STREAMS; si->file; si++) {
9196
char *error_prefix;
9297
if ((error_prefix = redirect_stream(si))) {

0 commit comments

Comments
 (0)