فهرست منبع

kconfig: confgen.py now handles many-to-one config renames

All old symbols will now be included in the output when renaming
multiple symbols to the same new symbol.
Marius Vikhammer 4 سال پیش
والد
کامیت
65a302a6f6
2فایلهای تغییر یافته به همراه43 افزوده شده و 12 حذف شده
  1. 29 0
      tools/ci/test_build_system_cmake.sh
  2. 14 12
      tools/kconfig_new/confgen.py

+ 29 - 0
tools/ci/test_build_system_cmake.sh

@@ -631,6 +631,35 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
     git checkout -- sdkconfig.rename Kconfig
     popd
 
+    echo "Can have multiple deprecated Kconfig options map to a single new option"
+    idf.py clean > /dev/null
+    rm -f sdkconfig.defaults
+    rm -f sdkconfig
+    echo "" > ${IDF_PATH}/sdkconfig.rename
+    idf.py reconfigure > /dev/null
+    echo "CONFIG_TEST_NEW_OPTION=y" >> sdkconfig
+    echo "CONFIG_TEST_OLD_OPTION_1 CONFIG_TEST_NEW_OPTION" >> ${IDF_PATH}/sdkconfig.rename
+    echo "CONFIG_TEST_OLD_OPTION_2 CONFIG_TEST_NEW_OPTION" >> ${IDF_PATH}/sdkconfig.rename
+    echo -e "\n\
+    menu \"test\"\n\
+    config TEST_NEW_OPTION\n\
+        bool \"test\"\n\
+        default \"n\"\n\
+        help\n\
+            TEST_NEW_OPTION description\n\
+    endmenu\n" >> ${IDF_PATH}/Kconfig
+    idf.py reconfigure > /dev/null
+    grep "CONFIG_TEST_OLD_OPTION_1=y" sdkconfig || failure "CONFIG_TEST_OLD_OPTION_1 should be in sdkconfig for backward compatibility"
+    grep "CONFIG_TEST_OLD_OPTION_2=y" sdkconfig || failure "CONFIG_TEST_OLD_OPTION_2 should be in sdkconfig for backward compatibility"
+    grep "#define CONFIG_TEST_OLD_OPTION_1 CONFIG_TEST_NEW_OPTION" build/config/sdkconfig.h || failure "sdkconfig.h should contain the compatibility macro"
+    grep "#define CONFIG_TEST_OLD_OPTION_2 CONFIG_TEST_NEW_OPTION" build/config/sdkconfig.h || failure "sdkconfig.h should contain the compatibility macro"
+    grep "set(CONFIG_TEST_OLD_OPTION_1 \"y\")" build/config/sdkconfig.cmake || failure "CONFIG_TEST_OLD_OPTION_1 should be in auto.conf for backward compatibility"
+    grep "set(CONFIG_TEST_OLD_OPTION_2 \"y\")" build/config/sdkconfig.cmake || failure "CONFIG_TEST_OLD_OPTION_2 should be in auto.conf for backward compatibility"
+    rm -rf sdkconfig sdkconfig.defaults build
+    pushd ${IDF_PATH}
+    git checkout -- sdkconfig.rename Kconfig
+    popd
+
     echo "Can have target specific deprecated Kconfig options"
     idf.py clean
     rm -f sdkconfig

+ 14 - 12
tools/kconfig_new/confgen.py

@@ -18,6 +18,7 @@ import re
 import sys
 import tempfile
 import textwrap
+from collections import defaultdict
 
 import gen_kconfig_doc
 import kconfiglib
@@ -43,7 +44,7 @@ class DeprecatedOptions(object):
 
     def _parse_replacements(self, repl_paths):
         rep_dic = {}
-        rev_rep_dic = {}
+        rev_rep_dic = defaultdict(list)
 
         def remove_config_prefix(string):
             if string.startswith(self.config_prefix):
@@ -68,11 +69,11 @@ class DeprecatedOptions(object):
 
                     (dep_opt, new_opt) = (remove_config_prefix(x) for x in sp_line)
                     rep_dic[dep_opt] = new_opt
-                    rev_rep_dic[new_opt] = dep_opt
+                    rev_rep_dic[new_opt].append(dep_opt)
         return rep_dic, rev_rep_dic
 
     def get_deprecated_option(self, new_option):
-        return self.rev_r_dic.get(new_option, None)
+        return self.rev_r_dic.get(new_option, [])
 
     def get_new_option(self, deprecated_option):
         return self.r_dic.get(deprecated_option, None)
@@ -128,10 +129,10 @@ class DeprecatedOptions(object):
                             for sym in syms:
                                 if sym.name in self.rev_r_dic:
                                     # only if the symbol has been renamed
-                                    dep_name = self.rev_r_dic[sym.name]
-
+                                    dep_names = self.rev_r_dic[sym.name]
+                                    dep_names = [config.config_prefix + name for name in dep_names]
                                     # config options doesn't have references
-                                    f_o.write('    - {}{}\n'.format(config.config_prefix, dep_name))
+                                    f_o.write('    - {}\n'.format(', '.join(dep_names)))
 
     def append_config(self, config, path_output):
         tmp_list = []
@@ -142,8 +143,9 @@ class DeprecatedOptions(object):
                 if item.name in self.rev_r_dic:
                     c_string = item.config_string
                     if c_string:
-                        tmp_list.append(c_string.replace(self.config_prefix + item.name,
-                                                         self.config_prefix + self.rev_r_dic[item.name]))
+                        for dep_name in self.rev_r_dic[item.name]:
+                            tmp_list.append(c_string.replace(self.config_prefix + item.name,
+                                                             self.config_prefix + dep_name))
 
         for n in config.node_iter():
             append_config_node_process(n)
@@ -392,10 +394,10 @@ def write_cmake(deprecated_options, config, filename):
                 write('set({}{} "{}")\n'.format(prefix, sym.name, val))
 
                 configs_list.append(prefix + sym.name)
-                dep_opt = deprecated_options.get_deprecated_option(sym.name)
-                if dep_opt:
-                    tmp_dep_list.append('set({}{} "{}")\n'.format(prefix, dep_opt, val))
-                    configs_list.append(prefix + dep_opt)
+                dep_opts = deprecated_options.get_deprecated_option(sym.name)
+                for opt in dep_opts:
+                    tmp_dep_list.append('set({}{} "{}")\n'.format(prefix, opt, val))
+                    configs_list.append(prefix + opt)
 
         for n in config.node_iter():
             write_node(n)