mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-13 17:43:27 +00:00
tools: Support sdkconfig.rename files from outside IDF in confgen.py
This commit is contained in:

committed by
Angus Gratton

parent
ba0f4f17ed
commit
a8e8919bbf
@@ -22,7 +22,6 @@
|
||||
# limitations under the License.
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import fnmatch
|
||||
import json
|
||||
import os
|
||||
import os.path
|
||||
@@ -46,15 +45,15 @@ class DeprecatedOptions(object):
|
||||
_RE_DEP_OP_BEGIN = re.compile(_DEP_OP_BEGIN)
|
||||
_RE_DEP_OP_END = re.compile(_DEP_OP_END)
|
||||
|
||||
def __init__(self, config_prefix, path_rename_files, ignore_dirs=()):
|
||||
def __init__(self, config_prefix, path_rename_files=[]):
|
||||
self.config_prefix = config_prefix
|
||||
# r_dic maps deprecated options to new options; rev_r_dic maps in the opposite direction
|
||||
self.r_dic, self.rev_r_dic = self._parse_replacements(path_rename_files, ignore_dirs)
|
||||
self.r_dic, self.rev_r_dic = self._parse_replacements(path_rename_files)
|
||||
|
||||
# note the '=' at the end of regex for not getting partial match of configs
|
||||
self._RE_CONFIG = re.compile(r'{}(\w+)='.format(self.config_prefix))
|
||||
|
||||
def _parse_replacements(self, repl_dir, ignore_dirs):
|
||||
def _parse_replacements(self, repl_paths):
|
||||
rep_dic = {}
|
||||
rev_rep_dic = {}
|
||||
|
||||
@@ -64,31 +63,24 @@ class DeprecatedOptions(object):
|
||||
raise RuntimeError('Error in {} (line {}): Config {} is not prefixed with {}'
|
||||
''.format(rep_path, line_number, string, self.config_prefix))
|
||||
|
||||
for root, dirnames, filenames in os.walk(repl_dir):
|
||||
for filename in fnmatch.filter(filenames, self._REN_FILE):
|
||||
rep_path = os.path.join(root, filename)
|
||||
for rep_path in repl_paths:
|
||||
with open(rep_path) as f_rep:
|
||||
for line_number, line in enumerate(f_rep, start=1):
|
||||
sp_line = line.split()
|
||||
if len(sp_line) == 0 or sp_line[0].startswith('#'):
|
||||
# empty line or comment
|
||||
continue
|
||||
if len(sp_line) != 2 or not all(x.startswith(self.config_prefix) for x in sp_line):
|
||||
raise RuntimeError('Syntax error in {} (line {})'.format(rep_path, line_number))
|
||||
if sp_line[0] in rep_dic:
|
||||
raise RuntimeError('Error in {} (line {}): Replacement {} exist for {} and new '
|
||||
'replacement {} is defined'.format(rep_path, line_number,
|
||||
rep_dic[sp_line[0]], sp_line[0],
|
||||
sp_line[1]))
|
||||
|
||||
if rep_path.startswith(ignore_dirs):
|
||||
print('Ignoring: {}'.format(rep_path))
|
||||
continue
|
||||
|
||||
with open(rep_path) as f_rep:
|
||||
for line_number, line in enumerate(f_rep, start=1):
|
||||
sp_line = line.split()
|
||||
if len(sp_line) == 0 or sp_line[0].startswith('#'):
|
||||
# empty line or comment
|
||||
continue
|
||||
if len(sp_line) != 2 or not all(x.startswith(self.config_prefix) for x in sp_line):
|
||||
raise RuntimeError('Syntax error in {} (line {})'.format(rep_path, line_number))
|
||||
if sp_line[0] in rep_dic:
|
||||
raise RuntimeError('Error in {} (line {}): Replacement {} exist for {} and new '
|
||||
'replacement {} is defined'.format(rep_path, line_number,
|
||||
rep_dic[sp_line[0]], sp_line[0],
|
||||
sp_line[1]))
|
||||
|
||||
(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
|
||||
(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
|
||||
return rep_dic, rev_rep_dic
|
||||
|
||||
def get_deprecated_option(self, new_option):
|
||||
@@ -190,6 +182,10 @@ def main():
|
||||
help='KConfig file with config item definitions',
|
||||
required=True)
|
||||
|
||||
parser.add_argument('--sdkconfig-rename',
|
||||
help='File with deprecated Kconfig options',
|
||||
required=False)
|
||||
|
||||
parser.add_argument('--output', nargs=2, action='append',
|
||||
help='Write output file (format and output filename)',
|
||||
metavar=('FORMAT', 'FILENAME'),
|
||||
@@ -235,10 +231,9 @@ def main():
|
||||
raise RuntimeError("Defaults file not found: %s" % name)
|
||||
config.load_config(name, replace=False)
|
||||
|
||||
# don't collect rename options from examples because those are separate projects and no need to "stay compatible"
|
||||
# with example projects
|
||||
deprecated_options = DeprecatedOptions(config.config_prefix, path_rename_files=os.environ["IDF_PATH"],
|
||||
ignore_dirs=(os.path.join(os.environ["IDF_PATH"], 'examples')))
|
||||
sdkconfig_renames = [args.sdkconfig_rename] if args.sdkconfig_rename else []
|
||||
sdkconfig_renames += os.environ.get("COMPONENT_SDKCONFIG_RENAMES", "").split()
|
||||
deprecated_options = DeprecatedOptions(config.config_prefix, path_rename_files=sdkconfig_renames)
|
||||
|
||||
# If config file previously exists, load it
|
||||
if args.config and os.path.exists(args.config):
|
||||
|
Reference in New Issue
Block a user