From 4be20f792aaf5152e331598903a6fa08cab9857c Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Thu, 1 Feb 2024 21:39:36 +0000 Subject: [PATCH 1/2] Update bump.py for Trunk Stable The next year's compatbility matrix is added to a conditional statement so it's only available on in-development release configurations. The curent year's compatibility matrix is moved from the conditional statement to always be added to all release configs. The next year's compatibility matrix level is set to the next year's level after copying the current matrix file. Test: ./bump.py Bug: 279809333 Change-Id: Id711ba79110c8775f715eddf37a9bf51b073ec91 --- compatibility_matrices/bump.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/compatibility_matrices/bump.py b/compatibility_matrices/bump.py index 88b7a42013..5cad1e5e31 100755 --- a/compatibility_matrices/bump.py +++ b/compatibility_matrices/bump.py @@ -47,6 +47,7 @@ class Bump(object): self.current_level = cmdline_args.current self.current_module_name = f"framework_compatibility_matrix.{self.current_level}.xml" self.current_xml = self.interfaces_dir / f"compatibility_matrices/compatibility_matrix.{self.current_level}.xml" + self.device_module_name = "framework_compatibility_matrix.device.xml" self.next_level = cmdline_args.next self.next_module_name = f"framework_compatibility_matrix.{self.next_level}.xml" @@ -81,7 +82,8 @@ class Bump(object): ]) def copy_matrix(self): - shutil.copyfile(self.current_xml, self.next_xml) + with open(self.current_xml) as f_current, open(self.next_xml, "w") as f_next: + f_next.write(f_current.read().replace(f"level=\"{self.current_level}\"", f"level=\"{self.next_level}\"")) def edit_android_bp(self): android_bp = self.interfaces_dir / "compatibility_matrices/Android.bp" @@ -124,19 +126,20 @@ class Bump(object): def edit_android_mk(self): android_mk = self.interfaces_dir / "compatibility_matrices/Android.mk" + lines = [] with open(android_mk) as f: if self.next_module_name in f.read(): return f.seek(0) - lines = f.readlines() - current_module_line_number = None - for line_number, line in enumerate(lines): - if self.current_module_name in line: - current_module_line_number = line_number - break - assert current_module_line_number is not None - lines.insert(current_module_line_number + 1, - f" {self.next_module_name} \\\n") + for line in f: + if f" {self.device_module_name} \\\n" in line: + lines.append(f" {self.current_module_name} \\\n") + + if self.current_module_name in line: + lines.append(f" {self.next_module_name} \\\n") + else: + lines.append(line) + with open(android_mk, "w") as f: f.write("".join(lines)) From 0425916b68fef4588cd34ac5c63de61fe1202f0d Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Tue, 6 Feb 2024 22:52:32 +0000 Subject: [PATCH 2/2] bump.py remove Level.h dependency We want to run bump.py during finalization. We don't want to have to update Level.h and the VTS tests that early. So this CL removes the dependency on Level.h and requires the current/next letters of the API levels for the kernerl configs to be passed as arguments. Test: bump.py 202404 202505 v w Bug: 279809333 Change-Id: If8f281eccf62d380949a5ea9f5d0d3bb2d7f19ab --- compatibility_matrices/bump.py | 39 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/compatibility_matrices/bump.py b/compatibility_matrices/bump.py index 5cad1e5e31..a5a453bdea 100755 --- a/compatibility_matrices/bump.py +++ b/compatibility_matrices/bump.py @@ -16,8 +16,6 @@ # """ Creates the next compatibility matrix. - -Requires libvintf Level.h to be updated before executing this script. """ import argparse @@ -44,41 +42,28 @@ class Bump(object): self.top = pathlib.Path(os.environ["ANDROID_BUILD_TOP"]) self.interfaces_dir = self.top / "hardware/interfaces" - self.current_level = cmdline_args.current + self.current_level = cmdline_args.current_level + self.current_letter = cmdline_args.current_letter self.current_module_name = f"framework_compatibility_matrix.{self.current_level}.xml" self.current_xml = self.interfaces_dir / f"compatibility_matrices/compatibility_matrix.{self.current_level}.xml" self.device_module_name = "framework_compatibility_matrix.device.xml" - self.next_level = cmdline_args.next + self.next_level = cmdline_args.next_level + self.next_letter = cmdline_args.next_letter self.next_module_name = f"framework_compatibility_matrix.{self.next_level}.xml" self.next_xml = self.interfaces_dir / f"compatibility_matrices/compatibility_matrix.{self.next_level}.xml" - self.level_to_letter = self.get_level_to_letter_mapping() - print("Found level mapping in libvintf Level.h:", self.level_to_letter) - def run(self): self.bump_kernel_configs() self.copy_matrix() self.edit_android_bp() self.edit_android_mk() - def get_level_to_letter_mapping(self): - levels_file = self.top / "system/libvintf/include/vintf/Level.h" - with open(levels_file) as f: - lines = f.readlines() - pairs = [ - line.split("=", maxsplit=2) for line in lines if "=" in line - ] - return { - level.strip().removesuffix(","): letter.strip() - for letter, level in pairs - } - def bump_kernel_configs(self): check_call([ self.top / "kernel/configs/tools/bump.py", - self.level_to_letter[self.current_level].lower(), - self.level_to_letter[self.next_level].lower(), + self.current_letter, + self.next_letter, ]) def copy_matrix(self): @@ -102,7 +87,7 @@ class Bump(object): next_kernel_configs = check_output( """grep -rh name: | sed -E 's/^.*"(.*)".*/\\1/g'""", cwd=self.top / "kernel/configs" / - self.level_to_letter[self.next_level].lower(), + self.next_letter, text=True, shell=True, ).splitlines() @@ -146,12 +131,18 @@ class Bump(object): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("current", + parser.add_argument("current_level", type=str, help="VINTF level of the current version (e.g. 9)") - parser.add_argument("next", + parser.add_argument("next_level", type=str, help="VINTF level of the next version (e.g. 10)") + parser.add_argument("current_letter", + type=str, + help="Letter of the API level of the current version (e.g. v)") + parser.add_argument("next_letter", + type=str, + help="Letter of the API level of the next version (e.g. w)") cmdline_args = parser.parse_args() Bump(cmdline_args).run()