Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
103f97e
Update to Android Gradle plugin version 8.4.2
mhsmith Jul 10, 2024
fb1b54a
Separate Python test runner from MainActivity so it can be run from a…
mhsmith Jul 10, 2024
b99b769
Add `android.py test` command
mhsmith Jul 10, 2024
6f07a39
--connected mode working
mhsmith Jul 23, 2024
c71f3cf
--managed mode working, and add instructions to README
mhsmith Jul 23, 2024
cd27b0f
Clarifications
mhsmith Jul 23, 2024
6bbdfda
Restore build command logging, and only require adb when running tests
mhsmith Jul 23, 2024
e738689
Make testbed include only those ABIs which have been built
mhsmith Jul 30, 2024
4561930
Merge branch 'android-2024-07' into android-test-script
mhsmith Jul 30, 2024
b519874
Fix Windows issues
mhsmith Jul 31, 2024
b3ed4c7
Merge branch 'main' into android-test-script
mhsmith Aug 5, 2024
32f79d7
Clarify documentation; remove default `python -m test` arguments
mhsmith Aug 8, 2024
6471512
Link to page about test options; add newlines at end of files
mhsmith Aug 8, 2024
5c3967e
Add `android.py build-testbed` command
mhsmith Aug 8, 2024
cb60cc4
If test script fails before logcat starts, show the Gradle output eve…
mhsmith Aug 11, 2024
b075842
Fix logcat error messages being hidden
mhsmith Aug 11, 2024
2266e82
Improve logging, add timeouts
mhsmith Aug 11, 2024
397d20b
Make the app use the same NDK version as the Python build
mhsmith Aug 11, 2024
8e80dd2
Install platform-tools automatically
mhsmith Aug 11, 2024
709061e
In --connected mode, uninstall app before running Gradle
mhsmith Aug 12, 2024
756bc13
Handle adb logcat returning failure when device disconnects
mhsmith Aug 12, 2024
6b2ed6c
Filter logs by PID rather than UID
mhsmith Aug 12, 2024
05a26cc
Try to terminate subprocesses with SIGTERM before sending SIGKILL
mhsmith Aug 12, 2024
a0dd03b
Handle SIGTERM the same way as SIGINT
mhsmith Aug 12, 2024
2d53549
Fix race condition with pre-run uninstall
mhsmith Aug 12, 2024
c9d5bf5
Fix race condition in a more efficient way
mhsmith Aug 12, 2024
706a1da
Make testbed pick up edits to pure-Python files in the Lib directory
mhsmith Aug 12, 2024
ae3a460
Merge branch 'main' into android-test-script
mhsmith Aug 12, 2024
cf15b99
Remove `boot_completed`, which is unnecessary since we're no longer r…
mhsmith Aug 13, 2024
c56373a
Automatically accept SDK licenses, and log Gradle package installatio…
mhsmith Aug 13, 2024
1e89e58
Stop Gradle test tasks being skipped as up to date
mhsmith Aug 13, 2024
91f356b
Fix CalledProcessError formatting
mhsmith Aug 13, 2024
bdaad24
Add note about testing on Windows
mhsmith Aug 13, 2024
ca2bae2
Implement `fileno` method on stdout and stderr
mhsmith Aug 13, 2024
7a3d674
Correct comment
mhsmith Aug 13, 2024
f4b06f5
Merge branch 'main' into android-test-script
freakboy3742 Aug 13, 2024
47c02a5
Merge branch 'main' into android-test-script
mhsmith Aug 15, 2024
602fbdd
Add note about RAM requirements
mhsmith Aug 15, 2024
305d786
Handle transient failure of pidof
mhsmith Aug 15, 2024
2ad8e4b
Merge branch 'main' into android-test-script
freakboy3742 Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Automatically accept SDK licenses, and log Gradle package installatio…
…ns even in non-verbose mode
  • Loading branch information
mhsmith committed Aug 13, 2024
commit c56373a20196950dc30cdb1e2064f175fbb1ab94
56 changes: 33 additions & 23 deletions Android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@


try:
android_home = os.environ['ANDROID_HOME']
android_home = Path(os.environ['ANDROID_HOME'])
except KeyError:
sys.exit("The ANDROID_HOME environment variable is required.")

sdkmanager = Path(
f"{android_home}/cmdline-tools/latest/bin/sdkmanager"
+ (".bat" if os.name == "nt" else "")
)

adb = Path(
f"{android_home}/platform-tools/adb"
+ (".exe" if os.name == "nt" else "")
Expand Down Expand Up @@ -217,10 +212,34 @@ def clean_all(context):
delete_glob(CROSS_BUILD_DIR)


def setup_sdk():
sdkmanager = android_home / (
"cmdline-tools/latest/bin/sdkmanager"
+ (".bat" if os.name == "nt" else "")
)

# Gradle will fail if it needs to install an SDK package whose license
# hasn't been accepted, so pre-accept all licenses.
if not all((android_home / "licenses" / path).exists() for path in [
"android-sdk-arm-dbt-license", "android-sdk-license"
]):
run([sdkmanager, "--licenses"], text=True, input="y\n" * 100)

# Gradle may install this automatically, but we can't rely on that because
# we need to run adb within the logcat task.
if not adb.exists():
run([sdkmanager, "platform-tools"])


# To avoid distributing compiled artifacts without corresponding source code,
# the Gradle wrapper is not included in the CPython repository. Instead, we
# extract it from the Gradle release.
def setup_testbed(context):
def setup_testbed():
if all((TESTBED_DIR / path).exists() for path in [
"gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.jar",
]):
return

ver_long = "8.7.0"
ver_short = ver_long.removesuffix(".0")

Expand All @@ -240,15 +259,11 @@ def setup_testbed(context):
f"{temp_dir}/{outer_jar}", "gradle-wrapper.jar"])


def setup_testbed_if_needed(context):
if not gradlew.exists():
setup_testbed(context)


# run_testbed will build the app automatically, but it hides the Gradle output
# by default, so it's useful to have this as a separate command for the buildbot.
def build_testbed(context):
setup_testbed_if_needed(context)
setup_sdk()
setup_testbed()
run(
[gradlew, "--console", "plain", "packageDebug", "packageDebugAndroidTest"],
cwd=TESTBED_DIR,
Expand Down Expand Up @@ -459,7 +474,9 @@ async def gradle_task(context):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
) as process:
while line := (await process.stdout.readline()).decode(*DECODE_ARGS):
if context.verbose:
# Gradle may take several minutes to install SDK packages, so
# it's worth showing those messages even in non-verbose mode.
if context.verbose or line.startswith('Preparing "Install'):
sys.stdout.write(line)
else:
hidden_output.append(line)
Expand All @@ -481,12 +498,8 @@ async def gradle_task(context):


async def run_testbed(context):
if not adb.exists():
print("Installing Platform-Tools")
# Input "y" to accept licenses.
run([sdkmanager, "platform-tools"], text=True, input="y\n" * 100)

setup_testbed_if_needed(context)
setup_sdk()
setup_testbed()

if context.managed:
# In this mode, Gradle will create a device with an unpredictable name.
Expand Down Expand Up @@ -550,8 +563,6 @@ def parse_args():
subcommand.add_argument("args", nargs="*",
help="Extra arguments to pass to `configure`")

subcommands.add_parser(
"setup-testbed", help="Download the testbed Gradle wrapper")
subcommands.add_parser(
"build-testbed", help="Build the testbed app")
test = subcommands.add_parser(
Expand Down Expand Up @@ -582,7 +593,6 @@ def main():
"make-host": make_host_python,
"build": build_all,
"clean": clean_all,
"setup-testbed": setup_testbed,
"build-testbed": build_testbed,
"test": run_testbed}

Expand Down