Change data driven "str" type to represent a quoted string literal (#16516)
* Change data driven "str" type to represent a quoted string literal * Update docs
This commit is contained in:
		@@ -82,7 +82,7 @@ def generate_config_items(kb_info_json, config_h_lines):
 | 
			
		||||
 | 
			
		||||
    for config_key, info_dict in info_config_map.items():
 | 
			
		||||
        info_key = info_dict['info_key']
 | 
			
		||||
        key_type = info_dict.get('value_type', 'str')
 | 
			
		||||
        key_type = info_dict.get('value_type', 'raw')
 | 
			
		||||
        to_config = info_dict.get('to_config', True)
 | 
			
		||||
 | 
			
		||||
        if not to_config:
 | 
			
		||||
@@ -110,6 +110,11 @@ def generate_config_items(kb_info_json, config_h_lines):
 | 
			
		||||
                config_h_lines.append(f'#ifndef {key}')
 | 
			
		||||
                config_h_lines.append(f'#   define {key} {value}')
 | 
			
		||||
                config_h_lines.append(f'#endif // {key}')
 | 
			
		||||
        elif key_type == 'str':
 | 
			
		||||
            config_h_lines.append('')
 | 
			
		||||
            config_h_lines.append(f'#ifndef {config_key}')
 | 
			
		||||
            config_h_lines.append(f'#   define {config_key} "{config_value}"')
 | 
			
		||||
            config_h_lines.append(f'#endif // {config_key}')
 | 
			
		||||
        elif key_type == 'bcd_version':
 | 
			
		||||
            (major, minor, revision) = config_value.split('.')
 | 
			
		||||
            config_h_lines.append('')
 | 
			
		||||
@@ -200,7 +205,7 @@ def generate_config_h(cli):
 | 
			
		||||
        cli.args.output.parent.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
        if cli.args.output.exists():
 | 
			
		||||
            cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak'))
 | 
			
		||||
        cli.args.output.write_text(config_h)
 | 
			
		||||
        cli.args.output.write_text(config_h, encoding='utf-8')
 | 
			
		||||
 | 
			
		||||
        if not cli.args.quiet:
 | 
			
		||||
            cli.log.info('Wrote info_config.h to %s.', cli.args.output)
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    info_key = info_dict['info_key']
 | 
			
		||||
    key_type = info_dict.get('value_type', 'str')
 | 
			
		||||
    key_type = info_dict.get('value_type', 'raw')
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        rules_value = kb_info_json[info_key]
 | 
			
		||||
@@ -32,6 +32,8 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
 | 
			
		||||
        return f'{rules_key} ?= {"yes" if rules_value else "no"}'
 | 
			
		||||
    elif key_type == 'mapping':
 | 
			
		||||
        return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()])
 | 
			
		||||
    elif key_type == 'str':
 | 
			
		||||
        return f'{rules_key} ?= "{rules_value}"'
 | 
			
		||||
 | 
			
		||||
    return f'{rules_key} ?= {rules_value}'
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user