From 5104002f1a7a860131b4f787cd86e4e27da7f7a9 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 18 Oct 2023 18:26:03 +0100 Subject: [PATCH] target: Update kernel version parsing for Android GKI kernels Android GKI kernels have versions such as: 5.15.110-android14-11-ga6d7915820a0-ab10726252 Update the parsing regex to include: * gki_abi: 10726252 in this example * android_version: 14 in this example This also allows parsing the git sha1 correctly, which otherwise is broken on a version like that. Fixes https://github.com/ARM-software/devlib/issues/654 --- devlib/target.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devlib/target.py b/devlib/target.py index f4c5ebd..3f2f03f 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -75,7 +75,7 @@ ANDROID_SCREEN_ROTATION_REGEX = re.compile(r'orientation=(?P[0-3])') DEFAULT_SHELL_PROMPT = re.compile(r'^.*(shell|root|juno)@?.*:[/~]\S* *[#$] ', re.MULTILINE) KVERSION_REGEX = re.compile( - r'(?P\d+)(\.(?P\d+)(\.(?P\d+)(-rc(?P\d+))?)?)?(-(?P\d+)-g(?P[0-9a-fA-F]{7,}))?' + r'(?P\d+)(\.(?P\d+)(\.(?P\d+))?(-rc(?P\d+))?)?(-android(?P[0-9]+))?(-(?P\d+)-g(?P[0-9a-fA-F]{7,}))?(-ab(?P[0-9]+))?' ) GOOGLE_DNS_SERVER_ADDRESS = '8.8.8.8' @@ -2527,6 +2527,10 @@ class KernelVersion(object): :type commits: int :ivar sha1: Kernel git revision hash, if available (otherwise None) :type sha1: str + :ivar android_version: Android version, if available (otherwise None) + :type android_version: int + :ivar gki_abi: GKI kernel abi, if available (otherwise None) + :type gki_abi: str :ivar parts: Tuple of version number components. Can be used for lexicographically comparing kernel versions. @@ -2550,6 +2554,8 @@ class KernelVersion(object): self.sha1 = None self.rc = None self.commits = None + self.gki_abi = None + self.android_version = None match = KVERSION_REGEX.match(version_string) if match: groups = match.groupdict() @@ -2563,6 +2569,10 @@ class KernelVersion(object): self.commits = int(groups['commits']) if groups['sha1'] is not None: self.sha1 = match.group('sha1') + if groups['gki_abi'] is not None: + self.gki_abi = match.group('gki_abi') + if groups['android_version'] is not None: + self.android_version = int(match.group('android_version')) self.parts = (self.version_number, self.major, self.minor)