]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-146450: Ensure Android gradle build uses custom cross-build dir (GH-148319...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 13 Apr 2026 01:13:49 +0000 (03:13 +0200)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2026 01:13:49 +0000 (09:13 +0800)
Ensures that the testbed's Gradle configuration uses the cross-build environment
variable, and that variable is passed to Gradle by the cross-build script.
(cherry picked from commit b29afe62f7236f7161c2670dccc24368217a7fb1)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Co-authored-by: Malcolm Smith <smith@chaquo.com>
Android/android.py
Android/testbed/app/build.gradle.kts

index fbb1d6a5fc2216735d6c853d225a6d0184c61848..c421576d99a96804fdbb274c277d64b2e05a5111 100755 (executable)
@@ -393,17 +393,6 @@ def setup_testbed():
         os.chmod(out_path, 0o755)
 
 
-# run_testbed will build the app automatically, but it's useful to have this as
-# a separate command to allow running the app outside of this script.
-def build_testbed(context):
-    setup_sdk()
-    setup_testbed()
-    run(
-        [gradlew, "--console", "plain", "packageDebug", "packageDebugAndroidTest"],
-        cwd=TESTBED_DIR,
-    )
-
-
 # Work around a bug involving sys.exit and TaskGroups
 # (https://github.com/python/cpython/issues/101515).
 def exit(*args):
@@ -645,6 +634,10 @@ async def gradle_task(context):
         task_prefix = "connected"
         env["ANDROID_SERIAL"] = context.connected
 
+    # Ensure that CROSS_BUILD_DIR is in the Gradle environment, regardless
+    # of whether it was set by environment variable or `--cross-build-dir`.
+    env["CROSS_BUILD_DIR"] = CROSS_BUILD_DIR
+
     if context.ci_mode:
         context.args[0:0] = [
             # See _add_ci_python_opts in libregrtest/main.py.
@@ -871,6 +864,18 @@ def parse_args():
 
     def add_parser(*args, **kwargs):
         parser = subcommands.add_parser(*args, **kwargs)
+        parser.add_argument(
+            "--cross-build-dir",
+            action="store",
+            default=os.environ.get("CROSS_BUILD_DIR"),
+            dest="cross_build_dir",
+            type=Path,
+            help=(
+                "Path to the cross-build directory "
+                f"(default: {CROSS_BUILD_DIR}). Can also be set "
+                "with the CROSS_BUILD_DIR environment variable."
+            ),
+        )
         parser.add_argument(
             "-v", "--verbose", action="count", default=0,
             help="Show verbose output. Use twice to be even more verbose.")
@@ -883,7 +888,7 @@ def parse_args():
     )
     configure_build = add_parser(
         "configure-build", help="Run `configure` for the build Python")
-    make_build = add_parser(
+    add_parser(
         "make-build", help="Run `make` for the build Python")
     configure_host = add_parser(
         "configure-host", help="Run `configure` for Android")
@@ -895,38 +900,12 @@ def parse_args():
         help="Delete build directories for the selected target"
     )
 
-    add_parser("build-testbed", help="Build the testbed app")
     test = add_parser("test", help="Run the testbed app")
     package = add_parser("package", help="Make a release package")
     ci = add_parser("ci", help="Run build, package and test")
     env = add_parser("env", help="Print environment variables")
 
     # Common arguments
-    # --cross-build-dir argument
-    for cmd in [
-        clean,
-        configure_build,
-        make_build,
-        configure_host,
-        make_host,
-        build,
-        package,
-        test,
-        ci,
-    ]:
-        cmd.add_argument(
-            "--cross-build-dir",
-            action="store",
-            default=os.environ.get("CROSS_BUILD_DIR"),
-            dest="cross_build_dir",
-            type=Path,
-            help=(
-                "Path to the cross-build directory "
-                f"(default: {CROSS_BUILD_DIR}). Can also be set "
-                "with the CROSS_BUILD_DIR environment variable."
-            ),
-        )
-
     # --cache-dir option
     for cmd in [configure_host, build, ci]:
         cmd.add_argument(
@@ -1031,7 +1010,6 @@ def main():
         "make-host": make_host_python,
         "build": build_targets,
         "clean": clean_targets,
-        "build-testbed": build_testbed,
         "test": run_testbed,
         "package": package,
         "ci": ci,
index b58edc04a929d9f323e607810157d893ded2fcf9..bd8334b64bb0a89acb39c2f1ed7853e101deef6b 100644 (file)
@@ -8,7 +8,7 @@ plugins {
 
 val ANDROID_DIR = file("../..")
 val PYTHON_DIR = ANDROID_DIR.parentFile!!
-val PYTHON_CROSS_DIR = file("$PYTHON_DIR/cross-build")
+val PYTHON_CROSS_DIR = file(System.getenv("CROSS_BUILD_DIR") ?: "$PYTHON_DIR/cross-build")
 val inSourceTree = (
     ANDROID_DIR.name == "Android" && file("$PYTHON_DIR/pyconfig.h.in").exists()
 )