Skip to content

Commit f4b1d3e

Browse files
authored
Minor fixes for Android (#154895)
A collection of small cleanups for Android support: * Clarifies the documentation around version number handling for iOS and Android in os.uname and platform.release * Ensures that automated NDK installs surface messages written to stderr * Makes the Android NDK check more robust for incomplete downloads * Corrects some linting errors in Android build scripts
1 parent 51ae3c0 commit f4b1d3e

5 files changed

Lines changed: 13 additions & 14 deletions

File tree

Doc/library/os.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@ process and user.
802802
Returns information identifying the current operating system.
803803
The return value is a :class:`uname_result`.
804804

805-
On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
805+
On macOS, iOS and Android, this returns the *kernel* name and release (i.e.,
806806
``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
807-
can be used to get the user-facing operating system name and version on iOS and
807+
can be used to get the user-facing operating system name and release on iOS and
808808
Android.
809809

810810
.. seealso::

Doc/library/platform.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Cross platform
141141
Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'``. An empty string is
142142
returned if the value cannot be determined.
143143

144+
On iOS and Android, this is the user-facing OS release. To obtain the
145+
Darwin or Linux kernel release, use :func:`os.uname`.
144146

145147
.. function:: system()
146148

@@ -163,9 +165,6 @@ Cross platform
163165
Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
164166
returned if the value cannot be determined.
165167

166-
On iOS and Android, this is the user-facing OS version. To obtain the
167-
Darwin or Linux kernel version, use :func:`os.uname`.
168-
169168
.. function:: uname()
170169

171170
Fairly portable uname interface. Returns a :func:`~collections.namedtuple`

Platforms/Android/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def android_env(host):
158158
f"PREFIX={prefix}; "
159159
f". {ENV_SCRIPT}; "
160160
f"export",
161-
check=True, shell=True, capture_output=True, encoding='utf-8',
161+
check=True, shell=True, stdout=subprocess.PIPE, encoding='utf-8',
162162
).stdout
163163

164164
env = {}
@@ -625,7 +625,8 @@ async def read_int(size):
625625
except ValueError:
626626
priority = LogPriority.UNKNOWN
627627

628-
payload_fields = (await read_bytes(payload_len - 1)).split(b"\0")
628+
payload = await read_bytes(payload_len - 1)
629+
payload_fields = payload.split(b"\0")
629630
if len(payload_fields) < 2:
630631
raise ValueError(
631632
f"payload {payload!r} does not contain at least 2 "

Platforms/Android/android-env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
: "${PREFIX:-}" # Path in which to find required libraries
88

99

10-
# Print all messages on stderr so they're visible when running within build-wheel.
10+
# Print all messages on stderr so they're visible when stdout is captured.
1111
log() {
1212
echo "$1" >&2
1313
}
@@ -27,7 +27,7 @@ fail() {
2727
ndk_version=27.3.13750724
2828

2929
ndk=$ANDROID_HOME/ndk/$ndk_version
30-
if ! [ -e "$ndk" ]; then
30+
if ! [ -e "$ndk/package.xml" ]; then
3131
log "Installing NDK - this may take several minutes"
3232
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
3333
fi

Platforms/Android/testbed/app/src/main/java/org/python/testbed/MainActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ class PythonTestRunner(val context: Context) {
2828
* @param args Python command-line, encoded as JSON.
2929
* @return The Python exit status: zero on success, nonzero on failure. */
3030
fun run(args: String) : Int {
31-
// We leave argument 0 as an empty string, which is a placeholder for the
32-
// executable name in embedded mode.
31+
// Argument 0 is a placeholder for the executable name in embedded mode.
3332
val argsJsonArray = JSONArray(args)
34-
val argsStringArray = Array<String>(argsJsonArray.length() + 1) { it -> ""}
35-
for (i in 0..<argsJsonArray.length()) {
36-
argsStringArray[i + 1] = argsJsonArray.getString(i)
33+
val argsStringArray = Array<String>(argsJsonArray.length() + 1) { i ->
34+
if (i == 0) ""
35+
else argsJsonArray.getString(i - 1)
3736
}
3837

3938
// Python needs this variable to help it find the temporary directory,

0 commit comments

Comments
 (0)