]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] Backport miscellaneous Android testbed changes (#131985)
authorMalcolm Smith <smith@chaquo.com>
Wed, 2 Apr 2025 00:11:57 +0000 (01:11 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Apr 2025 00:11:57 +0000 (08:11 +0800)
Backport miscellaneous Android testbed changes from #125946, but without the
Android API version bump.

Android/README.md
Android/testbed/app/build.gradle.kts
Android/testbed/app/src/main/c/main_activity.c

index 2c55d94a07b6192dff55d47fb557ae02793822b6..789bcbe5edff4428ac5fc249158efaac45b99c32 100644 (file)
@@ -143,10 +143,10 @@ stderr. Add the `-v` option to also show Gradle output, and non-Python logcat
 messages.
 
 Any other arguments on the `android.py test` command line will be passed through
-to `python -m test` – use `--` to separate them from android.py's own options.
+to `python -m test` – use `--` to separate them from android.py's own options.
 See the [Python Developer's
 Guide](https://devguide.python.org/testing/run-write-tests/) for common options
-– most of them will work on Android, except for those that involve subprocesses,
+– most of them will work on Android, except for those that involve subprocesses,
 such as `-j`.
 
 Every time you run `android.py test`, changes in pure-Python files in the
index 3ad062d9d51a148a585ec3981e91a33ab4201418..c627cb1b0e0b2234960caaf21c933bfd5adb6a29 100644 (file)
@@ -75,13 +75,24 @@ for ((i, prefix) in prefixes.withIndex()) {
 
 
 android {
+    val androidEnvFile = file("../../android-env.sh").absoluteFile
+
     namespace = "org.python.testbed"
     compileSdk = 34
 
     defaultConfig {
         applicationId = "org.python.testbed"
-        minSdk = 21
+
+        minSdk = androidEnvFile.useLines {
+            for (line in it) {
+                """api_level:=(\d+)""".toRegex().find(line)?.let {
+                    return@useLines it.groupValues[1].toInt()
+                }
+            }
+            throw GradleException("Failed to find API level in $androidEnvFile")
+        }
         targetSdk = 34
+
         versionCode = 1
         versionName = "1.0"
 
@@ -101,7 +112,6 @@ android {
         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
     }
 
-    val androidEnvFile = file("../../android-env.sh").absoluteFile
     ndkVersion = androidEnvFile.useLines {
         for (line in it) {
             """ndk_version=(\S+)""".toRegex().find(line)?.let {
index 69251332d48890c15541564890ca796a05aee6a9..ec7f93a3e5ee13a4c21d8236a4261353a7ea829f 100644 (file)
@@ -34,9 +34,12 @@ typedef struct {
     int pipe[2];
 } StreamInfo;
 
+// The FILE member can't be initialized here because stdout and stderr are not
+// compile-time constants. Instead, it's initialized immediately before the
+// redirection.
 static StreamInfo STREAMS[] = {
-    {stdout, STDOUT_FILENO, ANDROID_LOG_INFO, "native.stdout", {-1, -1}},
-    {stderr, STDERR_FILENO, ANDROID_LOG_WARN, "native.stderr", {-1, -1}},
+    {NULL, STDOUT_FILENO, ANDROID_LOG_INFO, "native.stdout", {-1, -1}},
+    {NULL, STDERR_FILENO, ANDROID_LOG_WARN, "native.stderr", {-1, -1}},
     {NULL, -1, ANDROID_LOG_UNKNOWN, NULL, {-1, -1}},
 };
 
@@ -87,6 +90,8 @@ static char *redirect_stream(StreamInfo *si) {
 JNIEXPORT void JNICALL Java_org_python_testbed_PythonTestRunner_redirectStdioToLogcat(
     JNIEnv *env, jobject obj
 ) {
+    STREAMS[0].file = stdout;
+    STREAMS[1].file = stderr;
     for (StreamInfo *si = STREAMS; si->file; si++) {
         char *error_prefix;
         if ((error_prefix = redirect_stream(si))) {