Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f3b1070 authored by Devin Moore's avatar Devin Moore Committed by Gerrit Code Review
Browse files

Merge "Bump.py: Add new level to libvts_vintf_test_common" into main

parents 9a63fb94 a4155ed1
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ class Bump(object):
        self.copy_matrix()
        self.edit_android_bp()
        self.bump_libvintf()
        self.bump_libvts_vintf()

    def bump_kernel_configs(self):
        check_call([
@@ -157,6 +158,20 @@ class Bump(object):
                                        }} break;"""),
                            "    "*3))

    def bump_libvts_vintf(self):
      if not self.current_version:
        print("Skip libvts_vintf update...")
        return
      try:
        check_call(["grep", "-h",
                    f"{self.next_level}, Level::{self.next_letter.upper()}",
                    f"{self.top}/test/vts-testcase/hal/treble/vintf/libvts_vintf_test_common/common.cpp"])
        print("libvts_vintf is already up-to-date")
      except subprocess.CalledProcessError:
        print("Adding new API level to libvts_vintf")
        add_lines_below(f"{self.top}/test/vts-testcase/hal/treble/vintf/libvts_vintf_test_common/common.cpp",
                        f"        {{{self.current_level}, Level::{self.current_letter.upper()}}},",
                        f"        {{{self.next_level}, Level::{self.next_letter.upper()}}},\n")

def add_lines_above(file, pattern, lines):
    with open(file, 'r+') as f:
@@ -171,6 +186,16 @@ def add_lines_above(file, pattern, lines):
        f.write(f"\n{lines}\n{pattern}\n".join(split_text))
        f.truncate()

def add_lines_below(file, pattern, lines):
    final_lines = []
    with open(file, 'r+') as f:
        for line in f:
          final_lines.append(line)
          if pattern in line:
              final_lines.append(lines)
        f.seek(0)
        f.write("".join(final_lines))
        f.truncate()

def main():
    parser = argparse.ArgumentParser(description=__doc__)