Skip to content

Commit 32e0610

Browse files
keithlelandjansen
andauthored
[7.x] Fix rules_apple device runner crash on Rapid Security Response versions (#2902)
Devices running an Apple RSR update report OS versions like "18.3.1 (a)". The rules_apple device runner fails to parse the "(a)" suffix: ``` ValueError: invalid literal for int() with base 10: '1 (a)' ``` Patch rules_apple 4.5.1 to strip non-numeric suffixes from each version component before integer conversion. `bazel run` an iOS application target on a physical device (builds, uploads, and runs) Fixes #2900 (cherry picked from commit 8c999a8) Co-authored-by: Leland Jansen <hello@lelandjansen.com>
1 parent 1b80aae commit 32e0610

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

apple/internal/templates/apple_device.template.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
# 1. Installs and launches the application on a device corresponding to `device_identifier`.
3131
# 2. Displays the application's output on the console
3232

33+
import re
34+
3335
import collections.abc
3436
import contextlib
3537
import json
@@ -189,8 +191,11 @@ def os_version_number_to_int(version: str) -> int:
189191
An integer in the form 0xAABBCC, where AA is the major version, BB is
190192
the minor version, and CC is the micro version.
191193
"""
192-
# Pad the version to major.minor.micro.
193-
version_components = (version.split(".") + ["0"] * 3)[:3]
194+
# Strip non-numeric suffixes (e.g. Rapid Security Response "(a)") from each
195+
# component, then pad to major.minor.micro.
196+
version_components = (
197+
[re.sub(r"[^0-9].*", "", c) or "0" for c in version.split(".")] + ["0"] * 3
198+
)[:3]
194199
result = 0
195200
for component in version_components:
196201
result = (result << 8) | int(component)

0 commit comments

Comments
 (0)