Devin Moore | faa5b0e | 2025-01-08 18:36:14 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2025 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | """ |
| 18 | Finalizes the current compatibility matrix and allows `next` targets to |
| 19 | use the new FCM. |
| 20 | """ |
| 21 | |
| 22 | import argparse |
| 23 | import os |
| 24 | import pathlib |
| 25 | import re |
| 26 | import subprocess |
| 27 | import textwrap |
| 28 | |
| 29 | |
| 30 | def check_call(*args, **kwargs): |
| 31 | print(args) |
| 32 | subprocess.check_call(*args, **kwargs) |
| 33 | |
| 34 | def check_output(*args, **kwargs): |
| 35 | print(args) |
| 36 | return subprocess.check_output(*args, **kwargs) |
| 37 | |
| 38 | class Bump(object): |
| 39 | |
| 40 | def __init__(self, cmdline_args): |
| 41 | self.top = pathlib.Path(os.environ["ANDROID_BUILD_TOP"]) |
| 42 | self.interfaces_dir = self.top / "hardware/interfaces" |
| 43 | |
| 44 | self.current_level = cmdline_args.current_level |
| 45 | self.current_module_name = f"framework_compatibility_matrix.{self.current_level}.xml" |
| 46 | self.device_module_name = "framework_compatibility_matrix.device.xml" |
| 47 | |
| 48 | def run(self): |
| 49 | self.edit_android_bp() |
| 50 | |
| 51 | def edit_android_bp(self): |
| 52 | android_bp = self.interfaces_dir / "compatibility_matrices/Android.bp" |
| 53 | |
| 54 | # update the SYSTEM_MATRIX_DEPS variable to unconditionally include the |
| 55 | # latests FCM. This adds the file to `next` configs so releasing devices |
| 56 | # can use the latest interfaces. |
| 57 | lines = [] |
| 58 | with open(android_bp) as f: |
| 59 | for line in f: |
| 60 | if f" \"{self.device_module_name}\",\n" in line: |
| 61 | lines.append(f" \"{self.current_module_name}\",\n") |
| 62 | |
| 63 | lines.append(line) |
| 64 | |
| 65 | with open(android_bp, "w") as f: |
| 66 | f.write("".join(lines)) |
| 67 | |
| 68 | def main(): |
| 69 | parser = argparse.ArgumentParser(description=__doc__) |
| 70 | parser.add_argument("current_level", |
| 71 | type=str, |
| 72 | help="VINTF level of the current version (e.g. 202404)") |
| 73 | cmdline_args = parser.parse_args() |
| 74 | |
| 75 | Bump(cmdline_args).run() |
| 76 | |
| 77 | |
| 78 | if __name__ == "__main__": |
| 79 | main() |