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

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
Neo Xu
2024-09-20 16:42:16 +08:00
committed by GitHub
parent 57b799f4fc
commit 8dea3225ff
3 changed files with 52 additions and 2 deletions

View File

@@ -122,6 +122,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()
@@ -133,6 +162,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: