chore(Kconfig): add version info to Kconfig file to check mismatch (#6900)

This commit is contained in:
Neo Xu
2024-09-24 11:33:39 +08:00
committed by GitHub
parent a246604041
commit 2b7cacf2bc
3 changed files with 50 additions and 0 deletions
+30
View File
@@ -121,6 +121,35 @@ class CmakeReplacer(MacroReplacer):
def getReplacement(self, val: str):
return r'\g<1>' + val + r'\g<3>'
class KconfigReplacer(RepoFileVersionReplacer):
"""Replace version info in Kconfig file"""
def __init__(self, relative_path_segments: List[str]):
super().__init__(relative_path_segments, 3)
def applyVersionToLine(self, line: str, version: Version):
targets = {
'LVGL_VERSION_MAJOR': version.major,
'LVGL_VERSION_MINOR': version.minor,
'LVGL_VERSION_PATCH': version.patch,
}
for key, val in targets.items():
pattern = self.getPattern(key)
repl = self.getReplacement(val)
replaced, n = re.subn(pattern, repl, line)
if n > 0:
return replaced
return None
def getPattern(self, key: str):
# Match the version fields in Kconfig file
return rf'(^\s+default\s+)(\d+) # ({key})'
def getReplacement(self, val: str):
# Replace the version value
return r'\g<1>' + val + r' # \g<3>'
if __name__ == '__main__':
args = get_arg()
@@ -132,6 +161,7 @@ if __name__ == '__main__':
MacroReplacer(['lv_version.h']),
CmakeReplacer(['env_support', 'cmake', 'version.cmake']),
PrefixReplacer(['lv_conf_template.h'], 'Configuration file for v'),
KconfigReplacer(['Kconfig']),
]
if version.is_release: