Skip to content

Commit 2b9750a

Browse files
committed
Move Android build script to Platforms folder.
1 parent efde433 commit 2b9750a

File tree

20 files changed

+51
-36
lines changed

20 files changed

+51
-36
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ jobs:
353353
with:
354354
persist-credentials: false
355355
- name: Build and test
356-
run: ./Android/android.py ci --fast-ci ${{ matrix.arch }}-linux-android
356+
run: python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
357357

358358
build-ios:
359359
name: iOS
Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Instead, use one of the tools listed
1111
[here](https://docs.python.org/3/using/android.html), which will provide a much
1212
easier experience.
1313

14-
1514
## Prerequisites
1615

1716
If you already have an Android SDK installed, export the `ANDROID_HOME`
@@ -25,15 +24,14 @@ it:
2524
`android-sdk/cmdline-tools/latest`.
2625
* `export ANDROID_HOME=/path/to/android-sdk`
2726

28-
The `android.py` script will automatically use the SDK's `sdkmanager` to install
27+
The `Platforms/Android` script will automatically use the SDK's `sdkmanager` to install
2928
any packages it needs.
3029

3130
The script also requires the following commands to be on the `PATH`:
3231

3332
* `curl`
3433
* `java` (or set the `JAVA_HOME` environment variable)
3534

36-
3735
## Building
3836

3937
Python can be built for Android on any POSIX platform supported by the Android
@@ -43,29 +41,28 @@ First we'll make a "build" Python (for your development machine), then use it to
4341
help produce a "host" Python for Android. So make sure you have all the usual
4442
tools and libraries needed to build Python for your development machine.
4543

46-
The easiest way to do a build is to use the `android.py` script. You can either
44+
The easiest way to do a build is to use the `Platforms/Android` script. You can either
4745
have it perform the entire build process from start to finish in one step, or
4846
you can do it in discrete steps that mirror running `configure` and `make` for
4947
each of the two builds of Python you end up producing.
5048

51-
The discrete steps for building via `android.py` are:
49+
The discrete steps for building via `Platforms/Android` are:
5250

5351
```sh
54-
./android.py configure-build
55-
./android.py make-build
56-
./android.py configure-host HOST
57-
./android.py make-host HOST
52+
python3 Platforms/Android configure-build
53+
python3 Platforms/Android make-build
54+
python3 Platforms/Android configure-host HOST
55+
python3 Platforms/Android make-host HOST
5856
```
5957

6058
`HOST` identifies which architecture to build. To see the possible values, run
61-
`./android.py configure-host --help`.
59+
`python3 Platforms/Android configure-host --help`.
6260

6361
To do all steps in a single command, run:
6462

6563
```sh
66-
./android.py build HOST
64+
python3 Platforms/Android build HOST
6765
```
68-
6966
In the end you should have a build Python in `cross-build/build`, and a host
7067
Python in `cross-build/HOST`.
7168

@@ -75,25 +72,23 @@ call. For example, if you want a pydebug build that also caches the results from
7572
`configure`, you can do:
7673

7774
```sh
78-
./android.py build HOST -- -C --with-pydebug
75+
python3 Platforms/Android build HOST -- -C --with-pydebug
7976
```
8077

81-
8278
## Packaging
8379

8480
After building an architecture as described in the section above, you can
8581
package it for release with this command:
8682

8783
```sh
88-
./android.py package HOST
84+
python3 Platforms/Android package HOST
8985
```
9086

9187
`HOST` is defined in the section above.
9288

9389
This will generate a tarball in `cross-build/HOST/dist`, whose structure is
9490
similar to the `Android` directory of the CPython source tree.
9591

96-
9792
## Testing
9893

9994
The Python test suite can be run on Linux, macOS, or Windows.
@@ -103,14 +98,10 @@ require adding your user to a group, or changing your udev rules. On GitHub
10398
Actions, the test script will do this automatically using the commands shown
10499
[here](https://github.blog/changelog/2024-04-02-github-actions-hardware-accelerated-android-virtualization-now-available/).
105100

106-
You can run the test suite either:
107-
108-
* Within the CPython repository, after doing a build as described above. On
109-
Windows, you won't be able to do the build on the same machine, so you'll have
110-
to copy the `cross-build/HOST/prefix` directory from somewhere else.
111-
112-
* Or by taking a release package built using the `package` command, extracting
113-
it wherever you want, and using its own copy of `android.py`.
101+
You can run the test suite by doing a build as described above, and then running
102+
`python3 Platforms/Android test`. On Windows, you won't be able to do the build
103+
on the same machine, so you'll have to copy the `cross-build/HOST/prefix` directory
104+
from somewhere else.
114105

115106
The test script supports the following modes:
116107

@@ -120,7 +111,7 @@ The test script supports the following modes:
120111
script like this:
121112

122113
```sh
123-
./android.py test --connected emulator-5554
114+
python3 Platforms/Android test --connected emulator-5554
124115
```
125116

126117
* In `--managed` mode, it uses a temporary headless emulator defined in the
@@ -131,29 +122,47 @@ The test script supports the following modes:
131122
to our minimum and maximum supported Android versions. For example:
132123

133124
```sh
134-
./android.py test --managed maxVersion
125+
python3 Platforms/Android test --managed maxVersion
135126
```
136127

137128
By default, the only messages the script will show are Python's own stdout and
138129
stderr. Add the `-v` option to also show Gradle output, and non-Python logcat
139130
messages.
140131

141-
Any other arguments on the `android.py test` command line will be passed through
142-
to `python -m test` – use `--` to separate them from android.py's own options.
132+
Any other arguments on the `Platforms/Android test` command line will be passed through
133+
to `python -m test` – use `--` to separate them from `Platforms/Android`'s own options.
143134
See the [Python Developer's
144135
Guide](https://devguide.python.org/testing/run-write-tests/) for common options
145136
– most of them will work on Android, except for those that involve subprocesses,
146137
such as `-j`.
147138

148-
Every time you run `android.py test`, changes in pure-Python files in the
139+
Every time you run `python3 Platforms/Android test`, changes in pure-Python files in the
149140
repository's `Lib` directory will be picked up immediately. Changes in C files,
150141
and architecture-specific files such as sysconfigdata, will not take effect
151-
until you re-run `android.py make-host` or `build`.
142+
until you re-run `python3 Platforms/Android make-host` or `build`.
143+
144+
### Testing a third-party package
145+
146+
The `Platforms/Android` script is also included as `android.py` in the root of a
147+
release package (i.e., the one built using `Platforms/Android package`).
148+
149+
You can use this script to test third-party packages by taking a release
150+
package, extracting it wherever you want, and using the `android.py` script to
151+
run the test suite for your third-party package.
152+
153+
Any argument that can be passed to `python3 Platforms/Android test` can also be
154+
passed to `android.py`. The following options will be of particular use when
155+
configuring the execution of a third-party test suite:
156+
157+
* `--cwd`: the directory of content to copy into the testbed app as the working
158+
directory.
159+
* `--site-packages`: the directory to copy into the testbed app to use as site
160+
packages.
152161

153-
The testbed app can also be used to test third-party packages. For more details,
154-
run `android.py test --help`, paying attention to the options `--site-packages`,
155-
`--cwd`, `-c` and `-m`.
162+
The arguments passed after `--` should also include either a `-c` or `-m`
163+
argument to specify how the test suite should be started.
156164

165+
For more details, run `android.py test --help`.
157166

158167
## Using in your own app
159168

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424

2525

2626
SCRIPT_NAME = Path(__file__).name
27+
if SCRIPT_NAME.startswith("__"):
28+
SCRIPT_NAME = "Python/Android"
29+
2730
ANDROID_DIR = Path(__file__).resolve().parent
28-
PYTHON_DIR = ANDROID_DIR.parent
31+
PYTHON_DIR = ANDROID_DIR.parent.parent
2932
in_source_tree = (
3033
ANDROID_DIR.name == "Android" and (PYTHON_DIR / "pyconfig.h.in").exists()
3134
)
@@ -772,7 +775,10 @@ def package(context):
772775
cwd=ANDROID_DIR, capture_output=True, text=True, log=False,
773776
).stdout.splitlines():
774777
src = ANDROID_DIR / line
775-
dst = temp_dir / line
778+
# "__main__.py" is renamed "android.py" for distribution purpose
779+
dst = temp_dir / {
780+
"__main__.py": "android.py"
781+
}.get(line, line)
776782
dst.parent.mkdir(parents=True, exist_ok=True)
777783
shutil.copy2(src, dst, follow_symlinks=False)
778784

Android/testbed/.idea/inspectionProfiles/Project_Default.xml renamed to Platforms/Android/testbed/.idea/inspectionProfiles/Project_Default.xml

File renamed without changes.
File renamed without changes.

Android/testbed/app/src/androidTest/java/org/python/testbed/PythonSuite.kt renamed to Platforms/Android/testbed/app/src/androidTest/java/org/python/testbed/PythonSuite.kt

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)