From 8dea3225ff71d16a9c5e1fac6a789deaf2feddf3 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Fri, 20 Sep 2024 16:42:16 +0800 Subject: [PATCH] chore(Kconfig): add version info to Kconfig file to check mismatch (#6789) Signed-off-by: Neo Xu --- Kconfig | 14 ++++++++++++-- scripts/update_version.py | 30 ++++++++++++++++++++++++++++++ src/lv_conf_kconfig.h | 10 ++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Kconfig b/Kconfig index 7df38b7a5..e6f88aac5 100644 --- a/Kconfig +++ b/Kconfig @@ -1527,15 +1527,25 @@ menu "LVGL configuration" default y help This can save some memory, but not much. After the quick access bar is created, it can be hidden by clicking the button at the top left corner of the browsing area, which is very useful for small screen devices. - + config LV_USE_FONT_MANAGER bool "Enable freetype font manager" depends on LV_USE_FREETYPE - default n + default n config LV_FONT_MANAGER_NAME_MAX_LEN int "Font manager name max length" depends on LV_USE_FONT_MANAGER default 32 + + config LVGL_VERSION_MAJOR + int + default 9 # LVGL_VERSION_MAJOR + config LVGL_VERSION_MINOR + int + default 2 # LVGL_VERSION_MINOR + config LVGL_VERSION_PATCH + int + default 0 # LVGL_VERSION_PATCH endmenu menu "Devices" diff --git a/scripts/update_version.py b/scripts/update_version.py index 8588ed96c..0db1f0361 100755 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -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: diff --git a/src/lv_conf_kconfig.h b/src/lv_conf_kconfig.h index a36eaf775..7796e0fb9 100644 --- a/src/lv_conf_kconfig.h +++ b/src/lv_conf_kconfig.h @@ -18,6 +18,16 @@ extern "C" { # ifdef __NuttX__ # include +/* + * Make sure version number in Kconfig file is correctly set. + * Mismatch can happen when user manually copy lvgl/Kconfig file to their project, like what NuttX does. + */ +# include "../lv_version.h" + +# if CONFIG_LVGL_VERSION_MAJOR != LVGL_VERSION_MAJOR || CONFIG_LVGL_VERSION_MINOR != LVGL_VERSION_MINOR \ + || CONFIG_LVGL_VERSION_PATCH != LVGL_VERSION_PATCH +# warning "Version mismatch between Kconfig and lvgl/lv_version.h" +# endif # elif defined(__RTTHREAD__) # define LV_CONF_INCLUDE_SIMPLE # include